Vi Text Editor
Vi Text Editor (command line)¶
Note: Vim is based off of Vi, so there are many similarities¶
- VIM: vimtutor
A long tutorial on vim command line text editor¶
- Two modes
- Insert (input): input or enter content into the file.
- Edit: move around the file, delete, copy, etc
vi
ex:vi firstfile
- If file name does not exist, vi will create one.
ZZ
(Note: capitals) - Save and exit:q!
- discard all changes, since the last save, and exit:w
- save file but don't exit:wq
- again, save and exit
Navigating a file in Vi¶
Arrow keys
- move the cursor aroundj, k, h, l
- move the cursor down, up, left and right (similar to the arrow keys)^ (caret)
- move cursor to beginning of current line$
- move cursor to end of the current linenG
- move to the nth line (eg 5G moves to 5th line)G
- move to the last linew
- move to the beginning of the next wordnw
- move forward n word (eg 2w moves two words forwards)b
- move to the beginning of the previous wordnb
- move back n word{
- move backward one paragraph}
- move forward one paragraph
If you type
:set nu
in edit mode within vi it will enable line numbers. I find that turning line numbers on makes working with files a lot easier.
Deleting Content¶
- x - delete a single character
- nx - delete n characters (eg 5x deletes five characters)
- dd - delete the current line
- dn - d followed by a movement command. Delete to where the movement command would have taken you. (eg d5w means delete 5 words)
Undo¶
- u - Undo the last action (you may keep pressing u to keep undoing)
- U (Note: capital) - Undo all changes to the current line
Other ways to view files¶
cat
Main purpose is to join files together, but can be used for just viewing. Harder to use with ;larger files , because the content will fly across the screen and you can only see the last page.- less View files with the ability of scrolling up and down
spacebar
Skip forward a pageb
Go back a pageq
Quit