4/13/2020

VI Editor

** VI Editor


`` VI Editor

` Why vi Editor?

- It is available in almost all Linux Distributions.

- It works the same across different platforms and Distributions.

- It is user friendly.


` Vim - Vi improved 


` Command Mode 

- Vi editor opens in this mode.

- Move the cursor and cut, copy, paste the text.

- Saves the changes to the file.

- Commands are case sensitive.



` Insert mode

- This mode is for inserting text in the file.

- Press 'i' on the keyboard for insert mode.

- In Insert mode, any key would be taken as an input.

- Press Esc key to save changes and return to command mode.


` Starting Vi Editor

- vi or vi

- ~ : denote unused lines


- i : Insert at cursor (goes into insert mode)

- a : Write after cursor (goes into insert mode)

- A : Write at the end of line (goes into insert mode)

- ESC : Terminate insert mode

- u : Undo last change

- U : Undo all changes to the entire line

- o : Open a new line (goes into insert mode)

- dd : Delete line

- 3dd : Delete 3 lines.

- D : Delete contents of line after the cursor

- C : Delete contents of line after the cursor and insert new text.

- dw : Delete word

- 4dw : Delete 4 words

- cw : Change word

- x : Delete character at cursor

- r : Replace character

- R : Overwrite characters from cursor onward

- s : Substitute one character under cursor continue to insert

- S : Substitute entire line and begin to insert at beginning of the line

- ~ : Change case of individual character


` Moving within a File

- Be in the command mode

- k : Move cursor up

- j : Move cursor down

- h : Move cursor left

- l : Move cursor right



` Saving or Closing the File

- Use only in Command Mode!

- Shift+zz : Save the file and quit

- :w : Save the file but keep it open

- :q : Quit without saving

- :wq : Save the file and quit



`` Summary

- The vi editor is the most popular and commonly used Linux text editor.

- It is usually available in all Linux Distributions.

- It works in two modes, Command and Insert.

- Command mode takes the user commands and the Insert mode is for editing text.

- You should know the commands in order to work on your file easily.

- Learning to use this editor can benefit you in creating scripts and editing files.