Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

171–179 of 179 posts

Re: A Vim Guide for Advanced Users

#171
post #95

One thing I've never been able to figure out in Vim: why does O (insert new line above the current line and enter insert mode) often wait and hang? And when you start typing, it'll sometimes do random stuff? Is there a way to just make it behave like a true counterpart of o (insert new line below and enter insert mode)?

You probably have a mapping for a multikey starting with O, I had this problem many times with different keys. You can search for it in `:map` or `:verbose map`. Or just `:map O` and tab for autocomplete (might work, not sure).

Re: A Vim Guide for Advanced Users

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

Nice, it works in evil-mode on emacs as well! Although for emacs I would just use query-replace, which does the same thing with y/n confirmation, and it can also be run on just a selected region if desired.

Re: A Vim Guide for Advanced Users

#174
post #95

One thing I've never been able to figure out in Vim: why does O (insert new line above the current line and enter insert mode) often wait and hang? And when you start typing, it'll sometimes do random stuff? Is there a way to just make it behave like a true counterpart of o (insert new line below and enter insert mode)?

Just add this to your .vimrc

set timeout timeoutlen=1000 ttimeoutlen=100 " Fix slow O inserts

Re: A Vim Guide for Advanced Users

#175

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 e…

This is not an answer to your first question, but I find that Ctrl-O and Ctrl-I are much more useful for getting back to your previous location -- which is normally what I want.

Re: A Vim Guide for Advanced Users

#176

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.

... I forgot it :D I'll fix that. Thanks to point it out :)

Thank you for reading the comments and updating the article.

Re: A Vim Guide for Advanced Users

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

I can also do a subset of lines in the way I described, actually
Post reply on HN