Vim
Vim
Introduction
Vim is a highly configurable text editor built to enable efficient text editing. It’s an improved version of the vi editor distributed with most UNIX systems.
Install Vim using Homebrew:
1
brew install vim
Basic Commands
Opening and Exiting
Open Vim:
1
vim #or viOpen a file:
1
vim filename
Exit Vim:
:q(if no changes were made):q!(to exit without saving changes):wq(to save changes and exit)ZZ(to save and quit)
Navigation
- Move cursor:
h(left),j(down),k(up),l(right)
- Go to start of the file:
gg
- Go to end of the file:
G
- Go to line number (e.g., line 5):
:5
Editing
- Insert mode:
i(before cursor),I(start of line),a(after cursor),A(end of line)
- Delete character:
x(under cursor),X(before cursor)
- Delete entire line:
dd
- Undo and redo:
u(undo),Ctrl-r(redo)
- Copy (yank) and paste:
yy(copy line),p(paste after cursor),P(paste before cursor)
Search and Replace
- Search for a pattern:
/pattern(thennfor next,Nfor previous)
- Replace:
:%s/old/new/g(replace all occurrences of ‘old’ with ‘new’):%s/old/new/gc(with confirmation)
Visual Mode
- Enter visual mode:
v(character mode),V(line mode),Ctrl-v(block mode)
- Commands in visual mode (like copy, delete) are applied to the selected text.
Windows and Tabs
- Split window:
:split(horizontal),:vsplit(vertical)
- Navigate windows:
Ctrl-wfollowed by navigation keys (h,j,k,l)
- Open new tab:
:tabnew
- Navigate tabs:
gt(next tab),gT(previous tab)
Advanced Features
- Command mode for complex commands
- Customization through
.vimrc - Extensive plugin system
- Integration with many tools
This post is licensed under CC BY 4.0 by the author.