top | item 33811705

A Vim Guide for Advanced Users

407 points| behnamoh | 3 years ago |thevaluable.dev | reply

82 comments

order
[+] janvdberg|3 years ago|reply
I keep this URL in my bookmarks: https://jemma.dev/blog/intermediate-vim-tips

Most advanced guides throw a lot at you at once. Digesting one or few commands at a time works better for me to really make it stick (and that is the goal right?)

[+] koningrobot|3 years ago|reply
I notice it mentions Ctrl-a and Ctrl-x which "increment or decrement any number after the cursor on the same line". I hate these shortcuts because several times I've accidentally pressed them (e.g. on some level thinking I'm in Spacemacs or in readline) and introduced a hard-to-find bug into my code without knowing it.
[+] michael_j_ward|3 years ago|reply
Having suffered through learning highly configurable software tools independently enough times, I agree completely with "digesting one or few commands" at a time works better for me too.

Spitballing:

We could probably make a general solution for organically producing "learning guide" if power users 1) share their custom configurations and share the frequencies of commands they use.

Start with the general configuration, knowing nothing about the commands the tool offers. The learning guide is just a queue of "here's the most common config edit that you don't have" and "here's the most common command that you don't know about."

We are already share configs with eachother via the dotfiles pattern. We somewhat share command patterns via coding streams. Seems doable.

(In general, making it easier to learn new tech and for devs to share / refresh the learning material for a new tech seem underdeveloped.)

