VI Editor Commands
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
For vi this is how you can select all text and write it into a new file:
shift v -- visual modeshift g -- jump to eof"*y -- yank select text:e my_new_file -- create a new file"*p -- paste into a new file
Other way
- Shift +v press down arrow to select all and then just use up arrow to unselect the line you need
- "*y - copy the lines u selected
- Open a new file
- "*p -- to paste the input
Moving to the top of the line , Moving to the end of the line
Press ^ to move the cursor to the start of the current line. Press $ to move the cursor to the end of the current line.
VI Editing commands
- 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 a line after the cursor and insert new text. Press ESC key to end insertion.
- dw – Delete word
- 4dw – Delete 4 words
- cw – Change word
- x – Delete character at the 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 the beginning of the line
- ~ – Change case of individual character
Moving within a file
- k – Move cursor up
- j – Move cursor down
- h – Move cursor left
- l – Move cursor right
Saving and Closing the file
- Shift+zz – Save the file and quit
- :w – Save the file but keep it open
- :q! – Quit vi and do not save changes
- :wq – Save the file and quit
- gg - to move to the top of the file
- shift +gg to move to the end of the file
Copying (Yanking)
To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands:
yy- Yank (copy) the current line, including the newline character.3yy- Yank (copy) three lines, starting from the line where the cursor is positioned.y$- Yank (copy) everything from the cursor to the end of the line.y^- Yank (copy) everything from the cursor to the start of the line.yw- Yank (copy) to the start of the next word.yiw– Yank (copy) the current word.y%- Yank (copy) to the matching character. By default supported pairs are(),{}, and[]. Useful to copy text between matching brackets.
Comments
Post a Comment