「Vim」- Vi IMproved

基本操作

_KEY_ _DESCRIPTION_
D、d$ 从当前光标位置开始,删除到行尾
v 进入Visual模式,可以选择
y 复制
p 粘贴
V、d、p 剪切
i、a 进入编辑模式;我们经常使用 a 键,因为我们希望光标移动到后一个字符。

全选:ggVG
从文件中读取内容,然后插入当前位置::-1.read<filename>
行号::set number

移动光标

功能 命令
第一行开始 gg
最后一行结束 G

执行命令

功能 命令
使用XMLINT格式化 ggVG:、 !xmllint –format –
重复输入 Ctrl+O 、 80 、 i 、 – 、 ESC

替换操作

功能 命令
替换命令 :%s/search/replace/g
将字符替换为换行 :%s/char/r/g

!!!替换操作是正则替换,因此特殊字符需要转义。

文本删除

功能 命令
从光标位置开始,删除到行尾 d $

常见问题处理

编辑 YAML 文件

Wrong indentation when editing Yaml in Vim – Stack Overflow

	# 修复错误的自动缩进
echo 'autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab' >> ~/.vimrc

参考文献

Wikipedia/Vim (text editor)
Delete from cursor to end of line on VI
what is the command for “Select All” in vim and VsVim?
Vim indent xml file
Vim tips: The basics of search and replace
Repeating characters in VIM insert mode
Copy, cut and paste
How To Show or Hide Line Numbers In vi / vim Text Editor
Vim: insert text from a file at current cursor position
How to replace a character by a newline in Vim
Find and replace using regular expressions
Delete from cursor to end of line in `vi`
How to set cursor to after last character in vim?