
If you want to highlight multiple lines or particular words in a line, you can do so in VISUAL mode. U undo all recent changes made to the current line You can use the arrow keys to navigate, or switch back to COMMAND mode and use the shortcuts mentioned earlier. I enter INSERT mode at the start of the current lineĪ enter INSERT mode appending after the cursorĪ enter INSERT mode appending to the end of the current line When you are ready to enter text, you should switch to INSERT mode. 3x deletes the 3 characters under and following the cursor). Nx delete the N characters under and following the cursor (e.g. X delete the character underneath the cursor This will put characters after the cursor and put lines below the current line depending on what you yanked. Yy or :y or Y "Yank" (cut) the current line Alternatively, search for a bogus string, like /thiswordwontexist Editing Text :noh to turn off highlighting until the next search. N move the cursor to the previous search match N move the cursor to the next search match This will highlight all matches in the editor for you to see. Search is another great way to move your cursor. Ctl-b page up ("back")Ĭtl-u half a page up. $ move to the end of the lineġ23G jump to line number 123 (equivalent to :123)Ĭtl-f page down ("forward"). e move to the end of the word ("end")Ġ move to the beginning of the line. B move to the previous word ("Back")ī move to the beginning of the word ("beginning"). There are also several additional keyboard shortcuts to navigate within a file. The preferred mode in vim, however, is to use the j``k``h``l keys instead in COMMAND mode (these do not work in INSERT mode), which allows users to keep their fingers on the home row to move around the screen. If you have unsaved changes, you will be asked whether or not you'd like to save your changes before quitting.Īrrow keys work in both modes to navigate as you would expect. If you would like to save the file under a different name, specify a filename. If you don't specify a name, changes will be saved to the current file. :w myprogram.c save the current changes to a file. Again, if this file exists in your current directory it will open it, or it will create it if it does not already exist in your current directory. If vim is already open and you would like to edit a different file, use the :e filename command (e.g. To open a file in vim (or create a new one if a file with this name does not exist): $ vim filename

Note that all commands mentioned below (except for arrow keys) only work in COMMAND mode.Over time, you will likely spend more time in COMMAND mode than INSERT mode. To go back to COMMAND mode, you type the esc key. To go into INSERT mode from COMMAND mode, you type i.There is a third mode, VISUAL mode, that is used to highlight and edit text in bulk. In COMMAND mode, you execute commands (like undo, redo, find and replace, quit, etc.). Vim has two "modes": COMMAND mode and INSERT mode. vim has a bit of a learning curve, meaning that you may get somewhat frustrated with it until you have used it a few times. Despite its age, vim is one of the most popular editors in the world, and it is available on virtually every computing platform (or vi is available). Vim is a text editor that is a clone of the vi editor, which was created around 1976. Written by Chris Gregg and Dominique Yahyavi, with modifications by Peter Johnston, Nick Troccoli, and Lisa Yan
