Viper Card
Viper Card
Viper has four states: emacs state, vi state, insert state, replace
state. Mode line tells you which state you are in. In emacs state you
Registers
can do all the normal GNU Emacs editing. This card explains only
vi state and insert state (replace state is similar to insert state). There are 26 registers (a to z) that can store texts and marks. You
GNU Emacs Reference Card explains emacs state. You can can append a text at the end of a register (say x) by specifying the
switch states as follows. register name in capital letter (say X). There are also 9 read only
registers (1 to 9) that store up to 9 previous changes. We will use
from emacs state to vi state C-z x to denote a register.
from vi state to emacs state C-z
from vi state to emacs state for 1 command \
from vi state to insert state i, I, a, A, o, O Entering Insert Mode
from vi state to replace state c, C, R
from insert or replace state to vi state ESC insert at point i
from insert state to vi state for 1 command C-z append after cursor a
insert before first non-white I
append at end of line A
Insert Mode open line below o
open line above O
You can do editing in insert state.
go back to vi state ESC
delete previous character C-h, DEL
Buffers and Windows
delete previous word C-w
delete line word C-u move cursor to next window C-x o
indent shiftwidth forward C-t delete current window C-x 0
indent shiftwidth backward C-d delete other windows C-x 1
quote following character C-v split current window into two windows C-x 2
emulate Meta key in emacs state C-\ switch to a buffer in the current window C-x buffer
escape to Vi state for one command C-z switch to a buffer in another window :n, :b, or C-x 4 buf
kill a buffer :q! or C-x k
The rest of this card explains commands in vi state. list existing buffers :args or C-x b
1
Viewing the Buffer Motion Commands
scroll to next screen C-f go backward one character h or C-h
scroll to previous screen C-b go forward one character l
scroll down half screen C-d next line keeping the column j or LF or C-n
scroll up half screen C-u previous line keeping the column k
scroll down one line C-e next line at first non-white + or RET or C-p
scroll up one line C-y previous line at first non-white -
put current line on the home line z H or z RET beginning of line 0
put current line on the middle line z M or z . first non-white on line ^
put current line on the last line z L or z - end of line $
go to n-th column on line n |
Marking and Returning go to n-th line n G
go to last line G
mark point in register x m x find matching parenthesis for (), {} and [] %
set mark at buffer beginning m < go to home window line H
set mark at buffer end m > go to middle window line M
set mark at point m . go to last window line L
jump to mark m ,
exchange point and mark ‘ ‘ Words, Sentences, Paragraphs, Headings
... and skip to first non-white on line ’ ’
go to mark x ‘ x forward word w or W
... and skip to first non-white on line ’ x backward word b or B
view contents of marker x [ x end of word e or E
view contents of register x ] x In the case of capital letter commands, a word is delimited by a
non-white character.
Macros forward sentence )
backward sentence (
Emacs style macros: forward paragraph }
start remembering keyboard macro C-x ( backward paragraph {
finish remembering keyboard macro C-x ) forward heading ]]
call last keyboard macro * backward heading [[
start remembering keyboard macro @ # end of heading []
finish macro and put into register x @ x
execute macro stored in register x @ x Find Characters on the Line
repeat last @x command @ @
find c forward on line f c
Pull last macro into register x @ ! x
find c backward on line F c
Vi-style macros (keys to be hit in quick succession): up to c forward on line t c
define Vi-style macro for Vi state :map up to c backward on line T c
define Vi-style macro for Insert state :map! repeat previous f, F, t or T ;
... in the opposite direction ,
toggle case-sensitive search //
toggle regular expression search ///
toggle ‘%’ to ignore parentheses inside com- %%% Searching and Replacing
ments
search forward for pat / pat
search backward with previous pat ? RET
search forward with previous pat / RET
search backward for pat ? pat
repeat previous search n
... in the opposite direction N
query replace Q
replace a character by another character c r c
overwrite n lines n R
buffer search (if enabled) g move command
2
Modifying Commands Miscellaneous Commands
Most commands that operate on text regions accept the motion shift left shift right filter shell command indent
commands, to describe regions. They also accept the Emacs re- region < m > m ! m shell-com = m
gion specifications r and R. r describes the region between point line < < > > ! ! shell-com = =
and mark, and R describes whole lines in that region. Motion join lines J
commands are classified into point commands and line commands. toggle case (takes count) ~
In the case of line commands, whole lines will be affected by the
command. view register x ] x
view marker x ] x
The point commands are as follows:
lowercase region # c m
h l 0 ^ $ w W b B e E ( ) / ? ‘ f F t T % ; , uppercase region # C m
The line commands are as follows: execute last keyboard macro on each line in the # g m
j k + - H M L { } G ’ region
insert specified string for each line in the region # q m
These region specifiers will be referred to as m below.
check spelling of the words in the region # s m
Delete/Yank/Change Commands repeat previous ex substitution &
change to previous file C-^
delete yank change Viper Meta key _
region determined by m d m y m c m
... into register x " x d m " x y m " x c m
a line d d Y or y y c c Customization
current region d r y r c r
expanded region d R y R c R By default, search is case sensitive. You can change this by includ-
to end of line D y $ c $ ing the following line in your ~/.vip file.
a character after point x y l c l (setq viper-case-fold-search t)
a character before point DEL y h c h
The following is a subset of the variety of options available for
Overwrite n lines n R customizing Viper. See the Viper manual for details on these and
other options.
Put Back Commands variable default value
viper-search-wrap-around t
Deleted/yanked/changed text can be put back by the following viper-case-fold-search nil
commands. viper-re-search t
Put back at point/above line P viper-re-replace t
... from register x " x P viper-re-query-replace t
put back after point/below line p viper-auto-indent nil
... from register x " x p viper-shift-width 8
viper-tags-file-name "TAGS"
Repeating and Undoing Modifications viper-no-multiple-ESC t
viper-ex-style-motion t
undo last change u or :und viper-always t
repeat last change . (dot) viper-custom-file-name "~/.vip"
Undo is undoable by u and repeatable by .. For example, u... will ex-find-file-shell "csh"
undo 4 previous changes. A . after 5dd is equivalent to 5dd, while ex-cycle-other-window t
3. after 5dd is equivalent to 3dd. ex-cycle-through-non-buffers t
blink-matching-paren t
buffer-read-only buffer dependent
To bind keys in Vi command state, put lines like these in your
~/.vip file:
3
Ex Commands in Viper Ex File and Shell Commands
In vi state, an Ex command is entered by typing: edit file :e file
: ex-command RET reedit messed up current file :e!
edit previous file :e#
read in a file :r file
Ex Addresses read in the output of a shell command :r !command
write out specified lines into file :w file
current line . next line with pat / pat / save all modified buffers, ask confirmation :W file
line n n previous line with pat ? pat ? save all modified buffers, no confirmation :WW file
last line $ n line before a a - n write out specified lines at the end of file :w>> file
next line + a through b a , b write to the input of a shell command :w !command
previous line - line marked with x ’ x write out and then quit :wq file
entire buffer % previous context ’ ’
run a subshell in a window :sh
Addresses can be specified in front of a command. For example, execute shell command command :! command
:.,.+10m$ execute previous shell command with args ap- :!! args
pended
moves 11 lines below current line to the end of buffer.
Ex Miscellaneous Commands
Ex Commands
define a macro x that expands to cmd :map x cmd
Avoid Ex text manipulation commands except substitute. There remove macro expansion associated with x :unma x
are better VI equivalents for all of them. Also note that all Ex define a macro x that expands to cmd in insert :map! x cmd
commands expand % to current file name. To include a % in the state
remove macro expansion associated with x in in- :unma! x
command, escape it with a \. Similarly, # is replaced by previous sert state
file. For Viper, this is the first file in the :args listing for that print line number :.=
buffer. This defaults to the previous file in the VI sense if you have print last line number :=
one window. Ex commands can be made to have history. See the print version number of Viper :ve
manual for details.
shift specified lines to the right :>
Ex Text Commands shift specified lines to the left :<
join lines :j
mark lines matching pat and execute cmds on :g /pat/ cmds mark specified line to register x :k x
these lines set a variable’s value :se
mark lines not matching pat and execute cmds :v /pat/ cmds find first definition of tag tag :ta tag
on these lines
move specified lines after addr :m addr Current directory :pwd
copy specified lines after addr :co (or :t) addr Copyright c 2025 Free Software Foundation, Inc.
by Michael Kifer, Viper 3.0
delete specified lines [into register x ] :d [x ] by Aamod Sane, VIP version 4.3
yank specified lines [into register x ] :y [x ] by Masahiko Sato, VIP version 3.5
put back text [from register x ] :pu [x ] Released under the terms of the GNU General Public License version 3 or
substitute repl for first string on line matching :s /pat/repl/ later.
pat For more Emacs documentation, and the TEX source for this card, see the
repeat last substitution :& Emacs distribution, or https://www.gnu.org/software/emacs
repeat previous substitute with previous search :~
pattern as pat