VIM Usage
These notes are how to use VIM in general use. They are based on A Byte of VIM and Practical VIM.
Modes
- Multiple modes - the aim to make mouse redundant so we switch navigation from the mouse to a VIM mode and use the keyboard
- insert mode for text entry
- normal mode for running commands (rewriting, editing)
- visual mode to visually select text
Commands
Press :
to enter commands in VIM. You can use the up arrows to scroll through previous commands. You can also type a portion of the command and then press up to scroll through previous commands with that prefix.
:e <name>
- edit a file & create it if it doesn't exist:w
- write (save) a file:q
- quit editor/query
- search for the next occurence of query:help
- open the vim help
Beginning to edit
Beginning editing starts from the normal mode. Some of these commands return you to normal mode after finishing editing.
.
- repeat the last normal mode change commandI
- go to the start of the line and enter insert modei
- switch to insert mode before the current postionA
- go to the end of the line and enter insert modea
- switch to insert mode after the current positionO
- open a new line above the current line and enter insert modeo
- open a new line below the current line and enter insert mode.S
- substitute the entire line for a new ones
- substitute the current character for a new one and stay in insert mode.r
- replace the current character and go back to normal modeR
- replace continuous characters and go back to normal modeC
- change the rest of the line
Single Character Edits
~
- change the case of the character under the cursorx
- delete the character under the cursorr
- replace the character under the cursor
Navigation
h
- move leftj
- move downk
- move upl
- move rightAdding a count before these will repeat the operation that amount of times.
Line
^
- move to the start of the line$
- move to the end of the line
File
Ctrl-b
- move one screen upCtrl-f
- move one screen downG
- move to the end of the file1G
- move to the top of the file50G
- move to line 50
Window
H
- move to top of the visible window (High)M
- move to middle of the visible window (Middle)L
- move to bottom of the visible window (Low)
Word
w
- move to the start of the next worde
- move to the end of the next wordb
- move back to start of the previous word
Sentence
(
- move to the previous sentence)
- move to the next sentence{
- move to the previous paragraph}
- move to the next paragraph
Mark
- This is a marker in a file identified by a single character (uppercase or lowercase) to which we can jump to
ma
- create a mark named a'a
- jump to mark named a
Location
Ctrl-o
- jump to the previous locationCtrl-i
- jump to the next location
Text selection
- Press
v
to enter visual mode - Now combine
a
with a text object selector to select the textaw
- select a wordap
- select a paragraphab
- select a block
Windows/Buffers
:pc
- close any preview window open
Cursor
- Vim can navigate based on what's under the cursor
gF
- go to the file under the cursorg]
- go to the tag under the cursor
Special/Unicode Characters
- To insert unicode characters type
Ctrl-vu
followed by the 4 digit hex code for that character.
Misc
- From force of habit I sometimes press Ctrl-s in VIM. This hangs my version of VIM. To recover from this press Ctrl-q.