gVim Commands

gVim is the graphical version of vim, which is the improved version of vi.

Getting Started

gVim can be found in the directory /usr/usc/vim/.

To set up gVim using a default USC csh or tcsh shell, run the command source /usr/usc/vim/default/setup.csh.
If you want to set up your enviroment to always set up gVim for you,
put these lines at the end of your .login file:

if (-e /usr/usc/vim/default/setup.csh) then
source /usr/usc/vim/default/setup.csh
endif

If you use a bourne shell, such as sh, ksh, or bash, run the command . /usr/usc/vim/default/setup.sh.
To set it up permanently, add these lines to your shell’s login script:

if [ -r /usr/usc/vim/default/setup.sh ] ; then
. /usr/usc/vim/default/setup.sh
fi

Now you should be able to start the command gvim

Note: In order to use gvim, you will need to be using an X-Windows compatible environment, such as those found on a SUN workstation, X-win32 on a PC, or X11 on a Mac. If you do not have such an environment, you can still use vi or vim, but not gvim.

Using gVim

Once you have your environment set up from the previous section, all you need to do is type gvim or add an amperstand (shift-7) in order to get your command prompt back: gvim &. You can have gVim start and automatically open a file named filename by typing gvim filename.

gvim.jpg

Once in gVim, you will see a menubar like in many familiar graphical applications. Using gVim is much easier to use for people familiar with graphical applications on Windows and MacOS. Next to every menu item is a keyboard shortcut to execute that function. gVim allows a new user to easily find common functions through the menu bar, but also gives the user the keystrokes that access the function faster, and are compatible with vim and usually vi.

To start using gVim, a user will first need to understand the modes of vi. You can start by opening a or creating a new file from the file
menu. Once the file is open, you will need to be in insert mode in order to add text to the file. You can enter insert mode by pressing INSERT, i, or
a. To stop editing and get back to the original command mode, press ESC. To enter status line mode in order to type longer commands, use the : key from within command mode.

vi Compatible Commands

Note: n will repeat the last search, whereas <n> represents a number to be typed in that generally sets the number of times a command is repeated.
The <n> is optional, and is assumed to be 1 if not present.

Leaving Vi


ZZ
exit from vi saving changes

:wq
exit from vi saving changes

:q
quit from vi (only if no changes made)

:q!
force quit from vi (without saving changes)

Note: You can also use the save and exit functions from the file menu.

Moving Around in Vi


h
or left arrow
move left one character

l
or right arrow
move right one character

j
or up arrow
move up one line

k
or down arrow
move down one line

Control-d
move down half screen

Control-u
move up half screen

<n> Control-f
scroll forward <n> screens

<n> Control-b
scroll backward <n> screens

1G
go to top of file

G
go to bottom of file

<n> G
go to line # <n>

0
move to beginning of the line

$
move to end of the line

<n> w
forward <n> words

<n> b
backward <n> words

Note: You can also move around through gVim by using the mouse and the scrollbar.

Inserting


i
insert at cursor

o
open new line below current line

O
open new line above current line

ESC
exit insert mode (stop inserting)

Deleting


<n> x
delete <n> characters

<n> dd
delete <n> entire lines

<n> dw
delete <n> words

Changing and Replacing


<n> cw
change <n> words

<n> cc
change <n> entire lines

:s/old/new/
replace old string with new string on
current line (replaces first occurrence
on line only)

:1,$s/old/new/g
replace old with new globally (lines 1–$
means all lines and g means all occurences
on a line.)

Searching


/pattern
forward search for pattern

?pattern
backward search for pattern

n
repeat last search

Yanking and Pasting


mx
mark current line with an x (x can be any
character)

'x
return to line marked with x

d'x
delete from line marked x to current line

y'x
yank from line marked x to current line

<n> yy
yank <n> lines starting at current

p
paste yanked lines below current line

P
paste yanked lines above current line

Miscellaneous


u
undo last change

.
repeat last change

J
join current line and next line together

Control-g
report line number information

Control-l
refresh screen

:w filename
write file out to filename

:r filename
read in filename below current line

vim Only Commands

:syntax on Turns on file-specific syntax colors

viSyntax.jpg

Note: The vim color syntax contains many bright colors, and seems best suited for a black background. You can start gvim with a black background by typing gvim -bg black -fg white &, where -bg represents the background color, -fg represents the foreground (basic text), and the & returns your command prompt.

More Help

Tips and more info are available at www.vim.org