various.txt For Vim version 7.4. Last change: 2014 Mar 23LINK


Various commands variousLINK

1. Various commands various-cmds

2. Using Vim like less or more less


1. Various commands various-cmdsLINK


CTRL-L Clear and redraw the screen. The redraw may happen

later, after processing typeahead.

:redr :redrawLINK

:redr[aw][!] Redraw the screen right now. When ! is included it is

cleared first.

Useful to update the screen halfway executing a script

or function. Also when halfway a mapping and

'lazyredraw' is set.

:redraws :redrawstatusLINK

:redraws[tatus][!] Redraw the status line of the current window. When !

is included all status lines are redrawn.

Useful to update the status line(s) when 'statusline'

includes an item that doesn't cause automatic



<Del> When entering a number: Remove the last digit.

Note: if you like to use <BS> for this, add this

mapping to your .vimrc:

:map CTRL-V <BS> CTRL-V <Del>

See :fixdel if your <Del> key does not do what you


:as[cii] or ga :as :asciiLINK

ga Print the ascii value of the character under the

cursor in decimal, hexadecimal and octal. For

example, when the cursor is on a 'R':

<R> 82, Hex 52, Octal 122

When the character is a non-standard ASCII character,

but printable according to the 'isprint' option, the

non-printable version is also given. When the

character is larger than 127, the <M-x> form is also

printed. For example:

<~A> <M-^A> 129, Hex 81, Octal 201

<p> <|~> <M-~> 254, Hex fe, Octal 376

(where <p> is a special character)

The <Nul> character in a file is stored internally as

<NL>, but it will be shown as:

<^@> 0, Hex 00, Octal 000

If the character has composing characters these are

also shown. The value of 'maxcombine' doesn't matter.

Mnemonic: Get Ascii value. {not in Vi}


g8 Print the hex values of the bytes used in the

character under the cursor, assuming it is in UTF-8

encoding. This also shows composing characters. The

value of 'maxcombine' doesn't matter.

Example of a character with two composing characters:

e0 b8 81 + e0 b8 b9 + e0 b9 89

