leader

Vim Getting Started Notes

View markdown

Vim commands

I'm not a Vi expert but I do fine just remembering this small set of commands. I wrote this web page with Vim.


unix_prompt> vi example.txt - start vi / vim
i - Enter insert mode. You need to be in insert mode to add text.
Esc Key - exit insert mode
Move up down left right - use the arrow keys

You can NOT be in Insert Mode when you do any of the following commands, so hit the Escape key.


:w - write and save edits
:q - quit
:wq - save and exit
:q! - quit  without
x - delete 1 character
dd - delete 1 line
gg - go to first line
G - go to last line
:5 - go to line 5
/abc - find string 'abc'
n - find next
u - undo
Ctrl-R - redo (Control R)

Copy and Paste

This works for me over Putty.


1a. Left-mouse-button to select text.
1b. You can even select text from Windows (such as Word, IE, Firefox, notepad++). Just hit Ctrl-C after you select the text.
  • Move cursor to where you want to insert (using arrow keys)
  • Make sure you're in Insert Mode (press i)
  • Right-mouse-click to paste
  • If you want more details here is the Official Vim Documentation.

    Vi is frozen

    You probably typed ctrl+s. To recover type `l'ctrl+q .

    If you hit ctrl+Zin vi/vim, enter fg (foreground) at the shell prompt to bring vim back.

    Setup / Configuration File

    The Vim resource configuration file is located in your home directory at ~/.vimrc
    It is a hidden file (all files that start with dot are hidden files, so to see it type ls -a ~
    The vimrc setup file is just a text file that can be edited with vim (or emacs LOL or my favorite nedit :)

    Show Linenumbers in Vim

    To show line numbers in Vim just type :set number. To turn off line numbers type :set nonumbers
    To show line numbers by default just add set number to .vimrc.

    Blue Comments are hard to see with Vim Syntax highlighting

    I use putty and with it's default dark background I can barely see the blue comments. The vim syntax highlighting scheme can be changed with :set background=dark. To make this syntax highlighing change the default add set background=dark to .vimrc. If you don't want to change the entire Vim syntax color scheme, but just want to change the comment's color try this: :highlight Comment ctermfg=green guifg=green gui=bold To save some typing the highlight command can be abbreviated to hi Here is a link to official Vim Syntax Highlighting Documentation