Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

141–150 of 179 posts

Re: A Vim Guide for Advanced Users

#141
post #63
post #57

Is there a good way by default to wrap a visual selection in braces/parens/brackets?

I use vim-surround. https://github.com/tpope/vim-surround

Great plugin. Everything Tim Pope produces is gold. All Vim users should check out his whole collection on GitHub.

Re: A Vim Guide for Advanced Users

#142
post #30
post #5

The article mentions ”gn” in passing, but it doesn’t give it enough credit: this is an enormously useful motion, almost more useful on its own than the rest of the article. The thing that makes it golden is that it is a motion, and thus combined with a command, it is repeatable! So, like: 1. Search for something (either using / or *). 2. Type ”cgn” in Normal mode (i.e. change next search match) and replace what you s…

Oh man, I knew there had to be a way to do that but I couldn't find it, so I always resorted to counting the number of characters in the match and then use cl to replace it if there was no convenient motion like some kind of barbarian.

cl is equivalent to s (unless you've installed a plugin that binds s to something else).

Re: A Vim Guide for Advanced Users

#143
post #107

Earlier quoted context omitted.

Thanks! Gonna try to remember that combo.

It appears in the table of commands at the bottom of the screen by default, doesn't it?

I don't remember exactly, I just remember having a hard time exiting nano but not vim (also not before I knew vim: it just tells you what to do when you press the usual ctrl+c). From the sibling comment to yours, it says ^X which probably wasn't clear to me is supposed to be ctrl instead of shift. With hindsight it seems quite obvious, I'll admit.

Re: A Vim Guide for Advanced Users

#144
post #87

The article mentions gI but that's 3 keystrokes (g, shift, i) when you can do 0i, and you probably want to know about 0 and i regardless, making the extra learning of gI unnecessary. Unfortunately this doesn't help anyone because it's not as if by deleting gI from your memory you can more easily learn something else, but perhaps it's helpful for a future guide writer or perhaps someone knows why gI is useful. Edit: T…

Re your edit: they explain it pastes the output of the command directly into your buffer, rather than temporarily showing you a shell with the output.

Oh, I missed that! Thanks for pointing that out :)

Re: A Vim Guide for Advanced Users

#145
post #106

Earlier quoted context omitted.

Took some effort to refine a websearch: https://stackoverflow.com/questions/2158516/delay-before-o-o...

Thanks! I never use arrows in insert mode so that's an easy choice for me, but removing 'nocompatible' from my vimrc does nothing and setting 'compatible' instead has side effects like not showing what mode I'm in. Not sure I need it, but I'm also wondering what other side effects I'll run into. The help file mentions a ton of things that I frankly don't care enough to comb through. The only thing I randomly spotted…

Woah, I just looked at the Vim help page for 'timeoutlen' and the fact that it's in milliseconds is only mentioned below, under 'ttimeoutlen'. The Neovim help page specifies that it's in milliseconds.

I think that the Stack Overflow answer was just saying that the default depends on 'compatible'; not that the recommended solution is to go back to 'compatible'.

Re: A Vim Guide for Advanced Users

#146
post #115

Earlier quoted context omitted.

The u option making it keep only unique lines, for anyone else left wondering. Personally, instead of re-learning how to do stuff with vim-sepecific commands, I just use the existing command line tool, especially since I don't do this on a daily/weekly basis (but I use sort in command line pipes at least weekly). The command is literally "sort" and for unique you just pass the -u flag, e.g. select something in Vim an…

Vim's sort is handy on Windows where the option to shell out usually doesn't exist. Additionally you have the full power of Vim regex to sort on subsets of lines.

On the other hand, the :! and ! commands are Vi compatible (though, as you say, you wouldn't get the additional features of :sort). So you get to pick who you're going to be compatible with: vi or Windows?

Re: A Vim Guide for Advanced Users

#147
post #87

The article mentions gI but that's 3 keystrokes (g, shift, i) when you can do 0i, and you probably want to know about 0 and i regardless, making the extra learning of gI unnecessary. Unfortunately this doesn't help anyone because it's not as if by deleting gI from your memory you can more easily learn something else, but perhaps it's helpful for a future guide writer or perhaps someone knows why gI is useful. Edit: T…

One difference is that `gI` is repeatable with `j.`, but `0i` is not.

Re: A Vim Guide for Advanced Users

#148
post #84
post #5

The article mentions ”gn” in passing, but it doesn’t give it enough credit: this is an enormously useful motion, almost more useful on its own than the rest of the article. The thing that makes it golden is that it is a motion, and thus combined with a command, it is repeatable! So, like: 1. Search for something (either using / or *). 2. Type ”cgn” in Normal mode (i.e. change next search match) and replace what you s…

I used to do n.n.n.n. to do the same (i.e. /search something, then do the replacing with something like cw or 3s or ct' or whatever you want, and then hit n for next result and . to repeat the change). Using cgn is less flexible and you need to learn another thing (you know about n and . already by the time you get to cgn), and maybe it's just me but hitting n. repeatedly is practically equally fast as just hitting t…

> But perhaps it's a bug in Vim since it works when I run * on the lowercase variant.

Per the help it's a feature, and it's infuriating! (From :help star)

> 'ignorecase' is used, 'smartcase' is not.

Here's your workaround:

    " By default, * and # respect 'ignorecase'. This mapping forces these commands
    " to search case sensitively, which is usually what you want when searching
    " code with * or #. May be less good for prose.
    nnoremap  * /\C\=expand('')\>
    nnoremap  # ?\C\=expand('')\>

Re: A Vim Guide for Advanced Users

#149
post #87

The article mentions gI but that's 3 keystrokes (g, shift, i) when you can do 0i, and you probably want to know about 0 and i regardless, making the extra learning of gI unnecessary. Unfortunately this doesn't help anyone because it's not as if by deleting gI from your memory you can more easily learn something else, but perhaps it's helpful for a future guide writer or perhaps someone knows why gI is useful. Edit: T…

Re your edit: they explain it pastes the output of the command directly into your buffer, rather than temporarily showing you a shell with the output.

You can just do `:r !ls` to do that. Using =system('ls') is way overkill.

That said I do agree that the expression register is amazing.

Re: A Vim Guide for Advanced Users

#150
post #87

The article mentions gI but that's 3 keystrokes (g, shift, i) when you can do 0i, and you probably want to know about 0 and i regardless, making the extra learning of gI unnecessary. Unfortunately this doesn't help anyone because it's not as if by deleting gI from your memory you can more easily learn something else, but perhaps it's helpful for a future guide writer or perhaps someone knows why gI is useful. Edit: T…

The number of keystrokes is an interesting number to use because it is only roughly correlated with the time it takes to press the keys. Both 2dd and 2[] are three keys, yet the latter can be typed much faster than the former as it is spread over both sides of the keyboard and it doesn’t repeat a key (so you can “roll” your fingers over the [] which is faster than double pressing the d).

In the case of g-shift-I, I’d call it 2.5 keys. Assuming you press g and I with the right hand, the shift key hardly matters in terms of time. Of course, by the same logic, 0i is faster still.

Post reply on HN