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 ato record into registera). - Perform the actions you want to record.
- Stop recording with
q. - Replay the macro with
@register(e.g.,@ato 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
~/.vimrcto personalize Vim (e.g.,set numberto show line numbers).
- Add custom settings to
-
Install Plugins:
- Use plugin managers like
vim-plug,Vundle, orPathogento extend Vim's functionality (e.g., for syntax highlighting, code completion).
- Use plugin managers like
Helpful Commands
-
Show Line Numbers:
-
:set numberor: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.
Top comments (2)
💡 Tips & Tricks in Using Vim: Unlock the full potential of Vim with our curated tips and tricks! Whether you're a beginner or a seasoned user, these insights will help you work smarter and faster. Dive in and take your Vim skills to the next level! 🚀 #VimTips #CodingEfficiency #VimMastery
Nice content 👍