vim cheat sheet
Keep this handy as you experiment with vim:
http://www.fprintf.net/vimCheatSheet.html
Here is another guide that covers the commands incrementally:
http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
moving around - hjkl
In insert mode, the arrow keys do work, but you should practice not using them!
Instead, in command mode:
- h - moves left one character
- j - moves down one line
- k - moves up one line
- l - moves right one character
moving around - even more!
You can move all kinds of places quickly in command mode:
- ^ or 0 - move to the start of the current line
- $ - move to the end of the current line
- gg - jump to the beginning of the file
- G - jump to the end of the file
delete
There are so many ways to delete!
- x - delete the character under the cursor
- dd - delete the current line
- d$ or D - delete from the cursor to the end of the current line
- d0 or d^ - delete from the cursor to the start of the current line
You'll notice that we've already seen 0
and $
before! You can repurpose each of the moving around commands to delete text. These all work:
- dG - delete from the current position to the end of the file
- dgg - delete from the current position to the start of the file
- dj - delete the current line and the line below
- dk - delete the current line and the line above
- 2dd, 3dd etc - delete the next N lines
Even dl
and dh
work!
Remember that vim is a language!
searching
You can search for text using regular expressions.
- /PATTERN - search forward for PATTERN
- ?PATTERN - search backward for PATTERN
Press:
- n - jump to the next match
- N - jump to the previous match
PATTERN is a regular expression, but you can just treat it as an ordinary text match for the most part.
You can combine searching with deleting too:
- d/PATTERN - delete to the next match of PATTERN
- d?PATTERN - delete to the previous match of PATTERN
- dn - delete to the next already matched pattern
- dN - delete to the previous already matched pattern
jumping
You can also skip ahead to individual characters in a simple way on the current line:
- f + CHAR - search forward on the current line to CHAR
- t + CHAR - search forward on the current line to the character before CHAR
- F + CHAR - search backward on the current line to CHAR
- T + CHAR - search backward on the current line to the character after CHAR
标签:CHAR,search,sheet,cheat,PATTERN,current,line,Tools,delete From: https://www.cnblogs.com/Answer1215/p/18298345