Starting VIM
:w file.txt
Buffers, Windows, and Tabs
Buffers
Buffers 是一个内存空间,您可以在其中写入和编辑一些文本。当你在 Vim 中打开一个文件时,数据被绑定到一个缓冲区。当你在 Vim 中打开 3 个文件时,你有 3 个缓冲区。
# 展示缓冲区的三个命令
:buffers
:ls
:files
# 跳转缓冲区
:bnext # 下一个缓冲区
:buffer + file name
:buffer + buffer number
Ctrl-^
# 删除缓冲区
:bdelete + file name
:bdelete + buffer number
# 退出所有缓冲区
:qall
:qall!
:wqall
Windows
windows 是展示 buffer 的显示 UI.
:split filename
:vsplit filename
:new filename
Ctrl-W H/J/K/L # move to left/below/upper/right window
Ctrl-W V/S # open a vertical/horizontal split
Ctrl-W C # close a window
Ctrl-W O # make the current window the only one on screen
Tabs
Tab 是一系列 windows。
:tabnew file.txt # Open file.txt in a new tab
:tabclose # Close the current tab
:tabnext # Go to next tab
:tabprevious # Go to previous tab
:tablast # Go to last tab
:tabfirst # Go to first tab
<n>gt, <n>gT # tab 之间跳转
vim -p file1 file2 file3 # 启动打开多个 tabs
Searching Files
Opening and Editing Files
:edit file.txt # 在 vim 中打开文件
:edit *.c # edit 接受通配符
:edit **/*.c # edit 接受递归搜索
Searching Files with Find
:find package.json
Searching in Files with Grep
:grep -R "xxx" /path/to/dir
Vim grammar
Moving in File
Marking Position
Reference
cheat sheet: https://vim.rtorr.com/lang/zh_cn