{not in Vi} {only when compiled with the +multi_byte



8g8 Find an illegal UTF-8 byte sequence at or after the

cursor. This works in two situations:

1. when 'encoding' is any 8-bit encoding

2. when 'encoding' is "utf-8" and 'fileencoding' is

any 8-bit encoding

Thus it can be used when editing a file that was

supposed to be UTF-8 but was read as if it is an 8-bit

encoding because it contains illegal bytes.

Does not wrap around the end of the file.

Note that when the cursor is on an illegal byte or the

cursor is halfway a multi-byte character the command

won't move the cursor.

{not in Vi} {only when compiled with the +multi_byte


:p :pr :print E749LINK

:[range]p[rint] [flags]

Print [range] lines (default current line).

Note: If you are looking for a way to print your text

on paper see :hardcopy. In the GUI you can use the

File.Print menu entry.

See ex-flags for [flags].

:[range]p[rint] {count} [flags]

Print {count} lines, starting with [range] (default

current line cmdline-ranges).

See ex-flags for [flags].

:P :PrintLINK

:[range]P[rint] [count] [flags]

Just as ":print". Was apparently added to Vi for

people that keep the shift key pressed too long...

Note: A user command can overrule this command.

See ex-flags for [flags].

:l :listLINK

:[range]l[ist] [count] [flags]

Same as :print, but display unprintable characters

with '^' and put $ after the line. This can be

further changed with the 'listchars' option.

See ex-flags for [flags].

:nu :numberLINK

:[range]nu[mber] [count] [flags]

Same as :print, but precede each line with its line

number. (See also 'highlight' and 'numberwidth'


See ex-flags for [flags].


:[range]# [count] [flags]

synonym for :number.


:#!{anything} Ignored, so that you can start a Vim script with:

#!vim -S

echo "this is a Vim script"


:z E144LINK

:{range}z[+-^.=]{count} Display several lines of text surrounding the line

specified with {range}, or around the current line

if there is no {range}. If there is a {count}, that's

how many lines you'll see; if there is only one window

then twice the value of the 'scroll' option is used,

otherwise the current window height minus 3 is used.

If there is a {count} the 'window' option is set to

its value.

:z can be used either alone or followed by any of

several punctuation marks. These have the following


mark first line last line new cursor line

---- ---------- --------- ------------

+ current line 1 scr forward 1 scr forward

- 1 scr back current line current line

^ 2 scr back 1 scr back 1 scr back

. 1/2 scr back 1/2 scr fwd 1/2 scr fwd

= 1/2 scr back 1/2 scr fwd current line

Specifying no mark at all is the same as "+".

If the mark is "=", a line of dashes is printed

around the current line.

:{range}z#[+-^.=]{count} :z#LINK

Like ":z", but number the lines.

{not in all versions of Vi, not with these arguments}


:= [flags] Print the last line number.

See ex-flags for [flags].

:{range}= [flags] Prints the last line number in {range}. For example,

this prints the current line number:


See ex-flags for [flags].

:norm[al][!] {commands} :norm :normalLINK

Execute Normal mode commands {commands}. This makes

it possible to execute Normal mode commands typed on

the command-line. {commands} are executed like they

are typed. For undo all commands are undone together.

Execution stops when an error is encountered.

If the [!] is given, mappings will not be used.

Without it, when this command is called from a

non-remappable mapping (:noremap), the argument can

be mapped anyway.

{commands} should be a complete command. If

{commands} does not finish a command, the last one

will be aborted as if <Esc> or <C-C> was typed.

This implies that an insert command must be completed

(to start Insert mode, see :startinsert). A ":"

command must be completed as well. And you can't use

"Q" or "gQ" to start Ex mode.

The display is not updated while ":normal" is busy.

{commands} cannot start with a space. Put a count of

1 (one) before it, "1 " is one space.

The 'insertmode' option is ignored for {commands}.

This command cannot be followed by another command,

since any '|' is considered part of the command.

This command can be used recursively, but the depth is

limited by 'maxmapdepth'.

An alternative is to use :execute, which uses an

expression as argument. This allows the use of

printable characters to represent special characters.


:exe "normal \<c-w>\<c-w>"

{not in Vi, of course}

{not available when the +ex_extra feature was

disabled at compile time}

:{range}norm[al][!] {commands} :normal-rangeLINK

Execute Normal mode commands {commands} for each line

in the {range}. Before executing the {commands}, the

cursor is positioned in the first column of the range,

for each line. Otherwise it's the same as the

":normal" command without a range.

{not in Vi}

{not available when +ex_extra feature was disabled

at compile time}

:sh :shell E371LINK

:sh[ell] This command starts a shell. When the shell exits

(after the "exit" command) you return to Vim. The

name for the shell command comes from 'shell' option.


Note: This doesn't work when Vim on the Amiga was

started in QuickFix mode from a compiler, because the

compiler will have set stdin to a non-interactive


:!cmd :! E34LINK

:!{cmd} Execute {cmd} with the shell. See also the 'shell'

and 'shelltype' option.

Any '!' in {cmd} is replaced with the previous

external command (see also 'cpoptions'). But not when

there is a backslash before the '!', then that

backslash is removed. Example: ":!ls" followed by

":!echo ! \! \\!" executes "echo ls ! \!".

After the command has been executed, the timestamp of

the current file is checked timestamp.

A '|' in {cmd} is passed to the shell, you cannot use

it to append a Vim command. See :bar.

A newline character ends {cmd}, what follows is

interpreted as a following ":" command. However, if

there is a backslash before the newline it is removed

and {cmd} continues. It doesn't matter how many

backslashes are before the newline, only one is


On Unix the command normally runs in a non-interactive

shell. If you want an interactive shell to be used

(to use aliases) set 'shellcmdflag' to "-ic".

For Win32 also see :!start.

Vim redraws the screen after the command is finished,

because it may have printed any text. This requires a

hit-enter prompt, so that you can read any messages.

To avoid this use:

:silent !{cmd}

The screen is not redrawn then, thus you have to use

CTRL-L or ":redraw!" if the command did display


Also see shell-window.


:!! Repeat last ":!{cmd}".

:ve :versionLINK

:ve[rsion] Print the version number of the editor. If the

compiler used understands "__DATE__" the compilation

date is mentioned. Otherwise a fixed release-date is


The following lines contain information about which

features were enabled when Vim was compiled. When

there is a preceding '+', the feature is included,

when there is a '-' it is excluded. To change this,

you have to edit feature.h and recompile Vim.

To check for this in an expression, see has().

Here is an overview of the features.

The first column shows the smallest version in which

they are included:

T tiny

S small

N normal

B big

H huge

m manually enabled or depends on other features

(none) system dependent

Thus if a feature is marked with "N", it is included

in the normal, big and huge versions of Vim.


+acl ACL support includedLINK

+ARP Amiga only: ARP support includedLINK

B +arabic Arabic language supportLINK

N +autocmd :autocmd, automatic commandsLINK

m +balloon_eval balloon-eval support. Included when compiling withLINK

supported GUI (Motif, GTK, GUI) and either

Netbeans/Sun Workshop integration or +eval feature.

N +browse :browse commandLINK

N +builtin_terms some terminals builtin builtin-termsLINK

B ++builtin_terms maximal terminals builtin builtin-termsLINK

N +byte_offset support for 'o' flag in 'statusline' option, "go"LINK

and ":goto" commands.

N +cindent 'cindent', C indentingLINK

N +clientserver Unix and Win32: Remote invocation clientserverLINK

+clipboard clipboard supportLINK

N +cmdline_compl command line completion cmdline-completionLINK

N +cmdline_hist command line history cmdline-historyLINK

N +cmdline_info 'showcmd' and 'ruler'LINK

N +comments 'comments' supportLINK

B +conceal "conceal" support, see conceal :syn-conceal etc.LINK

N +cryptv encryption support encryptionLINK

B +cscope cscope supportLINK

m +cursorbind 'cursorbind' supportLINK

m +cursorshape termcap-cursor-shape supportLINK

m +debug Compiled for debugging.LINK

N +dialog_gui Support for :confirm with GUI dialog.LINK

N +dialog_con Support for :confirm with console dialog.LINK

N +dialog_con_gui Support for :confirm with GUI and console dialog.LINK

N +diff vimdiff and 'diff'LINK

N +digraphs digraphs E196LINK

+dnd Support for DnD into the "~ register quote_~.LINK

B +emacs_tags emacs-tags filesLINK

N +eval expression evaluation eval.txtLINK

N +ex_extra Vim's extra Ex commands: :center, :left,LINK

:normal, :retab and :right

N +extra_search 'hlsearch' and 'incsearch' options.LINK

B +farsi farsi languageLINK

N +file_in_path gf, CTRL-W_f and <cfile>LINK

N +find_in_path include file searches: [I, :isearch,LINK

CTRL-W_CTRL-I, :checkpath, etc.

N +folding foldingLINK

+footer gui-footerLINK

+fork Unix only: fork shell commandsLINK

+float Floating point supportLINK

N +gettext message translations multi-langLINK

+GUI_Athena Unix only: Athena GUILINK

+GUI_neXtaw Unix only: neXtaw GUILINK


+GUI_Motif Unix only: Motif GUILINK

+GUI_Photon QNX only: Photon GUILINK

m +hangul_input Hangul input support hangulLINK

+iconv Compiled with the iconv() functionLINK

+iconv/dyn Likewise iconv-dynamic /dynLINK

N +insert_expand insert_expand Insert mode completionLINK

N +jumplist jumplistLINK

B +keymap 'keymap'LINK

B +langmap 'langmap'LINK

N +libcall libcall()LINK

N +linebreak 'linebreak', 'breakat' and 'showbreak'LINK

N +lispindent 'lisp'LINK

N +listcmds Vim commands for the list of buffers buffer-hiddenLINK

and argument list :argdelete

N +localmap Support for mappings local to a buffer :map-localLINK

m +lua Lua interfaceLINK

m +lua/dyn Lua interface /dynLINK

N +menu :menuLINK

N +mksession :mksessionLINK

N +modify_fname filename-modifiersLINK

N +mouse Mouse handling mouse-usingLINK

N +mouseshape 'mouseshape'LINK

B +mouse_dec Unix only: Dec terminal mouse handling dec-mouseLINK

N +mouse_gpm Unix only: Linux console mouse handling gpm-mouseLINK

B +mouse_netterm Unix only: netterm mouse handling netterm-mouseLINK

N +mouse_pterm QNX only: pterm mouse handling qnx-terminalLINK

N +mouse_sysmouse Unix only: *BSD console mouse handling sysmouseLINK

B +mouse_sgr Unix only: sgr mouse handling sgr-mouseLINK

B +mouse_urxvt Unix only: urxvt mouse handling urxvt-mouseLINK

N +mouse_xterm Unix only: xterm mouse handling xterm-mouseLINK

N +multi_byte 16 and 32 bit characters multibyteLINK

+multi_byte_ime Win32 input method for multibyte chars multibyte-imeLINK

N +multi_lang non-English language support multi-langLINK

m +mzscheme Mzscheme interface mzschemeLINK

m +mzscheme/dyn Mzscheme interface mzscheme-dynamic /dynLINK

m +netbeans_intg netbeansLINK

m +ole Win32 GUI only: ole-interfaceLINK

N +path_extra Up/downwards search in 'path' and 'tags'LINK

m +perl Perl interface perlLINK

m +perl/dyn Perl interface perl-dynamic /dynLINK

N +persistent_undo Persistent undo undo-persistenceLINK

+postscript :hardcopy writes a PostScript fileLINK

N +printer :hardcopy commandLINK

H +profile :profile commandLINK

m +python Python 2 interface pythonLINK

m +python/dyn Python 2 interface python-dynamic /dynLINK

m +python3 Python 3 interface pythonLINK

m +python3/dyn Python 3 interface python-dynamic /dynLINK

N +quickfix :make and quickfix commandsLINK

N +reltime reltime() function, 'hlsearch'/'incsearch' timeout,LINK

'redrawtime' option

B +rightleft Right to left typing 'rightleft'LINK

m +ruby Ruby interface rubyLINK

m +ruby/dyn Ruby interface ruby-dynamic /dynLINK

N +scrollbind 'scrollbind'LINK

B +signs :signLINK

N +smartindent 'smartindent'LINK

m +sniff SniFF interface sniffLINK

N +startuptime --startuptime argumentLINK

N +statusline Options 'statusline', 'rulerformat' and specialLINK

formats of 'titlestring' and 'iconstring'

m +sun_workshop workshopLINK

N +syntax Syntax highlighting syntaxLINK

+system() Unix only: opposite of +forkLINK

N +tag_binary binary searching in tags file tag-binary-searchLINK

N +tag_old_static old method for static tags tag-old-staticLINK

m +tag_any_white any white space allowed in tags file tag-any-whiteLINK

m +tcl Tcl interface tclLINK

m +tcl/dyn Tcl interface tcl-dynamic /dynLINK

+terminfo uses terminfo instead of termcapLINK

N +termresponse support for t_RV and v:termresponseLINK

N +textobjects text-objects selectionLINK

+tgetent non-Unix only: able to use external termcapLINK

N +title Setting the window 'title' and 'icon'LINK

N +toolbar gui-toolbarLINK

N +user_commands User-defined commands. user-commandsLINK

N +viminfo 'viminfo'LINK

N +vertsplit Vertically split windows :vsplitLINK

N +virtualedit 'virtualedit'LINK

S +visual Visual mode Visual-mode Always enabled since 7.4.200.LINK

N +visualextra extra Visual mode commands blockwise-operatorsLINK

N +vreplace gR and grLINK

N +wildignore 'wildignore'LINK

N +wildmenu 'wildmenu'LINK

S +windows more than one windowLINK

m +writebackup 'writebackup' is default onLINK

m +xim X input method ximLINK

+xfontset X fontset support xfontsetLINK

+xpm pixmap supportLINK

m +xpm_w32 Win32 GUI only: pixmap support w32-xpm-supportLINK

+xsmp XSMP (X session management) supportLINK

+xsmp_interact interactive XSMP (X session management) supportLINK

N +xterm_clipboard Unix only: xterm clipboard handlingLINK

m +xterm_save save and restore xterm screen xterm-screensLINK

N +X11 Unix only: can restore window title X11LINK

/dyn E370 E448LINK

To some of the features "/dyn" is added when the

feature is only available when the related library can

be dynamically loaded.

:ve[rsion] {nr} Is now ignored. This was previously used to check the

version number of a .vimrc file. It was removed,

because you can now use the ":if" command for

version-dependent behavior. {not in Vi}

:redi :redirLINK

:redi[r][!] > {file} Redirect messages to file {file}. The messages which

are the output of commands are written to that file,

until redirection ends. The messages are also still

shown on the screen. When [!] is included, an

existing file is overwritten. When [!] is omitted,

and {file} exists, this command fails.

Only one ":redir" can be active at a time. Calls to

":redir" will close any active redirection before

starting redirection to the new target.

To stop the messages and commands from being echoed to

the screen, put the commands in a function and call it

with ":silent call Function()".

An alternative is to use the 'verbosefile' option,

this can be used in combination with ":redir".

{not in Vi}

:redi[r] >> {file} Redirect messages to file {file}. Append if {file}

already exists. {not in Vi}

:redi[r] @{a-zA-Z}

:redi[r] @{a-zA-Z}> Redirect messages to register {a-z}. Append to the

contents of the register if its name is given

uppercase {A-Z}. The ">" after the register name is

optional. {not in Vi}

:redi[r] @{a-z}>> Append messages to register {a-z}. {not in Vi}

:redi[r] @*>

:redi[r] @+> Redirect messages to the selection or clipboard. For

backward compatibility, the ">" after the register

name can be omitted. See quotestar and quoteplus.

{not in Vi}

:redi[r] @*>>

:redi[r] @+>> Append messages to the selection or clipboard.

{not in Vi}

:redi[r] @"> Redirect messages to the unnamed register. For

backward compatibility, the ">" after the register

name can be omitted. {not in Vi}

:redi[r] @">> Append messages to the unnamed register. {not in Vi}

:redi[r] => {var} Redirect messages to a variable. If the variable

doesn't exist, then it is created. If the variable

exists, then it is initialized to an empty string.

The variable will remain empty until redirection ends.

Only string variables can be used. After the

redirection starts, if the variable is removed or

locked or the variable type is changed, then further

command output messages will cause errors. {not in Vi}

:redi[r] =>> {var} Append messages to an existing variable. Only string

variables can be used. {not in Vi}

:redi[r] END End redirecting messages. {not in Vi}

:sil :silentLINK

:sil[ent][!] {command} Execute {command} silently. Normal messages will not

be given or added to the message history.

When [!] is added, error messages will also be

skipped, and commands and mappings will not be aborted

when an error is detected. v:errmsg is still set.

When [!] is not used, an error message will cause

further messages to be displayed normally.

Redirection, started with :redir, will continue as

usual, although there might be small differences.

This will allow redirecting the output of a command

without seeing it on the screen. Example:

:redir >/tmp/foobar

:silent g/Aap/p

:redir END

To execute a Normal mode command silently, use the

:normal command. For example, to search for a

string without messages:

:silent exe "normal /path\<CR>"

":silent!" is useful to execute a command that may

fail, but the failure is to be ignored. Example:

:let v:errmsg = ""

:silent! /^begin

:if v:errmsg != ""

: ... pattern was not found

":silent" will also avoid the hit-enter prompt. When

using this for an external command, this may cause the

screen to be messed up. Use CTRL-L to clean it up


":silent menu ..." defines a menu that will not echo a

Command-line command. The command will still produce

messages though. Use ":silent" in the command itself

to avoid that: ":silent menu .... :silent command".

:uns :unsilentLINK

:uns[ilent] {command} Execute {command} not silently. Only makes a

difference when :silent was used to get to this


Use this for giving a message even when :silent was

used. In this example :silent is used to avoid the

message about reading the file and :unsilent to be

able to list the first line of each file.

:silent argdo unsilent echo expand('%') . ": " . getline(1)

:verb :verboseLINK

:[count]verb[ose] {command}

Execute {command} with 'verbose' set to [count]. If

[count] is omitted one is used. ":0verbose" can be

used to set 'verbose' to zero.

The additional use of ":silent" makes messages

generated but not displayed.

The combination of ":silent" and ":verbose" can be

used to generate messages and check them with

v:statusmsg and friends. For example:

:let v:statusmsg = ""

:silent verbose runtime foobar.vim

:if v:statusmsg != ""

: " foobar.vim could not be found


When concatenating another command, the ":verbose"

only applies to the first one:

:4verbose set verbose | set verbose



For logging verbose messages in a file use the

'verbosefile' option.


When 'verbose' is non-zero, listing the value of a Vim option or a key map or

an abbreviation or a user-defined function or a command or a highlight group

or an autocommand will also display where it was last defined. If it was

defined manually then there will be no "Last set" message. When it was

defined while executing a function, user command or autocommand, the script in

which it was defined is reported.

{not available when compiled without the +eval feature}


K Run a program to lookup the keyword under the

cursor. The name of the program is given with the

'keywordprg' (kp) option (default is "man"). The

keyword is formed of letters, numbers and the

characters in 'iskeyword'. The keyword under or

right of the cursor is used. The same can be done

with the command

:!{program} {keyword}

There is an example of a program to use in the tools

directory of Vim. It is called 'ref' and does a

simple spelling check.

Special cases:

- If 'keywordprg' is empty, the ":help" command is

used. It's a good idea to include more characters

in 'iskeyword' then, to be able to find more help.

- When 'keywordprg' is equal to "man", a count before

"K" is inserted after the "man" command and before

the keyword. For example, using "2K" while the

cursor is on "mkdir", results in:

!man 2 mkdir

- When 'keywordprg' is equal to "man -s", a count

before "K" is inserted after the "-s". If there is

no count, the "-s" is removed.

{not in Vi}


{Visual}K Like "K", but use the visually highlighted text for

the keyword. Only works when the highlighted text is

not more than one line. {not in Vi}

[N]gs gs :sl :sleepLINK

:[N]sl[eep] [N] [m] Do nothing for [N] seconds. When [m] is included,

sleep for [N] milliseconds. The count for "gs" always

uses seconds. The default is one second.

:sleep "sleep for one second

:5sleep "sleep for five seconds

:sleep 100m "sleep for a hundred milliseconds

10gs "sleep for ten seconds

Can be interrupted with CTRL-C (CTRL-Break on MS-DOS).

"gs" stands for "goto sleep".

While sleeping the cursor is positioned in the text,

if at a visible position. {not in Vi}

Also process the received netbeans messages. {only

available when compiled with the +netbeans_intg



g CTRL-A Only when Vim was compiled with MEM_PROFILING defined

(which is very rare): print memory usage statistics.

Only useful for debugging Vim.


2. Using Vim like less or more lessLINK

If you use the less or more program to view a file, you don't get syntax

highlighting. Thus you would like to use Vim instead. You can do this by

using the shell script "$VIMRUNTIME/macros/".

This shell script uses the Vim script "$VIMRUNTIME/macros/less.vim". It sets

up mappings to simulate the commands that less supports. Otherwise, you can

still use the Vim commands.

This isn't perfect. For example, when viewing a short file Vim will still use

the whole screen. But it works good enough for most uses, and you get syntax


The "h" key will give you a short overview of the available commands.