Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

1–10 of 179 posts

Re: A Vim Guide for Advanced Users

#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 about aerc

Re: A Vim Guide for Advanced Users

#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 searched for with whatever

3. Hammer on ”.” (i.e. repeat last command) to replace other matches.

This replaces, like, 97% of uses of :s and is a much more convenient way to do search/replace, especially if you use * to search for the word under the cursor. It’s the bee’s knees!

Re: A Vim Guide for Advanced Users

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

Re: A Vim Guide for Advanced Users

#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?

Re: A Vim Guide for Advanced Users

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

Ooh, sounds interesting. I'll have to look up the details. I currently do this after a search with / and regex (if it is a bit complicated)

    :%s//replace/gc

Re: A Vim Guide for Advanced Users

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

I dunno, I’ve also used both, and I keep coming back to the Vim/gn way of doing it, I just like it more. I see how people can feel otherwise, though.

Re: A Vim Guide for Advanced Users

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

Awesome, that's definitely something I'll add to my bag of tricks. But

> This replaces, like, 97% of uses of :s and is a much more convenient way to do search/replace, especially if you use * to search for the word under the cursor. It’s the bee’s knees!

I'm not really sure about that. I can definitely see it replacing :s for a small number of repetitions, but for a large number. I think using :s with a range is quicker.

Edit: typos, punctuation

Post reply on HN