Editors:
Editors are used for adding, modifying and / or deleting text.
The types of different editors used are:
- Windows:
notepad - DOS:
edit - Linux/Unix
CLI based : ex , ed , vi or vim, etc.
GUI based : Emacs, Gedit, nedit, nano, and pico, etc.
Editors:
- VI editor is a screen-oriented text editor written by Bill Joy in 1976.
- This is the most commonly used editor for editing files in Linux.
VI Editor Mode:
VI editor has three modes of operations.
- Command Mode
- Insert Mode
- Ex Mode (Extended Command Mode)
To go Insert Mode from Command Mode
| i | Inserts the text at the current cursor position |
| l | Inserts the text in beginning of a line |
| a | Adds the text after the current cursor position |
| A | Adds the text at the end of a line |
| o | Inserts the text one line below current cursor position |
| O | Inserts the text one line above current cursor position |
Ex mode:
| :q | Quit without saving |
| :q! | Quit forcefully without saving |
| :w | Write (save) |
| :wq | Save and quit |
| :wq! (or) : x | Save and quit forcefully |
| :se nu (or) :set nu | Sets line numbers |
| :se nonu (or) :set nonu | Removes line numbers |
| :n | Jumps to line n |
| :! (UNIX command) Eg: :! pwd | To execute UNIX commands |
| : X | To give password to the file and remove password |
| :/string/ | To search a word in the file |
| :84 | The cursor goes to line 84 |
| %s/old name/new name | Replace the particular keyword in first line |
| %s/old name/new name/g | Replace all matching keywords in all the lines |
| %s/old name/new name/gi | To ignore case sensitive |
| %s/old name/new name/gc | Ask for confirmation |
Command Mode:
| e | moves to the end of the word |
| b | Moves to beginning of the word |
| $ | Moves to the end of the line |
| ^ | Moves to the beginning of the line |
| H | Moves to the first line onscreen |
| M | moves to the middle of the onscreen |
| L | Moves to the last line onscreen |
| dd | Deletes a line |
| ndd | Deletes ‘n’ lines |
| yy | Copies a line |
| nyy | Copies ‘n’ lines |
| p | Paste below the cursor line |
| P | Paste above the cursor line |
| u | Undo (you can undo 1000 times) |
| Ctrl+r | Redo |
| gg | go to beginning of the file |
| G | Moves the cursor to the last line of the file |
| /<word to find> | Finds a word (press n for next) |
| n | Find next occurrence of search word |
| N | Find previous occurrence of search word |
| . | Repeat last command action |
VI Editor:
To create file
[root@webnoidschools ~]# vi <filename>
To create multiple file
[root@webnoidschools ~]# vi m –o <filename1> <filename2>
