VI小抄
Move
- h j k l
- Move to file begin
gg
- Move to file end
G - Move to line 3
:3
Copy & Paste
- Copy
y
- Cut
d
- Paste
p
Search & Replace
- Search
/Apple
- Search by word
/\<Apple\>
- Search ignorecase
/Apple\c
- Replace in lines
:1,10s/Apple/Banana
- Replace in a file
:%s/Apple/Banana/g
- Count items
:%s/Apple/&/gn
- Search in files
vimgrep /Apple/ *.txt
grep -R . --include='*.cxx' -i -e 'Apple' (You can open the quickfix list by :copen)
Align several lines
- Go to first line and enter Visual Mode by CRTL-v
- Move to the last line and select the lines by SHIFT-v
- Align the lines to have 4 spaces in the left by entering :'<,'>left 4
(You may need enable ":set expandtab" to insert tab by spaces.)
Undo & Redo
- Undo
u
- Redo
CTRL-r
New Window & Split Window
- New window
:new
- Switch between windows
CTRL-w CTRL-w
CTRL-w h (or j, k, l)
- Split horizontal window
CTRL-w s
- Split vertical window
CTRL-w v - Close a window
:q - Close other windows
CTRL-w o
Display
- Display line number
:set number
- Set tab stop
:set tabstop=4
- Insert space to tab
:set expandtab (reversely, :set noexpandtab)
- Highlight cursor line and column
:set cursorline
:set cursorcolumn
- Folding with marker
:set foldenable
:set foldmethod=marker
:set foldmarker={{{,}}}
(Then you can wrap the sections with {{{ and }}} to create folders and sub-folders. You can add comments after {{{ to add the folder comment)
Close a folder by zc
Open a folder by zo
Tag
- Generate tag file
ctags --extra=+q -R .
ctags -R --c++-kinds=+p --fields=+iaS --extra=+q .
- Install taglist (http://vim-taglist.sourceforge.net/installation.html)
- Show tag list
:Tlist
- Go to a tag
:ta class::member
:ta class.member
:ta /disp*
CTRL-] (go to tag)
CTRL-T (go back)
- Set Multiple Tag files
:set tags:=~/a/tags;~/b/tags
:set tags+=/my/path/to/tags
- Set Tag Files Recursively
:set tags=./tags;/.
Cscope
- Generate cscope file
find . -name '*.hxx' -print > cscope.files
find . -name '*.cxx' -print >> cscope.files
cscope -b
- Find functions calling this function
:cs find c foo
- Find a function definition and show the result in a newly splitted window
:scs find g foo
- Show cscope file (up to 8)
:cs show
- Add a cscope file
:cs add yourfile - Add the line to your ~/.vimrc to map "cscope find e" to Ctrl-\
nmap <C-\> :cs find e <C-R>=expand("<cword>")<CR><CR>
Word Completion
- C-x C-n
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· 展开说说关于C#中ORM框架的用法!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?