VIM
Intro
VIM is sheer awesomeness. It does take a while to get used to though. For the purpose of this document, VIM has three basic modes, Command, Insert and Visual. When you start VIM you are in Command Mode. To enter Insert mode, you can hit the 'i' key or the 'insert' key. To go back to Command mode you press Escape key. You can hit 'v' key in Command mode to get into Visual mode. Enough about modes. Let's get some editing done. Hit 'i' to enter Insert mode. You should see -- INSERT -- at the bottom-left of the screen.
Insert mode
This is the most boring of modes. You just keep typing stuff until you get tired or want to do something interesting.
Command mode
This is the mode you should be in if you want to run VIM commands.
- VIM commands typically have the form :vim_command
- You enter colon (:) and then you enter your desired command. Your command will appear at the bottom-left of the screen. When the command is complete you hit enter to execute the command
- Some interesting commands
- :w (save the current file)
- :w file_name (save the current file as file_name)
- :wall (save all open files)
- :q (quit. if the file has been modified you will need to run the command below)
- :q! (quit without saving. ignore any changes made to the file)
- :qall! (quit all files without saving)
- :x (jump to line number x)
- :%s/pattern/replacement_text (replace the first instance of pattern with the replacement text. %s means substitution)
- :%s/pattern/replacement_text/g (replace all instances of pattern with the replacement text. g means global substitution)
- :split file_name (split the window into two regions and open file_name in the new region. to cycle between regions, hold down the ctrl key and hit 'w' twice)
- :earlier 10m (will take you 10 minutes into the past. you can also do 10s to go back 10 seconds in time.
- You can also string together multiple commands.
- :wq (save the file and quits)
- :wqall (save all files and quit)
- Here are some shortcuts for text editing. These are different from regular commands in that you don't have to type the colon.
- hitting 'dd' (d twice in rapid succession) will delete the line under the cursor
- if you enter a number, say 15, and hit 'dd', vim will delete 15 lines. The line below the cursor and 14 lines below that.
- hit 'u' any time to undo any changes.
- Ctrl-r will redo any undone changes.
Visual Mode
Hitting 'v' in the Command mode will take you to Visual mode. You should see --VISUAL-- on the bottom-left of the screen. In visual mode, moving around with the cursor keys will highlight regions.
- Hitting 'y' will "yank" aka copy a region.
- Hitting 'p' in the Command mode will paste the yanked region at cursor position.
Misc stuff
VIM is a highly customizable editor. You are encouraged to customize VIM in whatever way you desire. The file .vimrc in your home directory is the gateway to VIM customization. We have done some cool stuff in this file. You may want to take a look.
- Hitting
in the Command or Insert Mode will save the current file and execute it. This applies only to Ruby source files. - Line numbers are displayed
- File specific syntax highlighting and indentation is enabled
