Tasty List of Danq Vim Tips

Table of Contents

The Problem

Vim, ah it’s so lovely. Can’t say enough good things and it’ll go on forever so I won’t. Bad things though? Yes, definitely. The main one being you find yourself pressing 4 keys and you realize there is probably some danq built in shiz you could do which would do that automatically through the whole file, fixing your spelling mistakes on yesterday’s, and organizing the indentations on your neighbour’s thesis. The problem is this is so common that it’s impossible to remember all the neat tricks you’ve found that are built in. To help rectify this, I’m just going to keep a running list of random things I come across which are useful in my usecases. Just to get started, use ZZ to write and quit and ZQ to :q!

ViM Tips and Tricks I’ll forget

While I’ve used this now for ages there are so many combos of simple keys and additional things which I learn and relearn and forget so I’m going to keep track of some of them here for reference. This document can be referenced as a PDF or it can be opened in ViM and used as practice. Hence some of the random Wikipedia pastings in here, these are just for different formatting of lots of text as I mainly use this as a word processor.

Moving around

Aside from the obvious ‘hjkl’ for moving, there are a few other ways to move around pages quicker. Below are just a list of some noice ones:

  • ‘gj’ and ‘gk’ will move among the line if its wrapped
  • CTRL+U will go up about a third of the page and CTRL+D does the same down
  • You can append any movements with a number, looking at the relative number on the side, to jump that far
  • ‘G’ and ‘gg’ are obvious but then, if you want to return to where you where, you can do CTRL+o
  • You can always search with /something or go backwards with ?something and then hit return to jump to something if you see it
  • ‘H’ is the top of the visual screen
  • ‘M’ is middle
  • ‘L’ is the bottom of the visual page
  • ‘{’ will move backward or ‘}’ forward by paragraph
  • ‘f+(a letter)’ will find the next iteration of that letter and jump forward to it in the line then use ‘;’ to repeat the command to keep moving by that letter
  • ‘zz’ moves the cursor to the center of the window

Pasting and the clipboard

Oh yes this is so cool but so over the top for something made in the 90s when there was no memory in computers. The ViM register system. So you can copy with the classic: ‘y’ or paste with the classic: ‘p’ But this gets confusing because deleting things also puts them in your register, which means you’re essentially always cutting and never deleting in ViM.

So, there are 26 registers lol, one for each letter. You use them by: ‘"(pick a letter)(operator being d or y or p or whatever)’ and so you can choose where you’re deleting or copying into and where you’re pasting from. The fancy bit here then comes how you go to and from your system clipboard and paste into a different window or paste something from elsewhere. There is a register with the + sign which, if you use that, it will be available when you CTRL+V outside ViM or if you copy something somewhere and you’re then in ViM and you paste with “+p it’ll take what you copied from outside.

  • You can ‘yi)’ for example anywhere on a line with ) not only inside them.

This can get annoying though because what always happens is you copy something then end up going over to paste it but realize that you’ve actually copied something else and gotten rid of what you wanted to paste, or so you thought.

  • Typing :registers will show you everything in all your registers, you can then use the corresponding one with the " to paste

There is a strange behavior when using the ‘.’ command which usually repeats what you last did in insert mode. You can use this to cycle through all the crap you’ve accidently yanked to get to what you want! If you paste with “1p to put the first thing down but its wrong, you can ‘u’ to undo, then press ‘.’, and it will move to the next thing! How swagger.

The letter G or maybe g

So a lot of the times there are many a words in a line in the actual text file and the line wraps much like it does here. This is treated as a single line so using ‘j’ to go down for example will skip the whole thing. Appending ‘g’ ahead of ‘j’ will fix that. Other cool things you can do with ‘g’ and many lines:

  • ‘g CTL+a’ somehow will increment numbers if you have a repeating line with a number in it posted a bunch of times?!
  • ‘gqq’ will enter all lines in a paragraph such that they actually break apart to the window width. So will ‘gwap’ as in wrap around paragraph.
  • ‘G’ goes to the top, ‘gg’ the bottom, but if you’re then lost CTRL+o brings ya back to where you were before you started hoping around.
  • ‘gv’ will reselect the last thing you had selected even after making many edits
  • ‘gu’ will uncaps and ‘gU’ will add caps. You can do this then to other modes for example ‘gU4j’ to uppercase an entire 4 lines down.

Spell Checking

Very useful for when writing documents. As far as I can remember having set=spell in the .vimrc puts the spell check on by default when you launch it. Might even be default in nViM which is what obviously you’re actually using. Depending on theme misspelled words are underlined or highlighted. There is a distinction for a correctly spelled word but in the wrong region for what your dictionary is set to. Now for some keys

  • ‘]s’ to jump forward between misspelled words, ‘[s’ to go back duh, ‘S’ will skip regional misspellings just big booboos
  • ‘z=’ whenever on any place of a misspelled word brings the correction list, choose the number and press enter to replace
  • ‘zg’ when on a misspelled word adds it to the dictionary, ‘zug’ removes it
  • ‘zw’ adds correct words to misspelled list, like a words to avoid list ‘zuw’ removes

Norm mode and Macros

This is where it gets straight wild and I’m not even sure how to organize this section. But for now I’m just going to make bullet points about things that I think to be semi related at the moment. I’ll work out a better way to organize this later

  • When using :norm mode, you can press CTRL+V then ESC to put the character in which then takes what you’re typing back to normal and not insert mode
  • You can @ your macros within normal mode. Think of this as maybe a nice way to select a block or paragraph and then run a macro if there are issues with the way the cursor ends at the end of the macro.

Lists Jumps Marks Changes Fixes?

Okay this has a lot in it and I don’t understand it much yet. Just to note, Vim keeps track of changes, jumps, marks which you add yourself, and errors which you can use to jump between them all supah fast. Easy example.

  • You’re typing, you escape, you search and skip to new part of the file, CTRL+o will bring you back one jump, to where you where. This works backwards even across files.
  • You can see jumps by doing :jumps
  • You can see marks by doing :marks

Misc

  • You can increment things?! This is so awesome and so random. Highlight any number just having your cursor over it, CTRL+A goes up and CTRL+X goes down. So handy!

  • Along these lines, if you paste something with a number 10 times for example, you can highlight the whole thing, “g then CTRL+a” will increment the entire list?

  • I do not understand how this works, but if you ‘gg’ to the top, then press “g=G” you’ll move to the bottom whilst fixing all the indentation for the whole document?

  • One shot mode, CTRL+o when in insert mode lets you do one normal mode motion before returning to insert mode