- 好不容易用英语写完了, 懒得翻译了
Basic Usage
Normal Mode
- First Open file with VIM command, with get into Normal Mode
h``j``k``l:←``↓``↑``→dd: delete current linex: delete current characteryy: copy current linep: paste. It will paste last copied, cut or deleted texts.^: go to first non-blank character in current line,$to the endu: undo,<C-r>: redo.g-/g+: go to older/newer text state.: repeat last actionN<command>: repeatCommandNtimes. For example,2dd: delete two linegg: go to first line,G: Go to last line,NG: Go to lineN(Nstands for a number, for example,10G)w: move cursor to the beginning of next word,e: move cursor to the end of next word%: match the closest{,[,(*: search forward for the occurrence of the word nearest to the cursor.,#: search backward.
Insert Mode
i: Get into Insert Mode,Escback to Normal ModeI: Start to insert text at the beginning of the current lineo: Begin a new line below the cursor and insert textO: Begin a new line above the cursor and insert text
Command Mode
- Execute command (
:), search patterns (/and?), and filter commands (!) :wq: Save then quit,:q: Quit,:w: Save,:q!: Quit current file without saving,:qa!Quit all files without saving:e <path/to/file>: Open another file:saveas <path/to/file>: Save as another file
Advance Usage
Insert Mode
gi: goto Insert mode where you left it last time
Normal Mode
<C-y>,<C-e>: check the text above or below the cursor<C-w>w: Switch windows between last one and current one<C-w><dir>:<dir>can beh``j``k``l, switch windows to left, down, up or right.to move at current line
0→ head^→ non-blank head$→ endg_→ non-blank endfa→ to next characterat,→ to the character right before the next,3fa→ to the thirdaF,T→ same asf,twith reverse direction
manipulate a text block
<C-v>, for example:add prefixes to multi lines

*^→ to the head of the line *→ Start to select a block of text *→ to move downward, you also can usehjk``lor%instead *I– → Insert–*[ESC]` → to make effects to every line
append text to multi lines
<C-v>→ Choose lines (You can also usej,<C-d>,/pattern,%, etc.$→ move cursor to the endA→ start to input text, type pressESC
indentation
J→ convert multi lines to single line<>→ indent to left or right=→ auto indent
Visual Mode
- Block Choosing
<action>a<object>or<action>i<object><action>can be any actions, liked(delete),y(copy),v(text selecting).<object>can bew(a word),W(a phrase),s(a sentance),p(a paragraph), or a special symbol like",',),},].For example:

vi"→ foova"→ “foo”vi)→ “foo”va)→ (“foo”)v2i)→ map (+) (“foo”)v2a)→ (map (+) (“foo”))
Command Mode
:split: split window horizontally,:vsplit: split window vertically.q: Record typed characters into register, then repeat them.qa: record every action into registera@a: replay it@@: to replay the latest registerFor example:
In this text file, only have “1” in it, start to input:
qaYp<C-a>qqa→ start to recordyyp→ copy current line to next line<C-a>→ add 1q→ stop recording@a→ write down 2 under 1@@→ write down 3 under 2100@@→ repeat it 100 times.
:[range]s/<pattern>/<replace>/{flags}: replace text- TODO
[range]
Plugins
Explanations of Important Keywords
<Leader>: default is\, you can change it by usinglet mapleader = ','in.vimrcfile.<CR>: equals<Return>&<Enter><S-...>: shift-key<C-...>: control-key<M-...>&<A-...>: alt-key<D-...>: command-key (Mac only)g:: means globally. Example:let g:last_active_tab = 1toggle switch between current tab and the last one globally.
remap: Allows for mappings to work recursively.noremap: Only a single entry. Can NOT be remapped.n&v&s&i: prefixes,nstands for Normal mode,vstands for Visual mode,sstands for Select Mode,istands for Insert Mode. Example:nnoremap <C-t> :tabnew<CR>: remapCtrl + tto create a new tabinoremap <C-t> <Esc>:tabnew<CR>: same as last one, with an escape action additionally.
<Plug>: in.vimrcfile, it has two meanings. First, it’s visible out of the plugin scripts. And the second, use structure<Plug> scriptname mapnameto avoid confliction with other plugins. For example:<Plug>TypecorrAdd,Typecorris the script name, andAddis the function name.<SID>: is the script ID and not visible outside. Compare with<Plug>, it’s more likeprivatefunction to other scrips. So can’t use it out of the script. Example:" ,en ,ep to jump between errors function! <SID>LocationPrevious() try lprev catch /^Vim\%((\a\+)\)\=:E553/ llast endtry endfunction function! <SID>LocationNext() try lnext catch /^Vim\%((\a\+)\)\=:E553/ lfirst endtry endfunction nnoremap <silent> <Plug>LocationPrevious :<C-u>exe 'call <SID>LocationPrevious()'<CR> nnoremap <silent> <Plug>LocationNext :<C-u>exe 'call <SID>LocationNext()'<CR> nmap <silent> <Leader>ep <Plug>LocationPrevious nmap <silent> <Leader>en <Plug>LocationNext<silence>: to make a key mapping can`t be echoed on the command line<expr>take the argument as expression. For example:inoremap <expr> <C-L> ListItem(), ListItem is a function which is mapped withCtrl + L.
unblevable/quick-scope
Github Repo: unblevable/quick-scope
Useage: highlights which characters to target for
f,Fand family.Key Mapping:
let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] //
ntpeters/vim-better-whitespace
Github Repo: ntpeters/vim-better-whitespace
Useage: clean extra whitespace.
Key Mapping:
nnoremap <silent> <Leader><Space> :StripWhitespace<CR> autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl autocmd BufWritePre <buffer> StripWhitespace let g:better_whitespace_filetypes_blacklist=['diff', 'gitcommit', 'unite', 'qf', 'help']
Vim-CtrlSpace
Github Repo: vim-ctrlspace/vim-ctrlspace
Useage:
- bookmarks for your favorite projects
- workspaces (sessions)
- tabs / buffers / files management
- fast fuzzy searching powered by Go
Shortkeys:
Ctrl + Space: open ctrl space command lineb: bookmark listw: workspace list in current bookmarkl: tab list in current workspaceo: file list in current workspaceh: buffer list in current workspace, this is default list when you hit ctrl + space/: Into Search Mode, type it again will close search mode. Aka,B,W,L,O,Hwith uppercase will open the same list with Search Modei: switch directory (when you on the buffer list)a: all the files are opend in current workspaces: save current workspace/bookmark, then<CR>to confirmd: delete a file from current buffer or file listj,k: switch items, then<CR>to confirmm: rename bookmark or workspace(when you on the workspace list or bookmark list)
Key Mapping:
if has("gui_running") " Settings for MacVim and Inconsolata font let g:CtrlSpaceSymbols = { "File": "◯", "CTab": "▣", "Tabs": "▢" } endif if executable("ag") let g:CtrlSpaceGlobCommand = 'ag -l --nocolor -g ""' endif let g:CtrlSpaceSearchTiming = 500 hi link CtrlSpaceNormal PMenu hi link CtrlSpaceSelected PMenuSel hi link CtrlSpaceSearch Search hi link CtrlSpaceStatus StatusLine nnoremap <silent><C-p> :CtrlSpace O<CR> let g:CtrlSpaceLoadLastWorkspaceOnStart = 1 let g:CtrlSpaceSaveWorkspaceOnSwitch = 1 let g:CtrlSpaceSaveWorkspaceOnExit = 1
scrooloose/nerdtree & jistr/vim-nerdtree-tabs
TODO
Github Repo: scrooloose/nerdtree & jistr/vim-nerdtree-tabs
Useage: to explore filesystem and to open files and directories.
Key Mapping:
" nerdtree map <C-n> :NERDTreeToggle<CR> let NERDTreeHighlightCursorline=1 let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ] "close vim if the only window left open is a NERDTree autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end let g:NERDTreeMapOpenSplit = 's' let g:NERDTreeMapOpenVSplit = 'v' let g:NERDTreeWinSize=26 " nerdtreetabs map <C-n> <plug>NERDTreeTabsToggle<CR> let g:nerdtree_tabs_synchronize_view=0 let g:nerdtree_tabs_synchronize_focus=0 let g:nerdtree_tabs_open_on_console_startup=0 let g:nerdtree_tabs_open_on_gui_startup=0
syntastic
Github Repo: vim-syntastic/syntastic
Useage: a syntax checking plugin
Key Mapping:
execute pathogen#infect() let g:syntastic_error_symbol='>>' let g:syntastic_warning_symbol='>' let g:syntastic_check_on_open=1 let g:syntastic_check_on_wq=0 let g:syntastic_enable_highlighting=1 " checkers let g:syntastic_php_checkers = ['php', 'phpcs', 'phpmd'] let g:syntastic_python_checkers=['pyflakes', 'pep8'] " 使用pyflakes,速度比pylint快 let g:syntastic_python_pep8_args='--ignore=E501,E225,E124,E712' let g:syntastic_javascript_checkers = ['jsl', 'jshint'] " let g:syntastic_markdown_checkers = ['proselint'] let g:syntastic_html_checkers=['tidy', 'jshint'] set statusline+=%#warningmsg# set statusline+=%{SyntasticStatuslineFlag()} set statusline+=%* " to see error location list let g:syntastic_always_populate_loc_list = 1 let g:syntastic_enable_signs = 1 let g:syntastic_auto_loc_list = 0 let g:syntastic_auto_jump = 0 highlight SyntasticErrorSign guifg=white guibg=black
YouCompleteMe
Github Repo: Valloric/YouCompleteMe
Useage: code completion
Key Mapping:
let g:ycm_key_list_select_completion=['<C-j>'] let g:ycm_key_list_previous_completion=['<C-k>'] let g:ycm_complete_in_comments = 1 let g:ycm_complete_in_strings = 1 let g:ycm_use_ultisnips_completer = 1 let g:ycm_collect_identifiers_from_comments_and_strings = 1 let g:ycm_collect_identifiers_from_tags_files = 1 let g:ycm_seed_identifiers_with_syntax=1 let g:ycm_goto_buffer_command = 'horizontal-split' nnoremap <leader>jd :YcmCompleter GoToDefinitionElseDeclaration<CR> nnoremap <leader>gd :YcmCompleter GoToDeclaration<CR> if !empty(glob("~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py")) let g:ycm_global_ycm_extra_conf = "~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py" endif
vim-easymotion
Github Repo: easymotion/vim-easymotion
Usage: Provides a much simpler way to use some motions in vim.
Keys Mapping:
let g:EasyMotion_smartcase = 1 " <Leader>f{char} to move to {char} map <Leader><Leader>f <Plug>(easymotion-bd-f) nmap <Leader><Leader>f <Plug>(easymotion-overwin-f) " s{char}{char} to move to {char}{char} nmap s <Plug>(easymotion-overwin-f2) " Move to line map <Leader><Leader>l <Plug>(easymotion-bd-jk) nmap <Leader><Leader>l <Plug>(easymotion-overwin-line)
easyalign
Github Repo: junegunn/vim-easy-align
Usage: alignment
Keys Mapping:
vmap ga <Plug>(EasyAlign) nmap ga <Plug>(EasyAlign) let g:easy_align_ignore_groups = ['Comment', 'String'] let g:easy_align_delimiters = { \ '>': { 'pattern': '>>\|=>\|>' }, \ '/': { \ 'pattern': '//\+\|/\*\|\*/', \ 'delimiter_align': 'l', \ 'ignore_groups': ['!Comment'] }, \ ']': { \ 'pattern': '[[\]]', \ 'left_margin': 0, \ 'right_margin': 0, \ 'stick_to_left': 0 \ }, \ ')': { \ 'pattern': '[()]', \ 'left_margin': 0, \ 'right_margin': 0, \ 'stick_to_left': 0 \ }, \ 'd': { \ 'pattern': ' \(\S\+\s*[;=]\)\@=', \ 'left_margin': 0, \ 'right_margin': 0 \ } \ }
NerdTree
Github Repo: scrooloose/nerdtree
Usage: to explore your filesystem and to open files and directories.
Keys Mapping:
map <leader>n :NERDTreeToggle<CR> let NERDTreeShowBookmarks=1 let NERDTreeHighlightCursorline=1 let NERDTreeIgnore=[ '\.pyc$', '\.pyo$', '\.obj$', '\.o$', '\.so$', '\.egg$', '^\.git$', '^\.svn$', '^\.hg$' ] "close vim if the only window left open is a NERDTree autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | end let g:NERDTreeMapOpenSplit = 's' let g:NERDTreeMapOpenVSplit = 'v' let g:NERDTreeWinSize=26
NERDCommenter
Github Repo: scrooloose/nerdcommenter
Usage: to wrangle your code comments.
Shortkeys:
[count]<leader>cc: Comment out the current line or text selected in visual mode.[count]<leader>c<space>: Toggles the comment state of the selected line(s). If the topmost selected line is commented, all selected lines are uncommented and vice versa.[count]<leader>cs: Comments out the selected lines with a pretty block formatted layout.[count]<leader>ci: Toggles the comment state of the selected line(s) individually.
Keys Mapping:
" Add spaces after comment delimiters by default let g:NERDSpaceDelims = 1 " Use compact syntax for prettified multi-line comments let g:NERDCompactSexyComs = 1 " Align line-wise comment delimiters flush left instead of following code indentation let g:NERDDefaultAlign = 'left' " Allow commenting and inverting empty lines (useful when commenting a region) let g:NERDCommentEmptyLines = 1
Airline
Github Repo: vim-airline/vim-airline
Usage: rich statusbar.
Keys Mapping:
if !exists('g:airline_symbols') let g:airline_symbols = {} endif let g:airline_mode_map = { \ '__' : '-', \ 'n' : 'N', \ 'i' : 'I', \ 'R' : 'R', \ 'c' : 'C', \ 'v' : 'V', \ 'V' : 'V', \ '' : 'V', \ 's' : 'S', \ 'S' : 'S', \ '' : 'S', \ } let g:airline_left_sep = '❯' let g:airline_right_sep = '❮' let g:airline_symbols.linenr = '¶' let g:airline_symbols.branch = '⎇'