Command-Line Mode

Table of Contents

Run commands in the Shell howto

Command Effect
:shell Start a shell
:!{cmd} Execute {cmd} with the shell
:read !{cmd} Execute {cmd} and paste its stdout
:[range]write !{cmd} Exectue {cmd} with [range] lines as stdin
:[range]!{filter} Filter [range] lines through external program {filter}

Bulk Rename multiple files howto

:read !ls

This will paste the files in the current directory, like follows:

a.txt
b.txt

Modify these lines to shell commands:

mv a.txt x.txt
mv b.txt y.txt

Make visual selection on these lines and run:

:'<:'>write !bash

Get the name of the current file howto

For example, in directory /abc the command vim def/my.txt would edit file /abc/def/my.txt.

:echo @%                def/my.txt       directory/name of file (relative to the current working directory of /abc)
:echo expand('%:t')     my.txt           name of file ('tail')
:echo expand('%:p')     /abc/def/my.txt  full path
:echo expand('%:p:h')   /abc/def         directory containing file ('head')
:echo expand('%:p:h:t') def              :p (/abc/def/my.txt), then  :h (/abc/def), then  :t (def)
:echo expand('%:r')     my               name of file less one extension ('root')
:echo expand('%:e')     txt              name of file's extension ('extension')

For more info run :help expand