My personal config ($HOME/.vimrc
)
set nobackup set noswapfile set noundofile set tabstop=4 shiftwidth=4 set number set showmatch " sometimes i lose this - not sure why :( syntax on " this is what i use on slackware (dwm) colorscheme elflord " F5 shortcut to remove trailing whitespace nnoremap <F5> :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
Basic Usage (Command Mode) | |
---|---|
Keys | Function |
:w | Write/save file |
:x | Save and quit |
:q | Quit |
:q! | Quit (Force) |
:set nu | Display line numbers |
:noh | No highlights |
Entering Insert Mode | |
Keys | Function |
i | insert at current position |
a | insert after current position |
I | insert before the current line |
A | insert after the current line |
o | insert a new line after the current line |
O | insert a new line before the current line |
C | ovewrite the whole current line |
Cursor Movement | |
Keys | Function |
h | move left |
j | move down |
k | move up |
l | move right |
w | move to next word |
b | move to the start of the word |
e | move to the end of the word |
( | move previous sentence |
) | move next one sentence |
{ | move previous paragraph |
} | move next paragraph |
^ | move to the beginning of the line |
$ | move to the end of the line |
<n>G | move to the n-th line |
G | move to the last line |
gg | move to the first line |
% | move to the matching bracket |
Select/Copy and paste | |
Keys | Function |
yy | Yank/copy current line |
yw | Yank/copy next word |
ynj | Yank/copy next n lines |
y$ | Yank to the end of the line |
p | Paste after cursor |
P | Paste before cursor |
Deleting | |
Keys | Function |
x | Delete a single character |
D | Delete the rest of the line |
dd | Delete current line |
ndw | Delete the next n words |
ndd | Delete the next n lines |
:m,nd | Delete from line m through to line n |
Visual Mode | |
Keys | Function |
Shift+v | Enter visual mode |
Code Folding | |
Keys | Function |
zfa} | Fold code in curly braces |
zc | Close code folding |
zo | Open code folding |
za | Toggle code folding |
zd | Delete fold marker |
Dumped…
Search and Replace /pattern Search for pattern. n Find the next occurrence of pattern. :%s/pattern/replace/g Replace every occurrence of pattern with replace.. Paste from clipboard Shift+Insert in insert mode!
Dumped…
Opening
:e filename
note: or simply specify multiple names at command line
Switching between files
:n Or :bn - switch to the next file :N Or :bp - switch to the previous file :bf - switch to the first file :bl - switch to the last file :b number - switch to a specific file number(for file number 3, use the command “b 3”): :b filename - switch to a specific file filename(for file name file1, use “:b file1”) :wall - save all open files :bw - quit the current file qall - quit all open files :qall! - forcefully quit all the files, discarding the changes :ls - list opened files
Multiple view
split horizontal (2-rows,top/bottom) $ vim -o file1 file2 split vertical (2-columns,side-by-side) $ vim -O file1 file2 :split filename :vsplit filename Ctrl+w,j - switch to the next window below the current window Ctrl+w,k - switch to the next window above the current window Ctrl+w,l - switch to the next window to the right of the current window Ctrl+w,h - switch to the next window to the left of the current window ctrl+w,w - cycle through all Vim windows ctrl+w,x - exchange?? Vim windows ctrl+w,r - rotate layout of all Vim windows