Useful Vim start arguments
- -g : run using GUI
- -d : diff mode
- -R : read only mode
- -m : modifications (writing files) not allowed
- -M : modifications not allowed
- -b : binary mode
- -n : no swap files, use memory only
- -r <with file name> : Recover crashed session
- -u <vimrc> : use <vimrc> of your choice, instead of default .vimrc
- -U <gvimrc> : use <gvimrc> of your choice, instead of default .gvimrc
- -p[N] : Open N tab pages, (default : one for each file)
- -o[N] : Open N window pages, (default : one for each file)
- -O[N] : Open N window pages, split vertically
- + : start at the end of file
- +<line-number> : start at the <lin-number> in the given file
Useful GUI Vim start arguments
- -background <color> : use <color> for the background (shortform : -bg)
- -foreground <color> : use <color> for the foreground (shortform : -fg)
- -font <font> : use <font> for normal text (shortform : -fn)
Marks in vim
- :marks : view all current marks
- ma : Normal mode : type m followed by mark character. example : ma - marks the current postion and maps it to a character
- `<mark-character> : go to marked position stored in <mark-character>. So, if I set a mark with ma, then `a will take me to location marked with character a
- :delm <mark-characters> : to delete marks. If you have marks set to a, b, c , D..then you can delete it with :delm abcD
- :delm! : deletes all the marks
- `" : go to the position, when last editing this file
- `. : go the position of last change of this file
- `` : go to the position of the last change of this file
- :ju[mps] : list of jumps
- Ctrl + i : go to newer position in jump list - can be used with Ctrl + o to loop between current and last positions
- Ctrl + o : go to older position in jump list - can be used with Ctrl + i to loop between current and last positions
- :changes : list of changes
- g, : go to newer position in the changelist
- g; : go to older position in the changelist
- Ctrl + ] : jump to tag under cursor
Motions in VIM
| Key | Motion Direction | Key | Motion Direction | Key | Motion Direction | Key | Motion Direction |
|---|---|---|---|---|---|---|---|
| h | Move Cursor Left | j | Move Cursor Down | k | Move Cursor Up | l | Move Cursor Right |
| H | Move To Top Of Screen | gj | Move Cursor Down (multi line text) | gk | Move Cursor Up (multi line text) | M | Move To Middle Of Screen |
| L | Move To Bottom Of Screen | w/W | jump to start of next word | e/E | jump to end of next word | b/B | jump to back to start of word |
| ge/gE | jump backward to end of word | % | move character to matching bracket/braces | 0 | Jump to start of line | ^ | Jump to first nonblank character of a line |
| $ | jump to end of line | g_ | jump to last nonblank character of a line | gg | Go to the first line of document | G | go to last line of document |
| 5gg/5G | go to line 5 | fx | jump to next occurrence of character 'x' | tx | jump before occurrence of character 'x' | Fx | jump previous occurrence of character x |
| Tx | Move before last occurrence of character 'x' | ; | repeat previous search f,F,t,T | , | repeat previous search f,F,t,T backwards | } | jump to next paragraph (function block) |
| { | jump to previous paragraph (function block) | zz | move current line to center of screen | zt | move current line to top of screen | zb | move current line to bottom of screen |
| Ctrl + e | move page up by one line | Ctrl + y | move page down by one line | Ctrl + f | Move Forward By One Screen | Ctrl + b | Move Backward By On Screen |
| Ctrl + d | Move forward by half Page | Ctrl + u | Move Backward by Half Page |
Search and Delete a line
- g/search-term/d : d is the command to delete
- dd : delete an entire line
- gnd : delete last searched term. Entire word can be repeated with . dot command
- diw : delete inside a character, eg. di" - will delete everything between " (double quotes)
- daw : delete a word, you can delete a word , when you are inside first and last character of a word
- ciw : change a word, go into insert mode and run the change command