Vim 使用笔记

1.查看帮助

1
:help

2.查看quickref

1
:help quickref

3.语法高亮

1
2
: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:

1
2
3
4
5
''
(two apostrophes) or:

``
(two backticks).

5.Show line number

1
:set number

6.Auto indent

1
:set autoindent

7.Set background

1
2
:set background=dark
:set background=light

8.Common move command

1
2
3
4
0, ^ line head
$, g_ line foot
ctl + f forword page
ctl + b back page

9.用vim编辑一个文件,改动了很多内容;最终要保存时却发现没有权限

1
:w !sudo tee % > /dev/null

Reference:http://www.caiyiting.com/blog/2014/vim-sudo.html

10.替换文字时有特殊字符怎么办?

A:用 \ 转义。

1
%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:

  1. Type gg to move the cursor to the first line of the file, if it is not already there.
  2. 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?

扩展阅读