We discussed the Basic Vim commands in
Now itβs time to level up your Vim skills with advanced β yet beginner-friendly β commands that can save time, improve workflow, and make terminal editing a breeze.
Letβs get started! π
π§± Normal Mode Editing Commands
Once you're in Normal Mode (press Esc
), you can perform actions like deleting, copying, and pasting β no mouse required.
βοΈ Line Editing Commands
dd β Delete (cut) the current line cc β Cut the line and enter Insert Mode yy β Copy (yank) the current line p β Paste below the current line P β Paste above the current line
π Make sure your cursor is on the line you want to act upon.
π’ Repeating Commands with Numbers
You can prepend a number to most commands to apply them multiple times:
3dd β Delete 3 lines (current + 2 below) 2yy β Copy 2 lines 5cc β Cut 5 lines and enter Insert Mode
This is a huge productivity booster when editing in bulk.
π§ Navigation in Vim
Vim offers fast, precise navigation with simple keystrokes:
Key | Action |
---|---|
h | Move left |
j | Move down |
k | Move up |
l | Move right |
w | Jump to next word |
b | Jump to previous word |
0 | Jump to beginning of line |
$ | Jump to end of line |
gg | Jump to start of file |
G | Jump to end of file (Shift + g) |
π― Combine these with commands like d
, y
, c
for powerful results.
Example: dw
= delete word, yw
= yank word.
π Searching in Vim
Use these commands to search for patterns in your file.
π Basic Search
/pattern β Search forward ?pattern β Search backward n β Go to next match N β Go to previous match
π§ Useful Pattern Examples
/root β Find next occurrence of βrootβ /^user β Match lines starting with βuserβ /bash$ β Match lines ending with βbashβ /foo.*bar/ β Match anything from βfooβ to βbarβ
Symbol | Meaning |
---|---|
^ | Start of line |
$ | End of line |
. | Any character |
* | Zero or more |
\< / \> | Word boundary |
Use :nohl
to clear search highlights from the screen if they remain after searching.
π Substitution (Find & Replace)
Vimβs :s
command helps you quickly replace text.
π Syntax
:[range]s/pattern/replacement/[flags]
π Component Breakdown
Part | Description |
---|---|
range | Line range (% = entire file) |
pattern | Text to search for |
replacement | Text to replace it with |
flags | Optional: g = global, c = confirm, i = ignore case |
π§ Practical Examples
:%s/foo/bar/g β Replace all "foo" with "bar" in entire file :1,10s/cat/dog/g β Replace from lines 1 to 10 :%s/hello/world/gc β Replace with confirmation prompt :%s/\<admin\>/user/g β Replace whole word "admin" with "user" :%s/test//g β Remove all occurrences of "test"
π Shell Integration
Use !
in command mode to temporarily drop to the terminal, then return to Vim after running a command.
:!date β Show the system date without exiting Vim
To paste the output of a shell command directly into the file at the cursor position:
:.!date β Insert the date output into the file
To switch to another file temporarily inside Vim:
:edit /path/to/targetfile
π§© Extra Handy Settings
:set number β Show line numbers :set nonumber β Hide line numbers :set ic β Ignore case in search :set noic β Make search case-sensitive
In normal mode:
- Use
Shift+D
to delete everything after the cursor on the same line.
π Bonus Tip β Use vimtutor
Practice all these commands interactively in your terminal:
vimtutor
Itβs built-in and walks you through essential Vim usage in under 30 minutes β perfect for beginners.
π§ Summary Table
Task | Vim Command |
---|---|
Delete current line | dd |
Copy current line | yy |
Paste below | p |
Move to next word | w |
Move to end of line | $ |
Go to file start | gg |
Search for βrootβ | /root |
Replace "a" with "b" | :%s/a/b/g |
Replace with confirmation | :%s/foo/bar/gc |
β Final Thoughts
Vim may feel intimidating at first β but once you get the hang of these commands, it becomes one of the fastest, most powerful editors available.
Start slow, practice often, and soon youβll be editing like a pro.
π¬ Have a favorite Vim trick? Share it below!
π‘ Need help with something Vim-related? Iβm here to help.
Top comments (0)