In Vim,
:%!ls
executes ls
command and prints its output to the current editable file.
But what do %
and !
mean separately in vim
?
Is it possible execute ls
and not put its output to document?
In Vim,
:%!ls
executes ls
command and prints its output to the current editable file.
But what do %
and !
mean separately in vim
?
Is it possible execute ls
and not put its output to document?
Within Vim, run
:h :!
and:h :%
to know what each does.Now, the
:%
is used to replace the contents of the file with the output of the shell command run using:!
. If you don't want to touch the contents of the file, don't use%
. Just do:According to VIM Tutorial:
%
!
for more information see Vim Commands Cheat Sheet, and VIM Tutorial
I had this same question and found this in
:h cmdline-special
, which was the meaning I was looking for:None of these answers is properly correct. At the beginning of a Vim command line statement, you can specify a range over which to operate.
%
is a common range for specifying the whole file, shorthand for1,$
, i.e. line 1 to end of file. See See:h cmdline-ranges
for more.Command mode operation of Vim
:%
select all the contents of the file:!
filter through external command:%!ls
doesls | vim -
in Bash TerminalBut
:pu!
in this case,!
means current positionCompare
:pu
does normal modep
and:pu!
does normal modeP