项目作者: BeanGreen247

项目描述 :
A cheat sheet for Vim
高级语言:
项目地址: git://github.com/BeanGreen247/Vim-Cheat-Sheet.git
创建时间: 2019-12-11T10:17:06Z
项目社区:https://github.com/BeanGreen247/Vim-Cheat-Sheet

开源协议:

下载


Vim Cheat Sheet

Global

  1. :help keyword - open help for keyword
  2. :saveas file - save file as
  3. :close - close current pane
  4. K - open man page for word under the cursor

Cursor movement

  1. h - move cursor left
  2. j - move cursor down
  3. k - move cursor up
  4. l - move cursor right
  5. H - move to top of screen
  6. M - move to middle of screen
  7. L - move to bottom of screen
  8. w - jump forwards to the start of a word
  9. W - jump forwards to the start of a word (words can contain punctuation)
  10. e - jump forwards to the end of a word
  11. E - jump forwards to the end of a word (words can contain punctuation)
  12. b - jump backwards to the start of a word
  13. B - jump backwards to the start of a word (words can contain punctuation)
  14. % - move to matching character (default supported pairs: '()', '{}', '[]' - use <code>:h matchpairs</code> in vim for more info)
  15. 0 - jump to the start of the line
  16. ^ - jump to the first non-blank character of the line
  17. $ - jump to the end of the line
  18. g_ - jump to the last non-blank character of the line
  19. gg - go to the first line of the document
  20. G - go to the last line of the document
  21. 5G - go to line 5
  22. fx - jump to next occurrence of character x
  23. tx - jump to before next occurrence of character x
  24. Fx - jump to previous occurence of character x
  25. Tx - jump to after previous occurence of character x
  26. ; - repeat previous f, t, F or T movement
  27. , - repeat previous f, t, F or T movement, backwards
  28. } - jump to next paragraph (or function/block, when editing code)
  29. { - jump to previous paragraph (or function/block, when editing code)
  30. zz - center cursor on screen
  31. Ctrl + e - move screen down one line (without moving cursor)
  32. Ctrl + y - move screen up one line (without moving cursor)
  33. Ctrl + b - move back one full screen
  34. Ctrl + f - move forward one full screen
  35. Ctrl + d - move forward 1/2 a screen
  36. Ctrl + u - move back 1/2 a screen
  37. **Tip**
  38. Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert mode - inserting/appending text

  1. i - insert before the cursor
  2. I - insert at the beginning of the line
  3. a - insert (append) after the cursor
  4. A - insert (append) at the end of the line
  5. o - append (open) a new line below the current line
  6. O - append (open) a new line above the current line
  7. ea - insert (append) at the end of the word
  8. Esc - exit insert mode

Editing

  1. r - replace a single character
  2. J - join line below to the current one with one space in between
  3. gJ - join line below to the current one without space in between
  4. gwip - reflow paragraph
  5. cc - change (replace) entire line
  6. C - change (replace) to the end of the line
  7. c$ - change (replace) to the end of the line
  8. ciw - change (replace) entire word
  9. cw - change (replace) to the end of the word
  10. s - delete character and substitute text
  11. S - delete line and substitute text (same as cc)
  12. xp - transpose two letters (delete and paste)
  13. u - undo
  14. Ctrl + r - redo
  15. . - repeat last command

Marking text (visual mode)

  1. v - start visual mode, mark lines, then do a command (like y-yank)
  2. V - start linewise visual mode
  3. o - move to other end of marked area
  4. Ctrl + v - start visual block mode
  5. O - move to other corner of block
  6. aw - mark a word
  7. ab - a block with ()
  8. aB - a block with {}
  9. ib - inner block with ()
  10. iB - inner block with {}
  11. Esc - exit visual mode

Visual commands

  1. > - shift text right
  2. < - shift text left
  3. y - yank (copy) marked text
  4. d - delete marked text
  5. ~ - switch case

Registers

  1. :reg - show registers content
  2. "xy - yank into register x
  3. "xp - paste contents of register x
  4. **Tip** Registers are being stored in ~/.viminfo, and will be loaded again on next restart of vim.
  5. **Tip** Register 0 contains always the value of the last yank command.

Marks

  1. :marks - list of marks
  2. ma - set current position for mark A
  3. `a - jump to position of mark A
  4. y`a - yank text to position of mark A

Macros

  1. qa - record macro a
  2. q - stop recording macro
  3. @a - run macro a
  4. @@ - rerun last run macro

Cut and paste

  1. yy - yank (copy) a line
  2. 2yy - yank (copy) 2 lines
  3. yw - yank (copy) the characters of the word from the cursor position to the start of the next word
  4. y$ - yank (copy) to end of line
  5. p - put (paste) the clipboard after cursor
  6. P - put (paste) before cursor
  7. dd - delete (cut) a line
  8. 2dd - delete (cut) 2 lines
  9. dw - delete (cut) the characters of the word from the cursor position to the start of the next word
  10. D - delete (cut) to the end of the line
  11. d$ - delete (cut) to the end of the line
  12. x - delete (cut) character

Exiting

  1. :w - write (save) the file, but don't exit
  2. :w !sudo tee % - write out the current file using sudo
  3. :wq or :x or ZZ - write (save) and quit
  4. :q - quit (fails if there are unsaved changes)
  5. :q! or ZQ - quit and throw away unsaved changes
  6. :wqa - write (save) and quit on all tabs

Search and replace

  1. /pattern - search for pattern
  2. ?pattern - search backward for pattern
  3. \vpattern - 'very magic' pattern: non-alphanumeric characters are interpreted as special regex symbols (no escaping needed)
  4. n - repeat search in same direction
  5. N - repeat search in opposite direction
  6. :%s/old/new/g - searchAndReplace.commands .colonPercentForwardSlashOldForwardSlashNewForwardSlashg
  7. :%s/old/new/gc - searchAndReplace.commands .colonPercentForwardSlashOldForwardSlashNewForwardSlashgc
  8. :noh - remove highlighting of search matches

Search in multiple files

  1. :vimgrep /pattern/ {`{file}`} - search for pattern in multiple files
  2. :vimgrep /foo/ **/*
  3. :cn - jump to the next match
  4. :cp - jump to the previous match
  5. :copen - open a window containing the list of matches

Working with multiple files

  1. :e file - edit a file in a new buffer
  2. :bnext or :bn -
  3. go to the next buffer
  4. :bprev or :bp -
  5. go to the previous buffer
  6. :bd - delete a buffer (close a file)
  7. :ls - list all open buffers
  8. :sp file - open a file in a new buffer and split window
  9. :vsp file - open a file in a new buffer and vertically split window
  10. Ctrl + ws - split window
  11. Ctrl + ww - switch windows
  12. Ctrl + wq - quit a window
  13. Ctrl + wv - split window vertically
  14. Ctrl + wh - move cursor to the left window (vertical split)
  15. Ctrl + wl - move cursor to the right window (vertical split)
  16. Ctrl + wj - move cursor to the window below (horizontal split)
  17. Ctrl + wk - move cursor to the window above (horizontal split)

Tabs

  1. :tabnew or :tabnew {page.words.file} - open a file in a new tab
  2. Ctrl + wT - move the current split window into its own tab
  3. gt or :tabnext or :tabn - move to the next tab
  4. gT or :tabprev or :tabp - move to the previous tab
  5. #gt - move to tab number #
  6. :tabmove # - move current tab to the #th position (indexed from 0)
  7. :tabclose or :tabc - close the current tab and all its windows
  8. :tabonly or :tabo - close all tabs except for the current one
  9. :tabdo command - run the <code>command</code> on all tabs (e.g. <code>:tabdo q</code> - closes all opened tabs)