Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

41–50 of 179 posts

Re: A Vim Guide for Advanced Users

#41
post #28

Earlier quoted context omitted.

Yeah I know the trick and I explain it a bit more in another article on my blog. Most of the time it's more keystrokes than using :s though, so I'm not a big fan of it. But I see the appeal :)

I'm paranoid and I like seeing exactly what I'm replacing. In that case I still use :s but I always end it with :s/foo/bar/gc. Although I do see the appeal of cgn for simple replacements.

If you use Neovim, you can set the option inccommand:

set inccommand=nosplit

It will display the substitute directly in the buffer.

Re: A Vim Guide for Advanced Users

#43
This was a really nice refresher and I learned a few new cool tricks (like gx).

I'm a bit surprised that the 'u' flag for sort wasn't mentioned. That's the most useful one in my mind and I use it almost every time.

Re: A Vim Guide for Advanced Users

#44
post #12

Earlier quoted context omitted.

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).

Yes, I am aware, but it's not nearly as flexible and quick. It doesn't allow me to in the meantime move my cursor around, switch buffers, undo, open/close a fold, etc. It takes complete control of your workflow to temporarily put you in some special 'search/replace mode' in a very non-Vimlike manner. My plugin has a simple operation (if cursor is on a match, replace, regardless jump to next match) that gets repeated with ., combined with nN and u and you have complete control while also rapidly doing search/replace.

And you would still need some nice mappings to substitute the word/selection underneath the cursor with :%s///gc.

Re: A Vim Guide for Advanced Users

#45
post #4

Earlier quoted context omitted.

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 :)

No problem, I also wrote a blog post about Vim sessions[0]. I think it definitely counts as intermediate/advanced vim material. Great work with your article.

0: https://rmpr.xyz/Vim-Session/

Re: A Vim Guide for Advanced Users

#48
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 is very useful, thank you! How would you go about pasting the "replace" part though?

I could only think of this rather awkward sequence:

1. Yank to named register

2. Search

3. "cgn"

4. Ctrl-R to paste from named register

5. Repeat

This is actually the biggest gripe I have with vim, even after almost 10 years of constant use. Vim always seems to overwrite the default register when I don't want it to. This makes replacing multiple bits of text with one pasted value awkward. I feel like I'm missing some essential shortcut or configuration that everybody else knows. It can't just be named registers, right?

Re: A Vim Guide for Advanced Users

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

You can just type n, followed by ., to view the next match before changing it.

Re: A Vim Guide for Advanced Users

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

Do you have any more aerc tricks? I use it and do like it but there's a whole lot of basic things even that I don't know how to do. And some things like saving file attachments that I'm not even sure if it supports or if I'm just clueless
Post reply on HN