viis a text editor. It does not format text. It does not (generally) set fonts, highlighting or anything else to the text document. It just edits the text data.
There are many variations of the
vi editor but they are mostly
attempts to extend the functionality of
vi rather than alter its
viis generally regarded as the "standard" unix editor. Probably every version of Unix includes the
vieditor. You can be sure that
viwill be available to you regardless of what version of Unix or Linux you are using.
viis very powerful. Like Unix in general, there is a vast array of features available but gaining the benefits requires some initial learning. Once proficient with
vi, you may quickly make changes to files on any Unix host.
vihas powerful search and replace functions and many other features useful when editing program code or other data.
viuses the terminal.
vidoes not depend on the graphical environment so it can be used to edit files on the local machine or using a remote shell on other hosts avialable to a networked unix machine.
viuses minimal system resources and is efficient on any machine capable of running unix.
viis simply started from the command line with the command "
vi". The file you wish to edit can be specified on the command line "vi newfile.txt" If the file specified does not exist then
viwill be started with a blank edit buffer. If the file does exist, the contents of the file will be loaded in the edit buffer. Once started,
vihas two basic "modes":
vishould look something like this:
viwill be in command mode when it is started. This is the mode where commands may be given to the editor. Note that all commands in
viare case sensitive.
|j||Move cursor down one character (down arrow)|
|k||Move cursor up one character (up arrow)|
|l||Move cursor right one character (right arrow)|
|h||Move cursor left one character (left arrow)|
|G||Move cursor to the end of the file buffer|
|^||Move cursor to the beginning of the current line|
|$||Move cursor to the end of the current line|
|/||Search down to end of file.|
|?||Search up to start of file.|
All commands will be executed once the character has been hit on the
keyboard, there is no need to hit enter. Most
commands are a
single character but will execute multiple times if preceded by a
number: hitting "3j" will cause the cursor to move down
3 lines from
its current position. This applies to all commands in command
Searching can be done by hitting the "/" key. The
cursor will drop to the bottom of the buffer where the search text
may be entered.
vi will stop the search with the
cursor on the first instance that matches the search conditions.
You may hit the "n" key to continue the search to the
next match. Hitting the "escape" key will terminate the
search command. Regular expressions (similar to the unix
grep command) may be used in the search
command for pattern matching.
viwill insert some number of copies of the text you just entered when you hit "escape".
|x||delete one character to the right|
|X||delete one character to the left|
|dd||delete current line|
|3x||delete 3 characters to the right|
|5dd||delete 5 lines (from the cursor position down)|
vi. File changes or newly created files may be saved by entering "w" at this prompt.
|:q||quit the editor|
|:w||write file (save)|
|:wq||write file then quit the editor (note that ":qw" will not produce the same results)|
|:q!||forcefully quit editor|
|:w!||write file regardless of file permissions (user must own the file)|
|:w filename.txt||write current buffer to the file named "filename.txt"|
|:22||go to line 22 in the current edit buffer|
There are many other commands available at the ":"
prompt that provide
vi's advanced functionality. If you decide
to abort the ":"
command simply hit the escape key and you will be returned to command
vi. This will immediately allow any further characters you type to be inserted into the current file buffer (edit window). When you are done entering text and wish to get out of the insert command you need to hit the "escape" key. This will return
viback to command mode. "i" will cuase
vito start inserting text at the current cursor position. You may also start entering text with the "a" key/command which will allow you to append text starting at the next character to the right of the current cursor position.
viresources such as on-line lessons, and manuals.
last updated: 12 Aug 2019 14:33