The VI/VIM editor is a screen-based Text editor used by many Unix users. Basically vi will not support colour format and VIM will support colour format.
VI/VIM has three modes
- Command mode
- Insert mode
- Execution/Last line mode
Creating a file with editor
vi/vim <file name>
Deleting a file
vi/vim -r <file name>
Entering to Insert mode
press “i” or “insert” button to go to the insert mode to edit text.after editing text press Esc button to return to the normal mode.
:q ----> Quit :q! ----> Forcible Quit :wq ----> Save and Quit
Commands for editing files:
- i —-> Insert at the current position
- I —-> Insert at the beginning of line
- a —-> Append just after the current cursor position
- A —-> Append at the end of the line
- o —-> Open a new line below the current line
- O —-> Open a new line above the current line
Cursor moving commands
- k —-> Moves the cursor up one line
- j —-> Moves the cursor down one line
- h —-> Moves the cursor to the left one character position
- l —-> Moves the cursor to the right one character position
- :set ic —-> Ignores the case when searching
- :set nu —-> to set the line number
- x —-> delete current character
- Nx —-> delete N number of characters
- dw —-> delete current word
- dd —-> delete current line
- Ndd —-> delete N number of lines
- d$ —-> delete to end of line
- d0 —-> delete to beginning of line
Copy and paste commands
- yy —-> Copies the current line.
- yw —-> Copies the current word from the character the lowercase w cursor is on, until the end of the word.
- p —-> Puts the copied text after the cursor.
- P —-> Puts the yanked text before the cursor.
Changing the text
- r —-> Replace single character under cursor(no <esc>needed)
- R —-> Replace characters starting with current cursor position until<esc>hit
- c —-> change(replace) the characters in the current line until<esc>hit enter
- cc —-> change(replace )the characters in the current line stopping when <esc>hit enter
- /string—->search forward for occurrence of string in text
- ?string—–>search backward for occurrence of string in text