Vi

From Supernifty
Jump to: navigation, search

Vi (or Vim) is a spectacular editor. This is a quick reference to some handy vi tricks.

Contents

Display

  • Line numbers - :set number
  • Line and column - :se ruler
  • Tabs and line endings - :se list
  • Tabs
    • Tabspace :se ts=2
    • Expand tabs :se et
  • Match braces - :se sm

Recording

  • qq - start recording (to register q)
  • q - stop recording
  • @q - execute recording in register q

Substitutions

  •  %s/./\L&/g - lower case whatever . matches
  • ~ toggles the current character between lower and upper case.

Autocomplete

  • ctrl-p - simpler auto-remember style

Enabling

autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType php set omnifunc=phpcomplete#CompletePHP

Using

  • Invoke - ctrl-x ctrl-o
  • Accept - ctrl-y
  • Cancel - ctrl-e
  • Next - ctrl-n
  • Previous - ctrl-p

Buffers

  •  :ls, :buffers - list buffers
  •  :b1 - switch to buffer 1
  •  :1bw - close buffer 1
  •  :bd - close current buffer

Folds

Enabling

:se foldmethod=indent
:se shiftwidth=2 # or whatever tabspace

Using

  • zc - close fold
  • zo - open fold
  • za - toggle fold

Doc

  • K - search for help on the word under the cursor

Python Doc

:au FileType python set keywordprg=pydoc

Registers

:registers = to see the contents of all registers

  • The + register represents the system clipboard
"ayy yank into "a" register
"ap  paste "a" register

Viewports

:vsplit - vertical split
:split - horizontal split
^w w - to move between them
Actions
Navigation
Toolbox
Advertisement