Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

31–40 of 179 posts

Re: A Vim Guide for Advanced Users

#31

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

You should just try seriously. First because many CLI have vim-like keystrokes, second because when you're lost on a remote server or on a docker container without nano you can use vi (close enough), and third because it might change your life :D

Re: A Vim Guide for Advanced Users

#32
post #7
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…

Why is this preferable to :%s?

It composes better if you were searching for something and then want to replace it IMO. You basically just have to remember the search syntax and then you can reuse it for replacing.

It's also better if you don't actually want to replace in the whole file and there's no convenient shorthand for the range.

I very rarely use :s myself, I'm always too worry that I'm going to clobber something I didn't mean to, I prefer to search and manually repeat a substitution. s can do it with with the "c" modifier but I find that using normal edit commands is both more flexible and easier to remember.

Re: A Vim Guide for Advanced Users

#34
post #4
post #2

Superb submission! I've been using vim for over a decade and I never knew about gx or gf. Thanks!

I was meant to write a blog post like this since forever. Anyway, if you want really advanced stuff this[0] is definitely a way to go. As for ```gx``` since I'm using aerc as my email client, a trick I found very useful to open links using only the keyboard is to open an email then rq (reply with quote) search for the link and gx. 0: https://www.ele.uri.edu/faculty/vetter/Other-stuff/vi/009-in... Edit: add the bit ab…

Wow this looks super interesting. Thanks for sharing :)

Re: A Vim Guide for Advanced Users

#35
post #16
post #2

Superb submission! I've been using vim for over a decade and I never knew about gx or gf. Thanks!

Related, gF will also scroll down to the line number if specified as: File.txt:45 Very handy when using a terminal from within vim and looking at compiler errors/warnings or log files etc.

Nice one. Didn't know that. I'll add it to the article :)

Re: A Vim Guide for Advanced Users

#36
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.

The non-barbarian way to avoid counting characters when there's no convenient motion is visual mode. Hit v, then hit l until you've highlighted the part you want to change, then hit c to start changing it.

Re: A Vim Guide for Advanced Users

#38

Thank you! Two things I really got from this: Capital marks. I use ma or ms and `a `s a lot, but did not know you could do global marks with mA and `A. Very useful! I've been using `` for a long time to mean "go back to the last place I was editing" but sometimes it gets overridden when navigating (I'm not super familiar with the jumplist, so maybe I need to get a better understanding) but `[ and `] are exactly what…

You should try g; and g, You'll go through the change list. I think it's what you want. I explain it in the article vim-intermediate on the same blog :)

Yes, thank you, I just read that article as well and that is what I was looking for =]

Re: A Vim Guide for Advanced Users

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

Thank you so much! I've been using Vim for 5 years and I always thought :s was one of the major pain points.

Re: A Vim Guide for Advanced Users

#40
post #12
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…

This has one huge shortcoming: when the next match is off-screen, pressing . jumps immediately to the next match and replaces it, before you had the opportunity to review whether you want that. To solve this I wrote a little plugin (that I finished as a plugin yesterday and uploaded just now): https://github.com/orlp/vim-quick-replace It requires vim-repeat (and a patched one because the current one has an issue): ht…

I'm not sure exactly what your plugin does, but are you aware of the "c" flag to substitute, eg

:%s/debug/dbg/c

vim will show the text which is about to be modified, and you have a prompt to confirm, skip, or quit (and some others).

Post reply on HN