10 tips for improving your code editing experience with Vim
Use the
h
,j
,k
, andl
keys to move the cursor around the code. These keys correspond to the left, down, up, and right arrow keys, respectively, and are easier to reach when your hands are positioned on the home row of the keyboard.Use the
w
,e
, andb
keys to move the cursor to the beginning or end of a word. Thew
key moves the cursor to the next word, thee
key moves the cursor to the end of the current word, and theb
key moves the cursor to the beginning of the current word.Use the
gg
andG
keys to move the cursor to the beginning or end of the file. Thegg
key moves the cursor to the beginning of the file, and theG
key moves the cursor to the end of the file.Use the
i
,a
,I
, andA
keys to enter insert mode. Thei
key enters insert mode at the current cursor position, thea
key enters insert mode after the current cursor position, theI
key enters insert mode at the beginning of the current line, and theA
key enters insert mode at the end of the current line.Use the
.
key to repeat the last edit. This can be helpful for quickly repeating an edit multiple times, such as inserting a block of code or deleting a line.Use the
u
key to undo the last change, and theCtrl+r
key to redo a change that has been undone.Use the
/
key to search for a word or phrase in the file. You can enter the search term after pressing the/
key, and use then
andN
keys to navigate to the next or previous occurrence of the search term.Use the
:%s/old/new/g
command to replace all occurrences of a word or phrase in the file. Theold
andnew
values should be replaced with the word or phrase to be replaced and the replacement text, respectively.Use the
Ctrl+n
andCtrl+p
keys to complete a word or phrase based on the context of the code. This can be helpful for quickly completing long or complex names or for inserting common code patterns.Use the
Ctrl+o
andCtrl+i
keys to jump between the current position and the previous position in the file. This can be helpful for quickly navigating between different parts of the code.