Vim

来自夜航船
跳到导航 跳到搜索

Vim is an editor to create or edit a text file.

http://www.vim.org/

VIM Editor Commands

Cheetsheet

速查手册:

Best-VIM-Cheat-Sheet

另外三个版本:

Syntax

$ mkdir -p ~/.vim/{ftdetect,indent,syntax} && for d in ftdetect indent syntax ; do curl -o ~/.vim/$d/scala.vim https://raw.githubusercontent.com/scala/scala-dist/master/tool-support/src/vim/$d/scala.vim; done

Then edit ~/.vimrc, add:

syntax on

cd ~/.vim/ftdetect:

$ wget https://raw.githubusercontent.com/gchen/scala.vim/master/scala.vim

Find

https://www.cs.swarthmore.edu/help/vim/searching.html

https://www.catswhocode.com/blog/vim-cheat-sheet-for-2016

For basic searching:

  • /pattern - search forward for pattern
  • ?pattern - search backward
  • n - repeat forward search
  • N - repeat backward

Some variables you might want to set:

  • :set ignorecase - case insensitive
  • :set smartcase - use case if any caps used
  • :set incsearch - show match as search

搜索之后,文档中的匹配关键字,会有黄色阴影,如果感觉碍眼,可以搜索一些不可能出现的字,阴影会消失。

Text Entry

Used to start text entry

a Append text following current cursor position
A Append text to the end of current line
i Insert text before the current cursor position
I Insert text at the beginning of the cursor line
o Open up a new line following the current line and add text there
O Open up a new line in front of the current line and add text there

Cursor Movement

Help for MediaWiki Table: here

h Moves the cursor one character to the left
l Moves the cursor one character to the right
k Moves the cursor up one line
j Moves the cursor down one line
nG or :n Cursor goes to the specified (n) line (ex. 10G goes to line 10)
^f One page forward
^b One page backward
$ Move cursor to the end of current line
0 (zero) Move cursor to the beginning of current line
w Forward one word
b Backward one word

Text Deletion Commands

Used to delete text

x Delete character
dw Delete word from cursor on
db Delete word backward
dd Delete line
d$ Delete to end of line

Exit

Used to exit text editing

:wq Write file to disk and quit the editor
:q! Quit (no warning)
:q Quit (a warning is printed if a modified file has not been saved)
ZZ Save workspace and quit the editor (same as :wq)