Skip to content

Instantly share code, notes, and snippets.

@chrisman
Last active December 12, 2021 21:37
Show Gist options
  • Save chrisman/99cc109416011f853018e7898d832873 to your computer and use it in GitHub Desktop.
Save chrisman/99cc109416011f853018e7898d832873 to your computer and use it in GitHub Desktop.

So you wanna vim!

one of us! one of us!

Prerequisites

Movement

  • hjkl actually isn't any better than arrow keys. If you find yourself holding down l, stop and think about what you're doing. Use f or t, /<fragment>, or text objects to jump around. (w, ), }, etc. :help objects for more.)

  • I prefer :set relativenumber number for line numbering. That way I can always see what line I'm on, and can see how far away lines are so I can 11j for example, and so I can tell at a glance that I want to 5dd without having to stop to count.

  • You can move lines with :m. Instead of dd7kp, you can :m-7. If you want Atom style moving lines up and down, remap something like Alt-k or the up arrow to :m-1, and its analog to :m+1.

"basics"

Concepts that I consider to make vim great

  1. registers

  2. macros

  3. marks

  4. repeat

useful commands

Stuff I use a lot

  1. :help - Just read it.

  2. All the basic movement commands like f and F, t and T, and : and ; to repeat forward and backward those "find"s and "to"s

  3. ^[ sends escape. very nice if you've mapped caps lock to CTRL

  4. * Find word under cursor

  5. gx Open URL under cursor. (gf: open file path under cursor.)

  6. % Find matching bracket

  7. >> indent (<< un-indent)

  8. ^z suspend. drop into the shell. (if you're in the terminal.) Do your stuff, then fg to bring vim back to the "foreground".

  9. H, M, L jump to top, middle, bottom of screen. ("High", "Medium", "Low")

  10. zz move current line to middle of screen. (see also zt and zb)

Weird stuff

  1. g?<dir> - rot13. g?? a whole line

Plugins

For the longest time, I didn't use any plugins. Now I do. ¯_(ツ)_/¯

Check out https://vimawesome.com/

A couple of favs:

  • NERDTree
  • fugitive and gitgutter
  • vim-surround
  • emmet-vim
  • vim-airline

suggestions

  1. keep your vimrc in a git repo. so you can pull it down where ever you are. snoop people's vimrcs on github. Here's mine: https://github.com/chrisman/dotfiles/blob/master/vimrc

other resources

appendix

Q. What kind of vim to use?

A. Use vim or neovim. (I use neovim.) Avoid using a GUI like gvim or macvim. One of the glorious things about vim in the terminal is having quick access to the command line and to UNIX utils. And being able to quickly suspend (c-z) and drop into a shell or into a REPL.

Q. How many different places can I use "vim"?

A. A lot. Most text editors support vim keys, or have a "vim mode" to various degrees. Including online editors like codepen. I make prodigious use of the vimium plugin in both Chrome and Firefox for a superior browser experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment