Remember, practice is key to mastering Vim. Start by applying these tips in your daily workflow. As you become more comfortable, explore additional commands and features to further improve your efficiency. Vim offers a vast array of possibilities, so keep exploring and experimenting to unlock its full potential as a Linux administrator.
- Opening a file:
vim filename
: Open a file in Vim.vim -o file1 file2
: Open multiple files in split windows horizontally.vim -O file1 file2
: Open multiple files in split windows vertically.
- Navigating within a file:
h
,j
,k
,l
: Move the cursor left, down, up, and right respectively.gg
: Go to the beginning of the file.G
: Go to the end of the file.:n
: Go to a specific line number.
- Editing text:
i
: Enter insert mode at the current cursor position.Esc
: Exit insert mode and return to command mode.dd
: Delete the current line.yy
: Copy the current line.p
: Paste the copied or deleted line below the current line.
- Saving and quitting:
:w
: Save the file.:q
: Quit Vim.:wq
or:x
: Save and quit Vim.:q!
: Quit Vim without saving changes.
- Searching and replacing:
/search_term
: Search for a specific term in the file (pressn
to find the next occurrence).:%s/old/new/g
: Replace all occurrences of “old” with “new” in the entire file.
- Working with multiple files and windows:
:vsp filename
: Open a file in a vertical split window.Ctrl+w, w
: Switch between open windows.Ctrl+w, arrow keys
: Move between split windows.:only
: Close all other windows, keeping only the current window.
These commands should give you a good starting point for mastering Vim. Remember, Vim has a steep learning curve, but with practice, it can become a powerful tool for editing and working with text efficiently.