What is the Vi editor?
Vi is a Notepad-like tool for editing text files from the command line, widely used in the Linux/Unix community. Although it was often thought that Unix had been written by this tool, Vi was originally developed by Bill Joy in 1976. (Unix is based on the year 1969.) According to my personal experience, I can say that 50% of Linux/Unix use is Vi. The beginners have bad experience of editor usage and usually cool open source operating systems off when they are not comfortable to use. (The remaining 50% is the use of shell)
How does Vi work?
Works in 3 different modes;
- VI: The editor starts working in this mode, most of the keys on the keyboard are assigned to specific commands. The ESC key is pressed to return from other modes.
- Input: You must be in VI mode before you switch to this mode. You can toggle by pressing the “:” (colon), the only exception is to be able to search the status “/” (forward slash).
- Command: A mode that allows a user to input data into files.
What are the Vi shortcuts?
If we summarize the shortcuts for three types, we will encounter a table like the following.
- To display the tables correctly on your mobile device, enable the desktop view in your browser.
|ESC to exit|
|-Cursor keys||i – insert||:q – Quit|
|H J k L – Cursor keys||a – append||:q! -Output without saving|
|CTRL-f – Move forward on the screen||A – Append EOL||:w – Write|
|CTRL-b – Go back on screen||O – Open line||:Wq – Write and quit|
|G – Go to end of file||R – Replace character||:num – Go to line num|
|x – Delete character||R – Overwrite||/str – Find str|
|dw – Delete word||:set all – vi settings|
|dd – Delete line||:r file – Import file|
|yy – Copy line to clipboard|
|D – Delete to EOL|
|p – Paste / put buffer|
|U – Undo last command|
|CTRL-R – Redo last undo|
|n – Find next occurrence of string|
|cw – Change Word|
|# command – repeat command # times|