Three modes
[normal] Esc
[insert] i, I
[visual] v, C+v (visual block)
Basic commands
:w write out
:q quit
:q! force quit
ZZ write the file and quit
dd delete one line
3dd delete three lines
D delete portion of current line to right of the cursor
p paste
u undo
C+r redo
w move cursor one word to right
b move cursor one word to left
0 move cursor to beginning of line
$ move cursor to end of line
nG move cursor to line n
C+f scroll forward one screen
C+b scroll backward one screen
a append to right of current cursor position (end with ESC)
dw delete current word (end with ESC)
ma mark currrent position
d`a delete everything from the marked position to here
`a go back to the marked position
/string search forward for string (end with Enter)
n repeat the last search (``next search'')
:s/s1/s2 replace (``substitute'') (the first) s1 in this line by s2
:%s/s1/s2 replace (``substitute'') (the first) s1 by s2 in filewide
% go to the "mate," if one exists, of this parenthesis
or brace or bracket (very useful for programmers!)
Advanced commands
:syntax on syntax coloring
move cursor to the defination of a function(variable): 1. ma 2. gD
visual block operations:
1. C+v -- swicth to visual block mode
2. select rectangular region
3. I -- switch to insert mode and do editing in the selected region, e.g. put "//" there
4. Esc -- back to the normal mode
5. you can also delete a rectangle region by hit "d"
Customize your vim
put ~.vimrce.g.
set visualbell " Silence the bell, use a flash instead
set cinoptions=:.5s,>1s,p0,t0,(0,g2 " :.5s = indent case statements 1/2 shiftwidth
" >1s = indent 1 shiftwidth
" p0 = indent function definitions 0 spaces
" t0 = indent function return type 0 spaces
" (0 = indent from unclosed parantheses
" g2 = indent C++ scope resolution 2 spaces
set cinwords=if,else,while,do,for,switch,case " Which keywords should indent
set formatoptions=tcqor " t=text, c=comments, q=format with "gq",
" o,r=autoinsert comment leader
set cindent " indent on cinwords
set shiftwidth=2 " set shiftwidth to 4 spaces
set tabstop=2 " set tab to 4 spaces
set showmatch " Show matching brackets/braces/parantheses.
"set background=dark " set background to dark
set showcmd " Show (partial) command in status line.
set autowrite " Automatically save before commands like :next and :make
set textwidth=98 " My terminal is 98 characters wide
colorscheme evening
syntax on
" Cleanup
function! Clean_up()
set visualbell&
set cinoptions&
set cinwords&
set formatoptions&
set cindent&
set shiftwidth&
set tabstop&
set showmatch&
"set background&
set showcmd&
set autowrite&
set textwidth&
"unmap
"unmap
"unmap
"unmap
"unmap
endfunction
No comments:
Post a Comment