VIM

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

Plugins

Vim 8.0 之后自带插件管理工具,只要 create the directory ~/.vim/pack/vendor/start/, and put plugins in there (e.g. via git clone). vendor目录名好像可以替换。

NERDTree

在 NERDTree 中输入? 查看帮助。

o: open in prev window
go: preview
t: open in new tab
T: open in new tab silently
i: open split
gi: preview split
s: open vsplit
gs: preview vsplit

I: 显示隐藏文件

ctrl w + w: 切换 focus 窗口

Others

Vscode Vim

C-q: visual block.
visual 模式选中后,I进入 muti-cursor 进行多行编辑。

Reference

https://learnvim.irian.to/

cheat sheet: https://vim.rtorr.com/lang/zh_cn