Playing With Linux Vim

 

Playing with Linux VIm
Vim (Vi Improved) in a Unix/Linux text editor. It’s an improved version of Vi and is used in most modern Linux distributions from the command line or as an independent graphical user interface application.
Vim has two modes, command mode and insert mode. Command mode is where you issue commands such as write, quit, search. And insert mode is where you edit the text file and delete or add characters.

Opening a file with vim from the command line:

vim text.txt 

And the file will open in “Command Mode”

Inserting Text:

To edit the text there are several command, press either:
i or INSERT button to insert new text where the cursor is positioned
a to append text after where the cursor is positioned
o to start a new line and add text

To Save the File:

:w to write/save the text to the file
:wq to save the text and exit vim
:wq! to save the text and exit vim without answering any question from vim

To Undo and Redo:

U to Undo
Control + R to Redo

To go to End of file and Start of file:

gg to go to the beginning of the file
Shift + g  to go to the end of the file

To go to End of line and Start of line:

$ to go to end of line
^ to go to start of line

 

To Select an entire Line:

v to enter visual mode by clicking
Shift + v to select an entire line, you can go up and down with the cursors as well to select more lines
gg to select all the text from the cursor to the start of the file
Shift + g to select all the text from the cursor to the end of the file

d to delete the selection
y to copy the selection (y = yank)
p to paste the selection

Search for a word:

/keyword / is to search downward and “keyword” is the word you’re searching for
?keyword ? is to search upward and “keyword” is the word you’re searching for
n to go to the next word

Replace a word or character:

:s%/oldText/NewText will replace the next word or character
:s%/oldText/NewText/g will globally replace all the words or characters

Want to know more? Leave a comment below!

Leave a Reply

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