Using vim
These are some basic commands to get you started using vim. For lots more useful information consult "VIM USER MANUAL," http://vimdoc.sourceforge.net/vimum.html, by Bram Moolenaar.
A. File creation
- At the $ prompt enter
vim
- You will then see an empty workspace
- Press the the A key
to allow you to enter text. Pressing A
puts you into append mode.
- Be sure to press Enter at the end of each line
- To save a file:
a. Press the ESC key to switch to command mode
b. Enter a colon (:). The cursor will move to the command line at the bottom
of the screen.
c. Enter wq filename.cpp
(press Enter)
- To periodically save your work:
a. Press the ESC key to switch to command mode
b. Enter :w filename.cpp
(press Enter)
- Continue entering and saving text as necessary. When you save a file this
way the previous version is replaced.
- When you're done press ESC
and enter :wq filename.cpp (Press
Enter)to save the current workspace and exit vi.
- To exit vim work session without saving current workspace press ESC
and enter :q!
B. File Modification Using vim
- Enter vim by entering the following at the $ prompt: vim
file_name
- Moving cursor around the screen
To end of current line use: $
To start of current line use: 0
up, down left, right use arrow keys OR k
, j, h, l
To end of file use: G
To first line of file use :1
ENTER
- To advance to next page use pgdown.
To go back to previous page use pgup
- To display line numbers enter:
ESC colon (:), set
number , ENTER
- To move cursor to a specific line enter
ESC colon(:), line_number,
ENTER
e.g. ESC:15 ENTER
- To insert text to left of cursor, enter i
followed by text to insert.
To insert text to right of cursor,enter a
followed by text to insert.
Lines may be inserted by following the same sequence and pressing ENTER as
appropriate.
- To delete character at cursor use x
- To delete line containing cursor use
dd
To delete several lines from cursor line on use:
#_of_linesdd, e.g. 12dd
- To replace character at cursor use
r newch
To substitute more than one character for character at cursor use s
newchars
- To replace all occurrences of a text pattern with another use
:g/text_pattern/s//replacement_pattern/g
- To search the file you are editing:
Forwards from cursor use /pattern
ENTER
Backwards from cursor use ?pattern
ENTER
To repeat previous search command use /ENTER
- To join current line with next line use J
- To move a block of text
-Position cursor at start of block
-remove block with #_lines_in_blockdd
e.g. 10dd
-reposition cursor
-press lowercase p
- To copy a block of text
-Position cursor at start of block
-copy block with #_lines_in_blockyy e.g. 12yy
-reposition cursor
-enter lowercase p
- Enter % with cursor on a
(,),{,},[,] to find its mate.
For lots more useful information consult "VIM USER MANUAL," http://vimdoc.sourceforge.net/vimum.html, by Bram Moolenaar.