即將失傳的古老技藝Vim
- 教学视频:即將失傳的古老技藝 Vim
02 Install vim¶
Windows: gvim
03 Type in vim¶
- Toggle Input mode:
ikey - Toggle Command mode:
esckey orctrl+[
04 Move cursor¶
- in Command mode, type
hjklto move cursor
05 Move faster¶
wfor jump a word forward,W表示可以跳过标点符号b与w相反,是往前跳单词,B也可以跳过标点符号Gjump to file end,ggjump to file start0jump to line start,$jump to line endgjjump to up block(上方的区块),gkjump to down block
06 Search text¶
- /TEXT_TO_SEARCH
- :set hlsearch 把搜索结果高亮
njump to next search result,Nfor previousi- ?TEXT_TO_SEARCH The only difference is
norNkeys direction is reversed! *or#search current cursor text- :set nohlsearch turn off hlsearch
-
fajumpt to nexta, theais custom.Fajump to previousa -
zz让当前行显示在画面中间 ztto top,zbto bottom
07 Select Copy Paste¶
- Enter visual mode:
v, then you can select - In visualt mode, you can press
faFawbggGetc... just like command mode Vfor select whole lineyfor copy(yank), copied context is in register(寄存器)pfor paste,5ppaste 5 timesyycopy whole line,yyp,yy5p
08 More Select Copy Paste¶
2yycopy two lines...Ppaste before cursory$copy to line end,y0copy to line startywybyGygg...ufor undo,Rfor redo
Vim has multiple Registers
"aycopy selected to Registera"bycopy selected to Registerb..."appaste Registeracontent,"bp...-
:reg check all Register
-
:set clipboard=unnamed 让剪贴板和寄存器互通
09 How to edit text¶
Insertion
Ijump to line first and enter Insert mode,i...Ajump to line end and enter Insert mode,a...Ocreate a new line above current line and enter Insert mode,o...
Deletetion
xdelete character in current cursor, also worked in selected(Visual mode)ddelete what you are selected,Ddelete everything after cursor(in current line)dddelete one line,2dddelete two lines...dGdgg...cequals delete and enter Insert mode (pressdand pressi)ClikesDand thenirxreplace current cursor to letterx
Indentation(缩进)
>>indent right current line,3>>...<<indent left current line- :set shiftwidth=8 设置缩进距离
10 Edit multiple files¶
- :tabe Create new tab
- :tabe FILENAME Create new tab and open FILENAME
gtgTswitch tabs- :new Create new horizontal window,
ctrl+w+wloop switch opened windows,ctrl+w+jctrl+w+k... - :vnew Create new vertical window,
ctrl+w+hctrl+w+l... - vim -o file1 file2 Open multiple files in vertical window at once
- vim -O file1 file2 (horizontal)
- vim -p file1 file3 Open multiple files in tabs
- :qa :quitall Close all file
11 Edit multiple files 2¶
A buffer is the in-memory text of a file. A window is a viewport on a buffer. A tab page is a collection of windows.
- vim file1 file2 Open two files in buffer
- :ls Show all opened buffers
- :b3 Jump to buffer #3, :b2 :b1 ...
- ctrl+^ Jump to previous buffer
- :b file1 Jump to file1 buffer
- :bn Jump to next buffer(:bnext), :bp(:bprevious), :bl(:blast), :bf(:bfirst)
- :bd Close current buffer
- :tab ba Expand all buffers to tabs