All you need to know about VIM Editor


VIM is the popular editor in LINUX Environment. Of course, we have VIM editor for other operating systems like Mac OS and Windows.

We have command line version and graphic version of VIM editor.

Here we are  dealing about VIM command line version, because it is common for all operating systems including servers.

Different modes in VIM editor:
  • Normal mode: Here in this mode we use VIM shortcuts to navigate through the file , duplicate the content and delete content in the file. By default, if we open the file it should be in normal mode.
  • Insert mode: In this mode, we enter new content into the file. In order to enter in to insert mode, we should press “i”. To leave insert mode, press Escape.
  • Command mode:  In this mode, we give few commands to perform few actions on the file.  In order to enter into this mode, we should press “:” in the normal mode. After a command completes inline mode you are returned to normal mode. You can also leave command mode by pressing Escape.

Navigation Commands [Normal mode]:
Command
Description
press "j"
To move down a line
press "k"
To move up a line
press "l"
To move to the right
press "h"
To move to the left
Ctrl + f
To move forward in the file
Ctrl + b
To move backward in the file
use "w"
To move forward by word
use "W"
To move forward by word using white space as
word boundaries
use "b"
To move backward by word
use "B"
To move back word by word using white space
as word boundaries
type "1gg" or just "gg"
To go to the beginning of the file
type "$G" or just "G"
To move to the last line of the file
use <LINE_NUMBER>gg or <LINE_NUMBER>G

EX: to go to line 27, type 27gg or 27G.
To go to a specific line number
“:32<ENTER>” => to move to
line 32

use “:$<ENTER>”=> To go to the last line
Use line mode to go to a specific line



Deleting Text in the file:
Command
Description
Positioning your cursor under letter in the file and press “x"
Delete the character under your cursor
press “X”
Delete the character before your cursor
“.” [period operator]
Repeat the previous command.
“d$” or “D”
Delete the remaining text on the line from cursor place.
dw or dW
{When the cursor is at beginning of line}Delete the first word of the line. 
2dw or 2dW
[count][operator]{motion}
Delete first 2 words
2W
Move forward2 words 
dd
Delete the line
[count]dd

EX: 3dd will delete total 4 files including line that cursor placed.
Delete multiple lines

Saving the file in VIM:
Command
Description
:w<ENTER>
Save your changes and keep vim running
:wq<ENTER>
To save your changes and immediately exit
:q!<ENTER>
Abandon your changes

VIM Help menu:
Command
Description
vim <path of file name>
Opens file is it already exists (OR) create a file with the name given by the user.
In command mode enter help <command name / shortcut name> 
View command help section in help guide  in VIM editor.
h :<beginning letter of command> + ctrl  + d
Show the commands that start with the given letter, navigate through all those commands using tab key and press enter to help section related to that command.
Ctrl + w + w
Switch between help screen and file which we are editing.






Will be updated…


Comments

Popular

PASSWORD MANAGER–DashLane