Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

81–90 of 179 posts

Re: A Vim Guide for Advanced Users

#81

Vim is getting more popular. Not just within vim, but outside vim! Practically every full-featured editor has a vi or vim mode, and when they say vi, usually they also mean vim. Things that have nothing to do with vim but are inspired by vim are even sprouting up! And apparently it's OK to name something based on vim: https://groups.google.com/g/vim_use/c/EnSMrx_rGg4/m/d_nVlmLQ... Edit: In Bram's reply he mentioned t…

I used to work near a gym called “Vim Fitness”[0] in Cambridge, MA and there were endless jokes about trainers calling out: “H! J! K! L!”

[0] https://vimfitness.com/

Re: A Vim Guide for Advanced Users

#82
One of my goals is to become a really good vim power user. I am not able to pick up all of these but one here and there.

In the first command gf, once new file opened and then closed (wq), is there a a way to close such that the previous file that was originally opened to return? At moment returning back to shell prompt.

Also curious if there is a way to open the file as a new split screen rather than replacing the entire window?

Re: A Vim Guide for Advanced Users

#83
post #19

Practical vim by Drew Neil is hands down the best vim learning resource out there. Nothing even comes close.

Anyone looking to pick this up: I found the best way to consume it is to grab a couple tips at a time (it’s structured as a “recipe book”) and incorporate them into your workflow. For example, try Netrw for a week, then another week try out folds. You don’t have to read it cover to cover to get the full benefit of it.

Re: A Vim Guide for Advanced Users

#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 the dot.

It also has the downside that it doesn't match what is being shown: when I hit * on "overview" it highlights both "overview" and "Overview" (I have highlight search enabled), but cgn replaces only one of them. When the cursor is on Overview and I run "*cgnexample..." it will skip all the "Overview"s and only replace "overview".

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

Re: A Vim Guide for Advanced Users

#85
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…

As someone who uses this regularly, it's still not as convenient as multi cursors that most modern ides give you. There's a vim extension for multiple cursors but it's a little buggy.

As someone who never used a multi-cursor IDE (I've seen other use it but not in a convincing way): what's something that you use this for that you don't think vim can do?

The main purpose I've seen is basically block mode (like ctrl+v) or (iirc) repeating things on multiple hits (like n. or indeed cgn).

Re: A Vim Guide for Advanced Users

#86
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…

This might be the right audience for this little vimrc tidbit:

    "Press space to highlight current word
    nnoremap 
        \ :let @/='\=expand("")\>':set hls
This works just like *, except that it leaves your cursor where it is. You can then use n/p/whatever as normal.

Re: A Vim Guide for Advanced Users

#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: The section "The Insane Expression Register" also doesn't make much sense to me. Why would I do this 'system("ls")' thing when there is '!ls'? Using vimscript instead of bash probably has advantages in, y'know, vim, but most people know their shell and probably very few people know vimscript (certainly not me) so I'm not quite clear on the advantages here.

Re: A Vim Guide for Advanced Users

#89

Nice, but still wondering if I should know vim since nano is enough for me :)

Can you tell me how to exit nano without writing changes? Every time some silly default server kicks me into nano I'm absolutely lost and ctrl+c doesn't give you help text like in vim iirc. (Not kidding)

Re: A Vim Guide for Advanced Users

#90
post #84

Earlier quoted context omitted.

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…

This might be the right audience for this little vimrc tidbit: "Press space to highlight current word nnoremap \ :let @/='\ =expand(" ") \>' :set hls This works just like *, except that it leaves your cursor where it is. You can then use n/p/whatever as normal.

> like * but leaves your cursor where it is

Ooooh that is great! I use *# every time and am then annoyed when the n key goes backwards instead of forwards and then I try to remember to do #* instead and pff... ^^ This will solve those issues!

Post reply on HN