If you are preparing for CKAD or CKA exam and are new to Vim/Vi, this post will help you know everything that is essential to being productive with Vim during your exam.
Vim has 3 modes as depicted in picture below:
- In Command Mode, you do things like navigating your cursor from one point to another in your text file, or delete text or replace text or select text or things like that. When you open Vim, you will be in this mode to begin with.
- In Insert Mode, you insert text and delete text with [backspace] key :)
- In Execution Mode, you do things like search text in file, set tab length, set line numbers in editor and stuff like that.
Frequently Used Keyboard Shortcuts In Command Mode
w ==> jump by start of words
e ==> jump by end of words
b ==> jump backward by words
0 ==> (zero) is to jump to the start of the line
$ ==> (dollar) jumps to end of line
gg ==> to go to top of page
G ==> to go to bottom of page
dd ==> delete current line
y ==> yank/copy current line
P ==> paste content before cursor
p ==> paster content after cursor
i ==> enter insert mode to input text in current cursor location
a ==> enter insert mode and move cursor to append to the existing line
u ==> undo last action
. ==> (dot) to repeat last command
Ctrl + r ==> redo last action
v ==> to visually select multiple lines
Things Done In Execution Mode
:5 ==> go to 5th line in the file
:N ==> go to Nth line in the file
/search_text ==> search for search_text
n ==> repeat search in same direction
:%s/old_text/new_text/g ==> replace all old_text with new_text throughput file
:%s/old_text/new_text/gc ==> replace all old_text with new_text throughput file asking for confirmation before making each change
:set et ==> set expandtabs to spaces
:set number ==> show line numbers
:set sw=2 ==> shiftwidth of tab from default 8 to 2 spaces
:set ts=2 ==> set tabstop to 2 spaces
:set sts ==> set softtabstop to 2 spaces
Configuring Vim To Your Preference
There are certain things that you don't want to set every-time you open vim, like showing line numbers and the tab spaces that suits your preference. All you have to do for this is create a ~/.vimrc file with the following content:
:set sw=2 ts=2 sts=2
This should improve your productivity big-time during the exam.
If you like this post or if this post helped you in your preparation, do care to share it among your circle. Let's spread goodness :)
If you think I have missed anything, do share your points as comments to this post. Thanks in advance for that..
Happy Vimming and good luck for your exams!