Everyday VIM
Discover how to boost productivity with Vim! Learn efficient file navigation, editing, and saving. Revolutionize your daily workflow, whether coding, taking notes, or managing tasks.
![Everyday VIM](/content/images/2024/04/vim.png)
Vim, short for Vi Improved, is a highly configurable text editor that has been around for decades. Although it has a steep learning curve, once mastered, Vim can significantly boost productivity. In this article, I’ll share how I integrate Vim into my daily routine and how you can do the same.
Why Vim?
Vim is popular among developers and power users for several reasons:
Speed
- Vim allows you to perform complex text editing operations quickly using just the keyboard. Once you’re proficient, you can navigate your code at an impressive pace.Efficiency
- With Vim, you can avoid moving your hands between the keyboard and mouse, saving valuable time and reducing strain on your hands.Cool
- 😎
Cheatsheet
- Existing
- Editing
- Operators
- Navigating
- Arrow
- Word
- Line
- Document
- Paragraph
- Window
- Other
- Scrolling
- Searching
- Character
- Current Word
- Pattern
- Replace
- Marking Text (Visual Mode)
- Tabs
- Windows
- Tips
Existing
:q
- Close the file:w
- Save/Write the file:wq
/:x
- Save and close the fileesc
/control + c
- Exit insert mode
Editing
i
- Insert before the cursora
- Insert after the cursorI
- Insert at the beginning of the lineA
- Insert at the end of the lineo
- Insert a new line below the current lineO
- Insert a new line above the current lineea
- Insert at the end of the wordx
- Delete a character (cut)r{character}
- Replace a character with the new characterp
- Pasteu
- Undocontrol + r
- RedoJ
- Join the line below with the current line
Operators
d
- Deletey
- Yank (copy)c
- Change (delete then insert)>
- Indent right<
- Indent leftgU
- Change to uppercasegu
- Change to lowercase
Operators can also be combined with movement keys. For instance:
d
- Deletedd
- Delete the line (repeat the operator)2dd
- Delete 2 linesdw
- Delete from the cursor to the end of the worddiw
- Delete the word under the cursord$
/D
- Delete from the cursor to the end of the lined^
- Delete from the first non-blank character of the line to the cursordip
- Delete the paragraph under the cursor- etc.
c
- Change (delete then insert)ci)
- Change the text inside the parentheses (...)ci}
- Change the text inside the curly braces {...}- etc.
Navigating
Arrow
h
- Move cursor leftj
- Move cursor downk
- Move cursor upl
- Move cursor right
If you want to move the arrows multiple times, such as moving down 5 lines, you can use 5j instead of holding down j or pressing j 5 times.
Word
w
- Jump to the start of the next wordb
- Jump to the start of the previous worde
- Jump to the next end of a wordge
- Jump to the previous end of a word
Line
0
- Jump to the start of the line^
/0w
- Jump to the first non-blank character of the line$
- Jump to the end of the line
Document
gg
- Go to the first lineG
- Go to the last line:{number}
- Go to the line {number}
Paragraph
%
- Jump between matching {}, [], ()}
- Go to the next paragraph{
- Go to the previous paragraph
Window
H
- Jump to the top of the windowM
- Jump to the middle of the windowL
- Jump to the bottom of the window
Other
gD
- Go to the global declaration (variable)
Scrolling
zt
- Position the cursor at the top of the windowzz
- Position the cursor at the middle of the windowzb
- Position the cursor at the bottom of the windowcontrol + e
- Scroll down one line (without moving the cursor)control + y
- Scroll up one line (without moving the cursor)control + f
- Scroll down one pagecontrol + b
- Scroll up one pagecontrol + d
- Scroll down half pagecontrol + u
- Scroll up half page
Searching
Character
f{character}
- Jump forward to the given characterF{character}
- Jump backward to the given character;
- Repeat the search forwards,
- Repeat the search backwards
Current Word
*
- Jump to the next word under the cursor#
- Jump to the previous word under the cursor
Pattern
/{ pattern }
- Search forward for the pattern?{ pattern }
- Search backward for the pattern/{ pattern }\c
- Search forward for the pattern case insensitivelyn
- Repeat the search in the same directionN
- Repeat the search in the opposite direction/ + enter
- Shows the last search/ + (control + p)
- View the backward search history/ + (control + b)
- View the forward search history
Replace
:%s/{ old }/{ new }/g
- Replace all old with new:%s/{ old }/{ new }/gc
- Replace all old with new with confirmations
Marking Text (Visual Mode)
v
- Start visual modeV
- Start visual line modecontrol + v
- Start visual block mode
After entering visual mode, you can combine it with movement or operator keys. For instance:
v
- Start visual mode, then...2j
- Mark 2 lines, then...p
- Paste something
ip
- Mark the paragraph under the cursor
Tabs
:tabnew { filename | optional }
- Open new tab:e { filename }
- Edit the filegt
/:tabn
- Go to the next tabgT
/:tabp
- Go to the previous tab{ number }gt
- Move to tab number:tabo
- Close all tabs except:qa
- Quit all tabs
Windows
sp { filename | optional }
vsp { filename | optional }
- ctrl+ws - Split windows horizontally
- control + wv - Split windows vertically
- control + ww - Switch between windows
- control + wq - Quit a window
- control + wL
Tips
- Delete a line without override yank
"_
+dd
- Register the line to_
- Repeat new replace of search
cgn
:ter
- Open terminal:set nu
- Show number of line"+y
- Copy a selection to the system clipboard"+p
- Paste from the system clipboard:ju
- Jumplistcontrol + i
control + o
:noh
Conclusion
Vim is an incredibly powerful tool for everyday tasks. By incorporating Vim into my daily workflow, I’ve significantly increased my productivity. Give it a try, and you might find yourself wondering how you ever lived without it. Happy Vimming! ⌨️
Kudos to...