Live data from Hacker News

A Vim Guide for Advanced Users

thevaluable.dev

101–110 of 179 posts

Re: A Vim Guide for Advanced Users

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

[deleted]

Re: A Vim Guide for Advanced Users

#102
post #93

Earlier quoted context omitted.

> is there a a way to close such that the previous file that was originally opened to return? If I understand the question correctly then the answer is ":bd" after ":w"riting the file. If you just want to switch between buffers (switch between the two files) then use ":b#". You can also list open buffers with ":ls" Someone recently told me of :tabedit, though, and that is lookin' way nicer to me. But I haven't gotten…

"Split screen" as in make a new window? Sure - `:vs` ("vertical split"), or `:vs filename.txt`. Or there's the "Windows" section on https://thevaluable.dev/vim-intermediate/ .

great got both answered perfectly!

Re: A Vim Guide for Advanced Users

#103
post #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)

It's CTRL+X and then N to not save changes

Re: A Vim Guide for Advanced Users

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

The author does mention this in an in-depth article on search: https://thevaluable.dev/vim-search-find-replace/

It's pretty comprehensive. Personally I'd just install Doom Emacs though :)

Re: A Vim Guide for Advanced Users

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

This is useful enough that I wonder why you chose not to just map it to *. Is there a reason you did not?

Re: A Vim Guide for Advanced Users

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

Took some effort to refine a websearch: https://stackoverflow.com/questions/2158516/delay-before-o-o...

Thanks! I never use arrows in insert mode so that's an easy choice for me, but removing 'nocompatible' from my vimrc does nothing and setting 'compatible' instead has side effects like not showing what mode I'm in. Not sure I need it, but I'm also wondering what other side effects I'll run into. The help file mentions a ton of things that I frankly don't care enough to comb through. The only thing I randomly spotted (and knew what it meant without digging deeper) is that this also breaks backspace in insert mode. Overall it makes vim feel quite a lot like vi.

Instead, setting nocompatible and timeoutlen=1 (1ms I guess? Help file doesn't say) works fine in my terminal, I guess because it's not over any sort of network connection. I'll give this a go and see if I run into any issues when using these escape-based features (afaik I use those only rarely) over the network.

Re: A Vim Guide for Advanced Users

#107
post #103
post #89

Earlier quoted context omitted.

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)

It's CTRL+X and then N to not save changes

Thanks! Gonna try to remember that combo.

Re: A Vim Guide for Advanced Users

#110
The number increment example doesn't seem to work for me. It says to start with this:

    1. a
    1. b
    1. c
The post says to "select in VISUAL mode the last two lines and hit `g CTRL+a`". So I guess with shift+v select the bottom two lines, and then I hit g, space, and Ctrl+a. I get:

    1. a
    2. b
    2. c
The post says that the last line should now start with 3 instead of 1, or in my case 2. The behavior is the same as when omitting g+space for me. Am I doing it wrong?
Post reply on HN