Gray at the temples and in need of reading glasses, the 43-year-old vi (pronounced vee-eye) editor is still a system administrator’s best friend. This advanced, yet simple to use, command line editing program shows no sign of slowing down. You can use it to edit configuration files, create a grocery list, write a letter home to ask for money, create a new script, or even to edit source code. Show
[ Download now: Vim cheat sheet ] Note: vi is often a symbolic link to vim (vi Improved) or an alias to vim. It’s easy to invoke vi. At the command line, you type
The vi editor has two modes: Command and Insert. When you first open a file with vi, you are in Command
mode. Command mode means that you can use keyboard keys to navigate, delete, copy, paste, and do a number of other tasks—except entering text. To enter Insert mode, press [ Free eBook: Manage your Linux environment for success. ]
To save a file, you must first be in Command mode. Press Esc to enter Command mode, and then type The best way to learn vi is to create a new file and try it out for yourself. Feel free to use the common keyboard shortcut table below to help you learn vi’s extensive vocabulary. This list of shortcuts is by no means exhaustive, but they will enable you to edit files and learn vi in a short amount of time.
[ Download now: Vim cheat sheet ] Written by Chris Gregg and Dominique Yahyavi, with modifications by Peter Johnston, Nick Troccoli, and Lisa Yan Click here for a walkthrough video.
Overview
Opening vimTo open a file in
If Saving and Quitting vim
Navigating A FileArrow keys work in both modes to navigate as you would expect. The preferred mode in
There are also several additional keyboard shortcuts to navigate within a file.
SearchingSearch is another great way to move your cursor.
Editing Text
Entering INSERT ModeWhen you are ready to enter text, you should switch to INSERT mode. There are a few ways to do this:
Then, just type as normal to enter text. You can use the arrow keys to navigate, or switch back to COMMAND mode and use the shortcuts mentioned earlier. Undo/Redo
Highlighting textIf you want to highlight multiple lines or particular words in a line, you can do so in VISUAL mode. There are three different visual modes:
Once you enter these modes by typing these in COMMAND mode, you can use the keyboard navigation (e.g., VISUAL mode is also useful for adjusting indent to a batch of text. For example, if you wanted to reduce the indent of a set of lines, you can
enter block-wise visual mode ( More ResourcesThe best way to get
familiar with
There is also a fun online Frequently Asked QuestionsWhen I do |