[+] SnooSux|3 years ago|reply
If I could add one thing to the list I would include `cib` as equivilent to `ci(` for changing everything in a set of parentheses (or brackets for the mnemonic's sake). For me at least the `b` is easier to reach than the `(`.

I need to use `z` for refocusing more

[+] thanato0s|3 years ago|reply
I agree. That said, I also like to have a more complete guide and pick and choose what could be useful for me.
[+] mstudio|3 years ago|reply
I recently picked up a copy of "Practical Vim" https://pragprog.com/titles/dnvim2/practical-vim-second-edit... based on a recommendation from a comment on HN. The first chapter mentions the built-in `vimtutor`

I never it existed! It was incredibly helpful with some features I'd never used such as Put, Replace and Visual mode. If you have vim, you should just be able to run `vimtutor` in the command line. If you have trouble, you can run `:help vimtutor` within vim.

[+] dunham|3 years ago|reply
Yeah, I've known and used "vi" for a couple of decades, saw someone use visual mode in a video a few months ago, and it blew my mind.

I still don't know how to do project navigation in vi, as I mainly use it for editing config files. I used emacs back in the day, but vscode is what I'm currently most comfortable with for moving between files in a large, deeply nested project.

[+] lou1306|3 years ago|reply
The "g" namespace is one of the few things I find annoying in Vim (which I like a lot). It is a grabbag of operations at cursor position ("gu", "gU"), mode switches ("gn"), file operations ("gf") and... weird stuff? Like, "ga" (prints the ascii value of the character under the cursor). This really does not help with memorizing the commands.

On the plus side, it enables "* + cgn + ." which is a neat way to do quick multiple substitutions, so yay I guess?

[+] g0xA52A2A|3 years ago|reply
The best guide is built in to Vim but sadly often overlooked.

https://vimhelp.org/usr_01.txt.html#usr_01.txt

[+] thanato0s|3 years ago|reply
I tried to go through it multiple time, but I couldn't:

1. It's way too long, the complete stuff is ten of thousand of lines. 2. It goes into needless details, especially at the beginning (the "finding help" section is intense for example). It turns me off each time. 3. It's too dry, not really enjoyable to read to me.

[+] alxmng|3 years ago|reply
This is really great.

I’ve recently switched to Helix editor after 10 years of vim and haven’t looked back. If you’re looking for something a bit simpler, zero configuration, but with the same philosophy as vim (select -> action) give it a try.

[+] Galanwe|3 years ago|reply
What annoyed me with helix was that invisible characters are treated the same as characters. That means your cursor can be positioned after the end of the line, on the '\n' and just sit there.

For instance, if you press "A", you are now after the \n of the end of line, and pressing backspace will remove the \n, joining with the line below.

I tried to ask whether that peculiar behavior could be toggled off somehow, but was welcomed by a wall of extreme purism on how treating differently visible and invisible characters would break the character model of the editor...

I'm too old to entertain the argument, and will just stick back to vim. Maybe its character model is unpure, but at least it's understandable by a mere mortal like me.

[+] johncoltrane|3 years ago|reply
> with the same philosophy as vim (select -> action)

"select->action" is definitely possible thanks to visual mode but it certainly is not Vim's "philosophy", which would be more in the line of "action->object".

[+] jb3689|3 years ago|reply
Zero configuration sounds like the opposite of why I like vim. I want things to work exactly how I want them to work. Vim’s composability of normal, day-to-day actions you already know is its best feature
[+] dragonelite|3 years ago|reply
Im also in the process of switching to Helix and Zellij. I like the minimal configuration of Helix compared to going through multiple git repos just to find the needed neovim config and adjust them to taste.
[+] mi_lk|3 years ago|reply
> with the same philosophy as vim (select -> action)

but Vim is not select -> action?

say `d2w` (to delete two words after the cursor) it's action then selection

[+] lawn|3 years ago|reply
But the massive plugin ecosystem and the endless configuration possibilities is part of the charm!
[+] johntb86|3 years ago|reply
Are there any good VSCode extensions that support helix-style input?
[+] PyWoody|3 years ago|reply
A useful Vi/m feature is splitting viewports with Ctrl-w + v/s.

    Ctrl-w + v == split current viewport vertically
    Ctrl-w + s == split current viewport horizontally
    Ctrl-w + = == resize viewports to equal height/widths
You can then move around the viewports with

    Ctrl-w + j == move one viewport down from current viewport (if available)
    Ctrl-w + k == moves one viewport up from current viewport (if available)
    Ctrl-w + h == moves one viewport to the left from current viewport (if available)
    Ctrl-w + l == moves one viewport to the right from current viewport (if available)
You can then :q viewports or :e to open a different file in that viewport.

Maybe it's so basic it never gets mentioned but I find a lot of people under utilize it.

Another good one is typing . to repeat previous command. You can do

    A, "something"
and then just type `.` to have "something" appended to whatever line the cursor is on.
[+] dontbenebby|3 years ago|reply
Thanks for this. I still remind having one of the kindest TAs of my undergrad remark in a thick Ukrainian accent “ahhh, vi, a true master” and move on to helping folks use pico during a *nix programming primer.

(Sometimes ppl would demand I follow the syllabus. I don’t like to follow the guidelines.)

You could always use emacs if you’re into that kind of thing, but telling them you should use pico is like telling them to clean their dorm with equal parts bleach and ammonia soaked in castor beans.

(Don’t do that.)

[+] cryptonector|3 years ago|reply
What, an explanation of `g` but no mention of `gq`?? :)
[+] navan|3 years ago|reply
There are lots of useful g commands. See also thread above talking about g commands. My favorite is g;
[+] talkingtab|3 years ago|reply
The most annoying thing about vim/vi is that after using it for twenty years I still don't know all the useful things you can do with it. To put that in context, I find vim indispensable. And adding stuff like markdown preview and fzf integration just makes the problem worse. Sigh.
[+] christophilus|3 years ago|reply
False. The most annoying thing about vim is that I can’t type properly in web input boxes, email clients, rich text editors… I want vim in all the places.
[+] b93rn|3 years ago|reply
I don't care if i'am not using every feature in Vim. I gave up on NVIM, because i was completely done with configuring plugins with bad documentation, no good defaults. For every plugin i needed to learn more and more shortcuts. After an update some plugins were broken etc. I just now stick with VSCode with the NVIM plugin.
[+] dotancohen|3 years ago|reply
Twenty years on VIM and I didn't know:

  gI - Insert text at the beginning of the line, no matter what the first characters are.
