vim commands in linux with examples
VIM: Text Editor Lean Basic And Advance in Linux/CentOS

vim commands in linux with examples

In this Tutorials We Learn about vim commands in linux with examples. Basic And Advance in Linux/CentOS. VIM is a text Editor that that’s included in Linux, BSD, and macOS. vim is an Improved version of VI. it can be used to Edit All kinds of text files.

(1) Install Vim package in Centos 8:

[root@simi ~]# dnf install vim -enhanced -y

Install Vim package in Centos 7:

[root@simi ~]# yum install vim -enhanced -y

install VIM Text Editor  package in Centos 8

(2) open file from Command line:

# vim filename

[root@simi ~]# vim data

OR

write vim in terminal and hit enter the press ESC button from keyboard +: e location of the file

Create and Open file in VIM Text Editor

[ root@simi ~] vim filename

Open File in vim text editor

saving a file:

:w Or : write The file will be saved but you cannot exit
:w ! Or : write !the file will be saved with overwriten option
:up OR :updateThe file will be saved but you cannot exit
save file in VIM Text Editor

Save And exit from file:

: xsave and exit from the file
:q!exit from the file without exit
:wqsave and exit from the file
save file in VIM Text Editor command in centos 8

We discussed about Basic three mode:

NORMAL MODE :By defaults vim stated in Normal mode Other modes can be accessed from normal mode only.

INSERT MODE: In this mode, anything can be written to the file. To write something in insert mode press o, Esc+i, Esc+s, Esc+a, and insert the key from your Keyboard.

COMMAND MODE: This mode is for executing commands at the bottom of the editor, To switch from normal mode to command mode type: then type the command For example wq.

Basic Navigation :

Basic navigation  key in VIM Text Editor

Navigate to Top and Bottom of the File:

Jump from beginning line to bottom of the line by shortcut.

:0 (zero)go to top of the file
gggo to the top of the file
1ggo to the top of the file
Ggo to the bottom file
:$go to the bottom of file

Search Word and Character in file:

:/f name of the character which you want to search ( f is a example of search character)
:/wordname of the word which you want to search ( Option is a example of search word)

Search Character in file:

:/ f Search forward for the pattern

Search Character in vim text editor

Search Character In File:

:/ option Search forward for the pattern

Search Word in vim text editor
Search word in file

Display Line number in open file.

: set nu or :set number : display line number in file.

set Line Number in VIM Text Editor

Hide Line Number :

:set no number or : set nonu : hide line number.

COPY AND PASTE

The line number from which to copy and cut the file move the cursor to that point and press <ESC> line No + yy (for copy text), <ESC> line No + cc ( for cut text ) Move cursor that point where you want to copy.

<Esc>+ line number + yy copy a line, press ‘p‘ for Paste whatever has been copied.

CUT AND PASTE

<Esc>+line number+cc cut a line, press ‘p‘ for Paste whatever has been copied.

DELETE Some LINES :

To delete a line number in Open vim file, move the cursor to that line and press dd twice.To delete multiple lines press <ESC> +Line number + dd

<Esc>+line number+dd

Create Password Protect Text Files

to Create Password Protected file in Linux/Centos/MacOS. first Open Linux Terminal through the system Dash or the press Ctrl+Alt+T from Your Keyboard.

To create a password protected file, follow the below command.

[root@simi ~] vim -x filename

When creating a password protected file with the above command, -x switch Indicating that you are protecting the file with a password.

Warning: Using A weak encryption method; see: help ‘cm’ Enter encryption key : ******* Enter same key again : ******

save password protected  file in VIM Text Editor

Enter Password and Confirm password, without password you can’t read file content. every time need password to open file.

Use the following command to open a password protected file.

[root@simi ~]# vim filename

Conclusion

This Tutorials We learned about vim commands in Linux with examples Step By steps hope that now you are comfortable with vim. If your problem is still not solved share your Problem via comments.

This Post Has 7 Comments

Comments are closed.