vim - ex commands

Table of Contents

Ex commands

EX COMMANDS (↵)

command description
:e f edit file f, unless changes have been made
:e! f edit file f always (by default reload current)
:n :N edit next, previous file in list
:rw write range r to current file
:rw f write range r to file f
:rw>>f append range r to file f
:q :q! quit and confirm, quit and discard changes
:wq or :x or ZZ write to current file and exit
:wn :wN write file and edit next, previous one
<up> <down> recall commands starting with current
:r f insert content of file f below cursor
:r! c insert output of command c below cursor
:args display the argument list
:rco a :rm a copy, move range r below line a

SAVE ALL OPEN BUFFERS AT ONCE

Vim can open multiple files, each in its own buffer. Here is how to save all changes and continue working, or save all changes and exit Vim. It is also possible to quit all (discard changes).

command description
:wa write all changed files (save all changes), and keep working
:xa exit all (save all changes and close Vim)
:wqa same as :xa
:qa quit all (close Vim, but not if there are unsaved changes)
:qa! quit all (close Vim without saving—discard any changes)

The :wa and :xa commands only write a file when its buffer has been changed. By contrast, the :w command always writes the current buffer to its file (use :update to save the current buffer only if it has been changed).

Warning: If you enter :qa!, Vim will discard all changes without asking “are you sure?”.


EX RANGES

command description
, ; separates two lines numbers, set to first line
n an absolute line number n
. $ the current line, the last line in file
% * entire file, visual area
’t position of mark t
p ?p? the next, previous line where p matches
+n -n +n, -n to the preceding line number


Links to this note