There's always more to learn.
[+] quesera|3 years ago|reply
Does this differ from 0i ?

  0  move to beginning of line
  i  enter insert mode before current char
[+] ngcc_hk|3 years ago|reply
As a beginner user for decades, some basic like visual mode is not covered even in the intermediate one. And so is plug-in not in advanced one.

Not sure about this arrangement.

[+] jb3689|3 years ago|reply
This is a good list. I need to get more comfortable with quickfix and location. I’d like to build something like the fzf plug-in some day

I’d highly recommend folks learn some vimscript. Mappings, functions, commands. My most recent use for these was for quickly generating a lot of permalinks for building internal documentation. Macros and argdo are also invaluable for large scale edits.

[+] johncoltrane|3 years ago|reply
The range injected for you by Vim when you do `:` in visual mode? Registers? Substitutions? Really?

There is nothing advanced about this and nothing to learn for an "advanced user".

[+] argonaut07|3 years ago|reply
I am struggling to get started on a German keyboard. Some special characters are hard to reach.
[+] jdrek1|3 years ago|reply
I recommend using the American keyboard layout if you're doing anything remotely programming related, otherwise all the special characters are just way too annoying (even though personally there's also a few of those in the American layout that are suboptimal, but a keyboard only has so much space...).

If you frequently find yourself needing German (or other European) symbols like ä then you can also look into using EurKEY [1] which is basically the American layout but gives you easy access to the "umlauts".

[1] https://eurkey.steffen.bruentjen.eu/

[+] FranklinMaillot|3 years ago|reply
Have you tried the US-International layout[0]? It's basically the standard QWERTY US layout but ", ', ^ are dead keys used to generate diacritics.

If you press " followed by o you get ö.

' + e prints é.

The only thing to get used to is that if you want quotes for example, you need to press <space> or another character that doesn't accept accents after the key. I used this layout for French and it's way better than the weird French AZERTY layout.

[0] https://en.wikipedia.org/wiki/QWERTY#US-International

[+] Daunk|3 years ago|reply
I enjoy using Vim, but I feel like it's a pain to use with lesser known languages. Especially when it comes to compiling and such.
[+] TheRealDunkirk|3 years ago|reply
Meh. I used vim for 20 years. Got to the point of tricking it all out with some of the full-blown ~/.vim configs you can just grab from GitHub. Some of the advanced tips on that site take it into the realm of being emacs. But I found that I was basically trying to get it to be... a GUI, with NERDtree and the lot. When I discovered Sublime Text, and multiple cursors, I quickly gave up on vim. I develop web applications (mostly). I'm pointing and clicking all throughout the process, since web pages are inherently graphical. I still haven't masted all of the keybindings for ST, but I think that being obstinate about keeping my hands on the keyboard when I'm editing is a waste of mental effort. YMMV. I think my lack of being able to fly through editor options without using a mouse cost me a job once, but if a place is going to fetishize that over being a deep expert with 25+ years of experience, go for it. I can solve business problems with software.

* Edited for "Sublime Text," though I don't know why I'm bothering, as this is being downvoted.

[+] bloopernova|3 years ago|reply
I think it's being downvoted because people may be interpreting the opening "meh" as too negative. Or possibly not meeting the standards of Hacker News.
[+] JadeNB|3 years ago|reply
What's the point of leaving a long comment on a post about vim detailing how and why you aren't interested in vim, or about how vim doesn't meet your needs? There are lots of posts here on HN about things that don't interest me, but probably not everyone needs to know about it.
[+] layer8|3 years ago|reply
What’s ST?
[+] dopp0|3 years ago|reply
pardon me, but what is ST?