gVim Quick Reference Pages Menu
Home
Basic Commands
Advanced Commands
The Settings File
 
Useful Programs
Yellow Legal Pad
 
 

gVim Quick Reference

Basic Commands

Here is a list of basic commands for gVim. This is not a complete list by any means; it is just a cheat sheet of commands that I find useful (or hard to remember) in day-to-day usage.

Introduction to Vi

Vi is a modal text editor. This means that there are two modes: a command mode and an insert mode. In insert mode, the keys on the keyboard are used to enter text, as with any other text editor. However, in command mode, the keyboard is used to enter commands, such as editing or navigating. More information on vi can be found on the wiki page.

What is Vim?

Vim is an improved version of the vi editor. It includes useful enhancements for programming. gVim is a graphical version of Vim for windows-oriented operating systems. For more information about Vim, and for downloads, visit vim.org.

Table of Basic Vim Commands

Changing Modes
a Enters edit mode (cursor is placed after the current character)
i Enters edit mode (cursor is placed before the current character)
  
Editing Text
cc Deletes the current line and leaves the cursor in insert mode.
c{motion} Deletes the text based on the specified motion and leaves the cursor in insert mode.
For example: c2w deletes the next two words.
C Deletes to the end of the line and leaves the cursor in insert mode. Same as c$.
dd Deletes the current line.
ddp Swaps two lines.
d{motion} Deletes based on the specified motion.
For example: d3w deletes the next three words.
d$ deletes to the end of the line.
D Deletes to the end of the line. Same as d$.
[count]r Replaces the current character with another.
For example: rx replaces the current character with 'x'.
[count]x Removes [count] number of characters.
For example, x deletes a single character.
3x deletes three characters.
u Undoes last action.
. Repeats the last change.
For example, if you changed a word using cwtext, then pressing . will repeat cwtext again where ever the cursor is located.
  
Navigation
[count]h Moves the cursor the specified number of characters to the left.
Placing a number before a navigation command causes it to be repeated that number of times. For example: 4h moves the cursor left four characters.
[count]j Moves the cursor the specified number of characters down.
[count]k Moves the cursor the specified number of characters up.
[count]l Moves cursor the specified number of characters to the right.
^ Moves the cursor to the first non-white space character on the line.
0 Moves the cursor to the beginning of the line.
$ Moves the cursor to the end of the line.
  
Opening and Creating Files
:enew Creates a new buffer in the current window.
:new Creates a new buffer and splits the window.
:e[dit] {filepath} Opens the specified file for editing.
:e[dit] Re-opens the current file. This refreshes the file to apply changes that were made outside of gVim.
:sp {filepath} Opens a file in split mode.
  
Quitting
:q[uit] Quits Vim.
This command will not succeed if changes have been made since last saving.
:q[uit]! Closes the current file without saving changes.
:qa! Quits the progam without saving changes.
:wq Writes changes and quits.
  
Yank and Put
y{motion} Yanks the specified text into a default register. This is like copying.
For example: yw yanks the current word into the register.
[count]yy Yanks a specified number of lines to the default register. The count is optional.
p Puts the text from the default register onto the screen. This is like pasting.
  
Yank and Put Using the Clipboard
"*y{motion} Yanks the specified text to the clipboard.
The gVim GUI commands can be used for copying and pasting (CTRL-C, CTRL-V), but you can also use the yank/put commands to access the clipboard. The commands are the same as normal yanking, except "* is prepended to the command.
"*yy Copies the current line to the clipboard.
"*p Pastes the text from the clipboard onto the screen.