TIPS & TRICKS IN USING VIM
Frank
Posted on August 11, 2024
Here are some tips and tricks to help you become more efficient with Vim:
Navigation
-
Move by Word or Paragraph:
-
w
/b
: Move to the beginning of the next/previous word. -
e
/ge
: Move to the end of the next/previous word. -
{
/}
: Move to the beginning/end of the previous/next paragraph.
-
-
Jump to Specific Lines:
-
:number
(e.g.,:25
): Go to line 25. -
G
: Go to the last line. -
gg
: Go to the first line.
-
-
Find Text:
-
/pattern
: Search forward for the pattern. -
?pattern
: Search backward for the pattern. -
n
: Go to the next occurrence of the search pattern. -
N
: Go to the previous occurrence of the search pattern.
-
Editing
-
Replace Text:
-
r
+char
: Replace the character under the cursor withchar
. -
R
: Enter Replace Mode, allowing you to replace multiple characters until you pressEsc
.
-
-
Change Text:
-
cw
: Change (delete and switch to Insert Mode) the current word. -
c$
: Change from the cursor to the end of the line.
-
-
Undo and Redo:
-
u
: Undo the last change. -
Ctrl-r
: Redo the last undone change.
-
-
Repeat Last Command:
-
.
: Repeat the last change.
-
Visual Mode
-
Select and Operate:
-
v
: Select text character by character. -
V
: Select whole lines. -
Ctrl-v
: Select a block of text. - After selecting text, you can use
d
(delete),y
(yank),c
(change), etc.
-
Efficiency
-
Use Macros:
- Start recording a macro with
q
+register
(e.g.,q a
to record into registera
). - Perform the actions you want to record.
- Stop recording with
q
. - Replay the macro with
@register
(e.g.,@a
to replay the macro stored in registera
).
- Start recording a macro with
-
Use Buffers and Tabs:
-
:e filename
: Open a new file in a buffer. -
:bnext
/:bprev
: Switch between buffers. -
:tabnew
: Open a new tab. -
:tabnext
/:tabprev
: Switch between tabs.
-
Customization
-
Edit
.vimrc
:- Add custom settings to
~/.vimrc
to personalize Vim (e.g.,set number
to show line numbers).
- Add custom settings to
-
Install Plugins:
- Use plugin managers like
vim-plug
,Vundle
, orPathogen
to extend Vim's functionality (e.g., for syntax highlighting, code completion).
- Use plugin managers like
Helpful Commands
-
Show Line Numbers:
-
:set number
or:set nu
: Show line numbers.
-
-
Show Whitespace Characters:
-
:set list
: Show whitespace characters (e.g., tabs, spaces).
-
-
Get Help:
-
:help
: Access Vim’s help documentation. -
:help command
: Get help for a specific command (e.g.,:help :w
).
-
These tips and tricks can help you navigate, edit, and customize Vim more effectively, making your workflow smoother and more efficient.
💖 💪 🙅 🚩
Frank
Posted on August 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.