Resources
vi Editor
vi is a full-screen text editor for Unix/Linux operating systems.
Modes
vi has two modes of operation:
- command mode (normal)
- insert mode
12 Commands
- Cursor Movement
- arrow keys (up, down, left, right)
- Common Commands
- x - delete character under cursor
- u - undo last command
- /string - find character string
- Ending Edit Session
- :wq - save changes and quit
- :q! - quit without saving changes
- Switch from Command Mode to Insert Mode
- i - insert to the left of the cursor
- a - insert after the cursor
- Switch from Insert Mode to Command Mode
Copy and Paste from a Web Page
To copy text directly from a web page
into a file named filename
use the following commands:
- Copy from the selected part into the clipboard using the mouse or <Ctrl>c
- Start vi: vi filename<Enter>
- Switch to insert mode: i
- Paste from the clipboard using the mouse or <Ctrl>v
- Switch to command mode: <Esc>
- Save and quit: :wq<Enter>
Other Useful Commands
- Navigation
- #G - go to line number # (default is the last line)
- <Ctrl>f - move forward to the next screen
- <Ctrl>b - move backward to the previous screen
- Copy and Paste
- yw - copy from the cursor to the end of word (copies to buffer)
- yy - copy the current line (copies to buffer)
- p - paste buffer contents after (or below) the cursor
- P - paste buffer contents before (or above) the cursor
- Delete
- dw - delete from the cursor to the end of word (copies to buffer)
- dd - delete the current line (copies to buffer)
- Editing
- o - open a new line below the cursor
- O - open a new line above the cursor
- r - replace character under cursor (eg. rw)
- Others
- . - repeat the last command that changed the file
- n - repeat the last /string (find) command
- J - join current and following line
- Most commands can be preceded by number of repetitions (eg. 27dd)
|