vi command in linux step by step | Pro Tech guides

vi command in linux step by step

vi is a primary text editor in Linux. This is not a normal test editing tool. vi has a lot of commands and modes.

vi / vim text editor (or) vi command in linux

vi (or) vim command in linux
vi (or) vim text editor

what is vi / vim?

'vi' is a primary text editor you can perform many operations using this editor, Let's see.

create a file

create a file using vi or vim text editor / command
create a file
$vi fileName
 
By default, You will be in the command mode. In this mode, you are able to perform a set of operations.

This tilde (~) symbol represents a new line.

In the end, it displays the file name.

change to insert mode

insert mode in vi command or vim command in linux
Insert mode
Just press i
Press "i" to enable insert mode.

text editing using vi command in linux
Text editing

To exit insert mode press the "Esc" key. And it will be in the command mode.

To delete the current line

dd
  • Move the cursor to the line which you want to delete.
  • press "dd" key to delete the current line.

undo changes

u (small letter)
  • If you want to undo your edits.
  • Press "u" to undo changes.

redo

. (dot)
  • Press "." (dot) to redo.

copy current line

yy
  •  press "yy" to copy the current line.

paste

P (capital letter)
  • press capital "P" to paste above the current line.
p (small letter)
  •  press small "p" to paste below the current line.

To delete a single character

x (small letter)
  • move the cursor to the character.
  • press "x" key to delete a single letter.

To delete a single word

dw
  • move the cursor to the word.
  • press "dw" to delete a word.

Beginning of the next word

w (small letter)
  • If you want to move the cursor to the beginning of the next word.
  • press the "w" key.
  • which moves the cursor to the beginning of the next word.

 Beginning of the previous word

b
  • press "b" key.
  • To move the cursor to the beginning of the previous word.

Move the cursor beginning or end of the paragraphs

{
  • press "{" symbol.
  • To move the cursor to the beginning of the paragraphs.
}
  • To move the cursor to the end of the paragraphs.

Move the cursor to the beginning or end of the line

0 (or) Home key
  • press "0" or "Home" key.
  • To move the cursor to the beginning of the line.
$ (or) End key
  •  To move the cursor to the end of the line.

Go to Begining or end of the file

Shift+G (or) Ctrl+Home
  • press "Shift+G" or "Ctrl+Home".
  • To move the cursor to the beginning of the file.
Shift+H (or) Ctrl+End
  • Move the cursor to the end of the file.

Appending lines

a
  • press "a" key.
  • To append text after the current cursor position.
A
  •  The cursor will move to the end of the current line in the Insert mode.
o (small letter)
  • The cursor will move to the new line below the current line in the insert mode.
O (capital letter)
  • The cursor will move to the new line above the current line in the Insert mode.

Execute mode

:
  • Press : (colon) key.
  • To enter into execute mode.

Save Files

save files in vi or vim command in linux
Save Files

:w
  • To save your file.
Note:
    You must save your file before exit because every change you made is automatically saved in a buffer until you save your files.

Quit

:q (or) :x
  • To quit a saved file.

Force Quit

:q!
  • To quit a file without saving.

Set line number

 
set line number in linux using vi command or vim commnad
Line number

:set nu
  • This will add a number at the beginning of each line.

Move the cursor using line number

:(line number)
  • Press ":" and line number.
  • To move the cursor at that line.

Replace a word

replace a word using vi command in linux
Replace a word

:%s/current word/replacement word
  • To replace a word.


Conclusion

These are the basic commands in vi editors. Note that these commands are case sensitive i.e) the capital letter is different from the small letter.
 
HAVE A NICE DAY 💓


Related,

Name

Apps,3,Games,1,Linux,38,Linux Commands,37,Network-Devices,1,Networking,1,Terminal Apps,2,Termux,17,Userland,3,Windows,1,
ltr
item
Pro Tech guides: vi command in linux step by step
vi command in linux step by step
vi is a primary text editor in Linux. This is not a normal test editing tool. vi has a lot of commands and modes.
https://1.bp.blogspot.com/-rkx67K1l_Hs/YPBGhDP69iI/AAAAAAAADgo/6g7MW3s0magiZv-Z-ZAE-C4SNxYiD1I9QCNcBGAsYHQ/s16000/vim-command-in-linux.webp
https://1.bp.blogspot.com/-rkx67K1l_Hs/YPBGhDP69iI/AAAAAAAADgo/6g7MW3s0magiZv-Z-ZAE-C4SNxYiD1I9QCNcBGAsYHQ/s72-c/vim-command-in-linux.webp
Pro Tech guides
http://www.protechguidez.com/2021/07/vi-command-in-linux-step-by-step.html
http://www.protechguidez.com/
http://www.protechguidez.com/
http://www.protechguidez.com/2021/07/vi-command-in-linux-step-by-step.html
true
7053638852026728047
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS PREMIUM CONTENT IS LOCKED STEP 1: Share to a social network STEP 2: Click the link on your social network Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy Table of Content