Skip to content

Instantly share code, notes, and snippets.

@klmr
Created January 22, 2014 11:46
Show Gist options
  • Save klmr/8557389 to your computer and use it in GitHub Desktop.
Save klmr/8557389 to your computer and use it in GitHub Desktop.
Notes for the seminar “Using Vim” for the Predoc Lunch Seminar series at EMBL-EBI.

Vim Notes

Setup

The Vim on the server is horribly outdated. Many of the things below won’t work, or will require extensive setup. In order to ease the pain, I suggest using the version installed and maintained by Micha via the EBI-predoc config.

If you’re using this version of Vim, it will also already come with some plugins (notably YouCompleteMe) pre-configured. I haven’t tried this yet, though, so I don’t know how the configuration works for that.

Notable options

  • hlsearch, incsearch, ignorecase, smartcase: More useful search
  • undofile, undodir: Infinite, persistent undo
    • NB: Requires up-to-date vim
  • autoread, autowrite: Automatically save & load file content after change
  • list, listchars: Show invisible characters
  • autocmd: Perform action when condition is met (file loaded …)
    • E.g. autocmd FileType make setlocal noexpandtab

Creating shortcuts

  • {nvxsilc}{nore}map: Map a key (combination) to something else
    • E.g. nmap <leader>x :echo "Hello"<CR>

Editor commands

Movement commands

Apart from the trivial cursor movements (hjkl):

  • g: go somewhere
    • [#]gg, [#]G: go to line # (default first / last)
    • g0, g^, g$: go to start / first non-blank character / end of line
  • H, M, L: go to top / middle / bottom of screen
  • e, w, b: Move to end of / beginning of next / beginning of previous word
  • f‹character›, F‹character›: go to next / previous ‹character› in line
  • ': go to marker
    • '': go to previous cursor location in file
    • m‹letter›: set marker ‹letter›
    • '‹letter›: go to marker ‹letter›
  • %: go to matching brace / parenthesis
  • (, ): go back / forth one sentence
  • {, }: go up / down a paragraph

Movement commands can be combined with actions: d'a deletes everything from the current cursor position until the line designated by marker a.

Movement commands can be prefixed by numbers: 7{ goes up seven paragraphs.

Basic action commands

  • i, a: insert before / after cursor
  • I, A: insert at start / end of line
  • o, O: insert new line after / before current
  • r‹character›: replace selection with ‹character›
  • v, V, Ctrl-V: start (or stop) selection (“visual mode”) of characters / lines / vertical block
  • c: change text of movement or selection
  • x: delete characters of movement or selection
  • d: delete characters of movement or selection
    • dd, D: delete whole line
  • >, <: indent, dedent movement or selection
  • =: re-indent movement or selection according to syntax rules
  • gq: break lines of movement or selection after maximum textwidth
  • y: copy movement or selection into register (kind-of clipboard)
    • yy, Y: copy whole line
  • p, P: paste register after / before cursor position
  • /, ?: search forward / backwards
    • n, N: go to next / previous hit
  • q‹letter›, q: start / stop recording of macro into register ‹letter›
    • @‹letter›: play back macro in register ‹letter›
  • J: join next line to current

Remember: combine! 3>} indents the rest of the paragraph by three tabs. gg=G re-indents the whole file (start to end) using the current syntax rules.

Special movement commands

These movements can be appended to an action command to denote a scope. For instance, gq (see above) breaks lines to limit them to textwidth length. gqap applies this to a paragraph.

  • aw, as, ap: select a word / a sentence / a paragraph
  • ab or a(: select a block in parentheses
  • aB or a{: select a block in braces
  • iw, is, ip, ib, i(, iB, i{: like above, but stay inside the selection with cursor (e.g. don’t select the delimiting parentheses).

For instance, vi(p replaces the content inside parentheses with the content of the clipboard register.

Notable plugins

  • Vundle: Plugin package manager
  • YouCompleteMe: The only auto completion you’ll ever need
    • NB: Requires up-to-date vim
  • r-plugin: Vim-R integration. R-Studio on ’roids.
  • syntastic: On-the-fly code error checking
  • ctrl-p: Full path fuzzy file finder
  • vim-gitgutter: Shows version tracking changes in gutter

Other resources

  • vim-github: Github mirror of the Vim plugins
  • Solarized: The One True™ colour scheme Install via Vundle: Bundle 'altercation/vim-colors-solarized'. However, this has some issues in the terminal which are solved easiest by setting Solarized as the terminal’s colour scheme, in addition to Vim’s. The website contains detailed instructions on how to do this for each terminal emulator.
  • My dot-files, including my .vimrc
  • Exhaustive (!) Vim cheat sheet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment