How to set vim/gvim on windows?

Using the following steps one can setup vim/gvim to run on windows.

1) Add the following new variable VIM on your system. Example: VIM=C:\apps\vim\vim73 (Where C:\apps\vim\vim73 is where vim/gvim is installed)
2) Copy the file %VIM%\vimrc_example.vim as _vimrc in %VIM% folder
3) Add the following 2 lines at the end in %VIM%\_vimrc so it sets up vim for windows
source $VIM/mswin.vim
behave mswin

Advertisements

Movement commands in vi

Move by one character
h – Move cursor left
j – Move cursor down
k – Move cursor up
l – Move cursor right

Move by word
w or W – Move forward by word, cursor is beginning of the word
b or B – Move backward by word, cursor is beginning of the word
e or E – Move forward by word, cursor is end of the word

Move by line
0 – Move to start of line (Position 0)
$ – Move to end of line
^ – Move to start of line (exclude leading spaces)
j – Move down one line
+ – Move down one line to first character (exclude leading spaces)
– – Move up one line to first character (exclude leading spaces)
H – Move to first line on the screen
M – Move to middle line on the screen
L – Move to last line on the screen

Scroll
Ctrl-F – Scroll down by one screen
Ctrl-B – Scroll backward by one screen
Ctrl-D – Scroll down by half screen
Ctrl-U – Scroll backward by half screen
Ctrl-E – Scroll down by one line
Ctrl-Y – Scroll backward by one line

Search
/pattern + [Enter] – Search for pattern forward
?pattern + [Enter] – Search for pattern backward
n – Search for next pattern in the same direction as the last one
N – Search of next pattern in the opposite direction as the last one
/ – Search for the last pattern forward and sets direction to forward
? – Search for the last pattern backward and sets direction to backward

Search options
set ignorecase – Option sets which allows to search case insensitive
set noignorecase – Option sets which allows to search case sensitive
set nowrapscan – Search is not scrolled wrapped i.e. after reaching the end of the file it will stop searching and it will display message “Search hit BOTTOM”
set wrapscan – Search is scrolled wrapped i.e. after reaching the end of the file it will start searching for the next from top of the file and it will display message Search has hit bottom and starting from the top.

Mark current position
my – Mark current position as y
`y – Move cursor to y

Ctrl-G – Print current cursor position
nG – Move line number n
G – Move to last line in a file
1G – Move to first line in a file

Commands to change cursor position in vi

h – Left
l – Right
k – Up
j – Down
w – Move forward to beginning of next word
e – Move end of the word
b – Move backward to beginning of the previous word
0 – First position on the line
$ – Last position on the line
^ – First non-blank position on the line
+ or <Return> – First non-blank character on the next line
– First non-blank character on the previous line
n| – Column n of the current line
H – Top line of screen
L – Bottom line of screen
M – Middle line of screen

Useful commands in vi to save/quit

There are few commands one can use to save a file n
To save and quit: <esc>:wq
To save (if modified) and then quit, if not modified then does not save quit: <esc>:x (by jwood@opsource.net)
To save (if modified) and then quit, if not modified then does not save quit: <esc>ZZ (by boomslaang@hotmail.com)
To save and continue edititing: <esc>:w
To quit: <esc>:q (Note: You will be able to quit from vi if no changes were made in the file since opening the file or all changes have already been saved, if there changes in the file vi will display the following message “No write since last change..”)
To force quit without saving: <esc>:q!
To save with a different filename: <esc>:w <new filename path can be specified too> (It can be used incases when one doesn’t have permission to overwrite the file or directory is not writable by the user so using this option the changes made by the user can be saved with a different name in a different folder)

Useful commands in vi to delete

Useful commands in vi:
To delete lines
One at a time: <esc>dd
n lines at a time: <esc>ndd – where n is the number of lines to be deleted, eg: 3dd would delete 3 lines

To delete all blank lines (lines that don’t have spaces in between): <esc>:g/^$/d
To delete all blank lines that have spaces in them: <esc>:g/^ *$/d
To delete from current cursor position to end of line: <esc>d$ or <esc>D
To delete from current cursor position to beginning of line: <esc>d0
To delete word from current cursor position forward: <esc>dw
To delete word from current cursor position backward: <esc>db
To delete current character: <esc>dl or <esc>x
To delete one character backward: <esc>dh or <esc>X