Live data from Hacker News

Intermediate Vim tips

kinbiko.com

51–60 of 79 posts

Re: Intermediate Vim tips

#51
post #28

Where have you been all my life, "set cursorcolumn"?

LOL that was my exact thought. Added to .vimrc. But will never get back all the time lost trying to make sure I was at proper indent level.

I highly highly recommend always using a linter/formatter that just fixes this for you

Re: Intermediate Vim tips

#53

Whenever a Vim post mentions grep, ack or ag — especially in conjunction with fzf/fzy — I'll make sure to mention the even faster rg (ripgrep): https://github.com/BurntSushi/ripgrep BurntSushi's write-up about the internal workings of ripgrep is also super interesting: http://blog.burntsushi.net/ripgrep/ ) It's a really amazing piece of software. It has also recently been included in Visual Studio Code to search in f…

Completely agree. I used to use ag, but its handling of .gitignore files is buggy and often returns a lot more results than it should. Switching to ripgrep made a pretty significant difference for me.

Re: Intermediate Vim tips

#54
post #46

Whenever a Vim post mentions grep, ack or ag — especially in conjunction with fzf/fzy — I'll make sure to mention the even faster rg (ripgrep): https://github.com/BurntSushi/ripgrep BurntSushi's write-up about the internal workings of ripgrep is also super interesting: http://blog.burntsushi.net/ripgrep/ ) It's a really amazing piece of software. It has also recently been included in Visual Studio Code to search in f…

I use ripgrep and it's pretty great, but I don't know why Visual Studio Code would be using it. Why not just use Rust's Regex library instead?

I'm just guessing here, but ripgrep is an executable that they can bundle and write a simple wrapper around. VSCode isn't written in Rust so they'd have to write their own "grep" in Rust which most likely wouldn't be anywhere near as good as ripgrep.

Or am I misunderstanding your question?

Re: Intermediate Vim tips

#55
post #48
post #46

Earlier quoted context omitted.

I use ripgrep and it's pretty great, but I don't know why Visual Studio Code would be using it. Why not just use Rust's Regex library instead?

Is it? Funny because I have tmux open in the side pane, and execute my searches that way.

Yup: https://users.rust-lang.org/t/ripgrep-is-now-the-standard-te...

Re: Intermediate Vim tips

#56
post #33

Do you even emacs bro?

We've banned this account for repeatedly posting unsubstantive and uncivil comments to HN.

If you don't want to be banned, you're welcome to email hn@ycombinator.com and give us reason to believe that you'll follow the rules in the future.

Re: Intermediate Vim tips

#57
post #50

Earlier quoted context omitted.

It's not just that, in fact the reason for limiting to 80 is mostly because short lines help readability because of how human eyes operate. Eyes prefer to stay within a small circular region located in the center of the visual field. Too much vertical or horizontal movement makes it harder to see, but vertical movement isn't an issue in text because of scroll, but horizontal movement is a problem.

Yes; see https://en.wikipedia.org/wiki/Line_length

This assumes that code should be read as prose. I posit that code should be skimmed, then the eye can track right if the code is relevant to the task at hand. This is all subjective, which is why I feel soft-wrapping is appropriate as it allows the coder to decide their preference.

Re: Intermediate Vim tips

#58
post #9

Earlier quoted context omitted.

Same. I spend most of my time in a terminal and SSH into various boxes daily. I do customize my standard Unix toolset, but avoid plugins and non-standard configs that increase cognitive burden. It's very liberating to feel comfortable with shitty defaults. If you feel at home with the defaults, you feel at home anywhere.

You can remotely edit on any system accessible over ssh thanks to netrw: vim scp://some-remote-box/some/path You can jump to a directory listing by including a trailing / :help netrw

Emacs has Tramp, and you can do the same thing!

Re: Intermediate Vim tips

#59

> I don't like excessively long lines of code (120+ in most languages) Quick straw poll on this... How many people like a line length limit? My personal preference is a fairly strict 80 (barring silly things like URLs), but I've always been met with resistance to ANY line length limit. Is it really that imposing?

