Vim 使用笔记
###1.查看帮助
:help
###2.查看quickref
:help quickref
###3.语法高亮
:syn-on :syntax on start using syntax highlighting
:syn-off :syntax off stop using syntax highlighting
###4.Move cursor to its last position
The quickest way is to hit either:
''
(two apostrophes) or:
``
(two backticks).
###5.Show line number
:set number
###6.Auto indent
:set autoindent
###7.Set background
:set background=dark
:set background=light
###8.Common move command
0, ^ line head
$, g_ line foot
ctl + f forword page
ctl + b back page
###9.用vim编辑一个文件,改动了很多内容;最终要保存时却发现没有权限
:w !sudo tee % > /dev/null
Reference:http://www.caiyiting.com/blog/2014/vim-sudo.html
###10.替换文字时有特殊字符怎么办? A:用 \ 转义。
%s/\/Users\/dongmeiliang\/Sites/\/home\/meiliang\/public_html/g
###11.How to reload current file when it has been changed outside of Vim?
A::e
, more info at :help :e
###12.How to delete all lines of file in Vim? A:
- Type
gg
to move the cursor to the first line of the file, if it is not already there. - Type
dG
to delete all the lines.
Reference:How to delete all lines of file in Vim
###13.How to select all lines of file in Vim?
A: ggVG
Reference:How do i select all text in Vi/Vim?
##扩展阅读