Skip to content

Instantly share code, notes, and snippets.

@vincentbel
Last active February 26, 2018 09:18
Show Gist options
  • Select an option

  • Save vincentbel/37f8bc435c49f8ee2bb0e9131ba13280 to your computer and use it in GitHub Desktop.

Select an option

Save vincentbel/37f8bc435c49f8ee2bb0e9131ba13280 to your computer and use it in GitHub Desktop.
vim today.

2017-11-02

  • zm: fold one more
  • zr: reduce one fold
  • zM: fold all
  • zR: unfold all

2016-11-28

2016-11-10

  • >: indent operator(like >ip >w etc)
  • <: unindent operator
  • V: linewise virsual mode(v -> characterwise; <ctrl-v> -> blockwise)

2016-11-09

  • D: short for d$

2016-10-29

  • <shift-j>: join two lines

2016-09-12

  • <ctrl-n>: select next in autocomplete
  • <ctrl-p>: select previous in autocomplete

2016-09-10

  • ci): change inside parentheses
  • ci": change inside quote
  • ci}: change inside }

2016-09-08

  • %: go to matched parentheses
  • <shift-i>: insert at the first character
  • <shift-a>: append at the last character
  • ^: go to the first character of current line.(0 go to start of the line, $ go to end of the line)

Search

  • f: fo find next o in current line. (F to find previous one)
  • /: /hello find all text hello in the file, n go to next one, N go to privious one.
  • *: go to next matched word under the cursor, # go to previous one.

2014-07-31

Suspend

  • ctrl-z: will suspend the process and get back to your shell
  • fg: will resume (bring to foreground) your suspended vim

Start a new shell

  • :sh(or :!bash): start a subshell
  • ctrl-d(or exit): kill the shell and return to vim

2014-07-28

插入模式

  1. a 在光标后插入
  2. i 在光标前插入
  3. o 在当前行后插入一个新行
  4. O 在当前行前插入一个新行
  5. cw 替换从光标所在位置后到一个单词结尾的字符

光标移动

  1. 四个方向移动:

        k
     h     l
        j
    
  2. 0 数字零,到行头

  3. ^ 到本行第一个不是 blank 字符的位置(所谓 blank 字符就是空格,tab,换行,回车等)

  4. $ 到本行行尾

  5. NG:N → 到第 N 行

  6. gg → 到第一行(相当于1G,或 :1)

  7. G → 到最后一行

  8. w → 到下一个单词的开头

  9. e → 到下一个单词的结尾

  10. % → 匹配括号移动,包括 (, {, [

  11. *# → 匹配光标当前所在的单词,移动光标到下一个(或上一个)匹配单词(*是下一个,#是上一个)

删除、拷贝、粘贴

  1. x 删当前光标所在的一个字符,并把删除的字符存到剪贴板里
  2. dd 删除当前行,并把删除的行存到剪贴板里
  3. p 在(当前行/光标)后粘贴
  4. P 在(当前行/光标)前粘贴
  5. yy 拷贝当前行当行于 ddP

undo/redo

  1. u undo
  2. <C-r> redo

打开/保存/退出/改变文件

  1. :e <path/to/file> → 打开一个文件
  2. :saveas <path/to/file> → 另存为 <path/to/file>
  3. :bn 和 :bp → 你可以同时打开很多文件,使用这两个命令来切换下一个或上一个文件。

重复

  1. . 重复上次命令
  2. N<command> 重复某个命令N次
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment