Toolbox: Vim Walkthrough

Ashutosh Gupta
4 min readNov 7, 2020

Hello everyone I hope you are best and doing well. I am m3ta_c1ph4r back with another writeup but this time I am doing a walkthrough of one tool named Vim!!. Yeah most of the people knows that it is only a text editor but it is more than that.

So there is one room in TryHackme name “Toolbox: Vim”. So today we are going to solve this room.

So there are three basic modes in Vim:

  • Command mode is where you can run commands. This is the default mode in which Vim starts up
  • Insert mode is where you insert i.e. write the text
  • Visual mode is where you visually select a bunch of text so that you can run a command/operation only on that part of the text.

Task 2:-

Question 1:-How do we enter “INSERT” mode?

I think you have installed vim. So before giving the answer let’s see help. Type :help and then you will see a help of vim.

So this is vim help and in this you can see for entering into insert mode you have to type i.

Answer_1:- i

Question 2:-How do we start entering text into our new Vim document?

So after entering into input mode what you can do now?

Answer_2:- typing

Question 3:-How do we return to command mode?

Answer_3:-esc. Press esc key for changing the mode.

Question 4:-How do we move the cursor left?

Answer_4:-Press h for moving cursor left in command mode. You can use left arrow key also.

Question 5:-How do we move the cursor right?

Answer_5:-Press l for moving cursor right in command mode.

Question 6:-How do we move the cursor up?

Answer_6:-Press k for moving cursor up in command mode.

Question 7:- How do we move the cursor down?

Answer_7:-Press j for moving cursor down in command mode.

Question 8:-How do we jump to the start of a word?

So you have to move cursor to the word and then press w. You will see the cursor is at starting of the word and if you add word in between them.

Answer_8:-w

Question 9:-How do we jump to the end of a word?

Answer_9:-e

Question 10:-How do we insert (before the cursor)?

Answer_10:-i (insert mode)

Question 11:-How do we insert (at the beginning of the line?)

Answer_11:-I

Question 12:-How do we append (after the cursor)

Answer_12:-a

Question 13:-How do we append (at the end of the line)

Answer_13:-A

Question 14:-How do we make a new line under the current line?

Answer_14:-o(this is going to help you a lot)

Task 3:-

In this task You will get some answers in the help.

Question 1:-How do we write the file, but don’t exit?

Answer_1:- :w

Question 2:-How do we write the file, but don’t exit- as root?

Answer_2:-:w !sudo tee %

Question 3:-How do we write and quit?

Answer_3:-:wq

Question 4:-How do we quit?

Answer_4:-:q

Question 5:-How do we force quit?

Answer_5:-:q!

Question 6:-How do we save and quit, for all active tabs?

Answer_6:-:wqa

Task 4:-

Question 1:-How do we copy a line?

Answer_1:-yy

Question 2:-how do we copy 2 lines?

Answer_2:-2yy

Question 3:-How do we copy to the end of the line?

Answer_3:-y$

Question 4:-How do we paste the clipboard contents after the cursor?

Answer_4:-p

Question 5:-How do we paste the clipboard contents before the cursor?

Answer_5:-P

Question 6:-How do we cut a line?

Answer_6:-d

Question 7:-How do we cut two lines?

Answer_7:-2dd

Question 8:-How do we cut to the end of the line?

Answer_8:-D

Question 9:-How do we cut a character?

Answer_9:-x

Task 5:-

Question 1:-How do we search forwards for a pattern (use “pattern” for your answer)

Answer_1:- /pattern

Question 2:-How do we search backwards for a pattern (use “pattern” for your answer)

Answer_2:-?pattern

Question 3:-How do we repeat this search in the same direction?

Answer_3:-n (this is quite helpful I think)

Question 4:-How do we repeat this search in the opposite direction?

Answer_4:-N

Question 5:-How do we search for “old” and replace it with “new”

Answer_5:-:%s/old/new/g

Question 6:-How do we use “grep” to search for a pattern in multiple files?

Answer_6:-:vimgrep (so you have to add word after this like “ :vimgrep hello”)

Make sure that you don’t use the commands in insert mode otherwise they will behave as text. Press esc before typing any command.

--

--