Mastering VIM: Essential Commands and Features for Efficient Text Editing

Welcome to our code Snippets post on VIM, the powerful text editor. Uncover essential commands, navigation tips, and advanced features to boost your productivity. From mastering command mode to efficient buffer management and precise text selection with visual mode, we’ve got you covered. Explore window splitting, handling of suspended jobs, executing Linux commands, and optimizing settings. Upgrade your text editing skills with this comprehensive VIM guide.

Command Mode:
Shift + a: Enters insert mode at the end of the line.w: Write (save changes)
q: Quit
wq: Write and quit
q!: Quit and discard changes
r: Replace character
x: Delete current character
dd: Delete entire line / cut line to be pasted if desired
i: Enters insert mode at the current cursor location
Ctrl + a: Enters insert mode at the end of the file
r file: Places the content of the specified file at the cursor position
%s/old/new/g: Find and replace (g: replace every occurrence of the given word)

Buffers:
e file: Opens the file in a buffer
bp: Moves to the previous buffer
bn: Moves to the next buffer
bd: Deletes the current buffer
badd: Opens a new buffer while staying in the current buffer
enew: Opens a new buffer
ls: Lists all open buffers
b number (e.g., :b 1): Takes you to the buffer with the specified number

Visual Mode:
v: Enters visual mode
yy: Copies the highlighted text
d: Cuts the highlighted text
p: Pastes the copied or cut text
sort u: Sorts the highlighted text in alphabetical order

Navigation:
0: Moves to the beginning of the line
$: Moves to the end of the line
gg: Moves to the top of the file
G: Moves to the bottom of the file

Splits:
split file-name: Splits the window horizontally
sp: Shortcut for split
vsplite file-name: Splits the window vertically
vs: Shortcut for vsplit
Ctrl + w: Switches between two files in command mode

Jobs:
Ctrl + z: Suspends Vim and returns to the terminal
fg: Brings the suspended Vim process to the foreground
fg number (e.g., fg 1, fg 2): Brings the specified suspended process to the foreground

! linux-command: Executes a Linux command in command mode and returns to Vim.

Miscellaneous:
set number: Displays line numbers on the left of each line
set nonumber: Hides line numbers
vim + number file name: Opens the file and moves the cursor to the specified line
vim -o file1 file2: Opens two files with a horizontal split
vim -O file1 file2: Opens two files with a vertical split



Join the conversation.

Leave a Reply

Your email address will not be published. Required fields are marked *