I break lines if it looks like they’re getting too long, where it feels right to do so. Setting a fixed number of columns causes people to align hanging lines to the right in my experience: some_example_code = LongTypeName(argument_one=1, argument_two=2, argument_three=3) (pretend that’s 80 columns), resulting in this mess when I try to look at it in a narrower view: some_example_code = LongTypeName(argument_on ↳ e=1…

> What does help is creating indented blocks where it feels right

Over the years, I've come to believe that using a hanging indent for alignment is actually better in terms of readability as opposed to aligning at a column after the opening parenthesis, brace, or bracket. It's also easier to type as well even if the editor doesn't provide an auto-indent facility (or if it's not configured correctly for some reason) since you only have to press TAB the same number of times to correctly position each formal parameter in the function definition.

As a side benefit, it also takes care of any alignment issues regardless of whether one uses tabs or spaces.

> and letting other lines just naturally be long.

Using the language's feature for string concatenation still makes it as easy to read:

  some_example_code = LongTypeName(
        "just a string that happens to be long; some people introduce " +
        "acceptable percentages of string literals for long lines, but it's " +
        "really not necessary. let word wrap take care of it!")
Another benefit of doing this is that it makes a unified diff and side-by-side diffs easier to read. Contrast the wrapped version when I add another sentence to the end of your example:

  diff --git a/tmp/wrapped b/tmp/wrapped
  index 972537b..27e3e31 100644
  --- a/tmp/wrapped
  +++ b/tmp/wrapped
  @@ -1,4 +1,5 @@
     some_example_code = LongTypeName(
           "just a string that happens to be long; some people introduce " +
           "acceptable percentages of string literals for long lines, but it's " +
  -        "really not necessary. let word wrap take care of it!")
  +        "really not necessary. let word wrap take care of it! Though unified " +
  +        "and side-by-side diffs may be more difficult to read")
versus the unwrapped one:

  diff --git a/tmp/unwrapped b/tmp/unwrapped
  index 284ef1e..db47f46 100644
  --- a/tmp/unwrapped
  +++ b/tmp/unwrapped
  @@ -1,2 +1,2 @@
     some_example_code = LongTypeName(
  -      "just a string that happens to be long; some people introduce acceptable percentages of string literals for long lines, but it's really not necessary.  let word wrap take care of it!")
  +      "just a string that happens to be long; some people introduce acceptable percentages of string literals for long lines, but it's really not necessary.  let word wrap take care of it! Though unified and side-by-side diffs may be more difficult to read")
With the wrapped version, you can more easily see what I added to the end of the line in your example. In the unwrapped example, I most likely would have to either scroll horizontally to read the entire line. If the line is soft-wrapped, then I would have to realize that the second line is part of the previous line and not a different context line (soft-wrapping is simulated by hard-wrapping right after the "for long lines," comma and the space after "difficult to " based on how blockquoted text appears a rendered comment):

  diff --git a/tmp/unwrapped b/tmp/unwrapped
  index 284ef1e..db47f46 100644
  --- a/tmp/unwrapped
  +++ b/tmp/unwrapped_more
  @@ -1,2 +1,2 @@
     some_example_code = LongTypeName(
  -      "just a string that happens to be long; some people introduce acceptable percentages of string literals for long lines,
  but it's really not necessary.  let word wrap take care of it!")
  +      "just a string that happens to be long; some people introduce acceptable percentages of string literals for long lines,
  but it's really not necessary.  let word wrap take care of it! Though unified and side-by-side diffs may be more difficult to
  read")

Re: Intermediate Vim tips

#60
post #9

Earlier quoted context omitted.

Same. I spend most of my time in a terminal and SSH into various boxes daily. I do customize my standard Unix toolset, but avoid plugins and non-standard configs that increase cognitive burden. It's very liberating to feel comfortable with shitty defaults. If you feel at home with the defaults, you feel at home anywhere.

You can remotely edit on any system accessible over ssh thanks to netrw: vim scp://some-remote-box/some/path You can jump to a directory listing by including a trailing / :help netrw

Is there a way to combine this with sudo, to edit root's files remotely? Apparently tramp is supposed to support this, but I prefer vim.
Post reply on HN