Notes on vim

May 19th, 2010 by papillon

Movement
f,F Find char, find char backwards
; Repeat last find
zL Scroll half a screenwidth to the left

Copy and paste
"ay Copy visual selection to register A
"ap Paste from register A

Mark
ma Set mark “a”
'a Go to mark “a”

Searching

/ Search forward
? Search backward

:vimgrep /my_search_term/ **/*.c Recursively search all .c files
:cnext Jump to next hit
:clist Show hits
:cc n
Jump to hit no. n:

Replace
:%s/search/replace/g
%s whole file (range)
/g replace every instance

Tab / window management
Open one tab for each buffer in the buffer list
:tab ball

Enable tab-completion window:
:set wildmenu

Close (split) window:
Ctrl+W C

Previous / next tab:
Ctrl+PgDn / Ctrl+PgUp

Create / close tab:
Ctrl+Ins / Ctrl+Del
… via mappings created using the following line in .vimrc:
nmap <C-Insert> :tabnew<CR>
nmap <C-Delete> :tabclose<CR>

Folds
zo/O Open one/all folds under cursor
zc/C Close one/all folds under cursor
zR Open all folds

Color
xterm 256 notes

Misc
Reindex help (after plugin installation):
:helptags C:\Program Files\Vim\vimfiles\doc

Add/remove CRLF
To remove all carriage-returns at end-of-line:

:set fileformats=
:e ++ff=dos filename
:setlocal ff=unix
:w

To repair any lines where a CR is missing, (by adding it):
same as above, but omit the line with “:setlocal ff=unix”.

Whitespace
:set list Show whitespaces
:set nolist Stop showing whitespaces
:set expandtab Insert space characters whenever the tab key is pressed
:set tabstop=2 Each tab = 2 spaces
:retab Change all the existing tab characters to match the current tab settings (expandtab)

Links
VIM FAQ
Working with Unicode


1 Response to “Notes on vim”

  1. 1

    machine