can anyone give me an example of how !!
works? The documentation says:
!!{filter} Filter [count] lines through the external program {filter}.
can anyone give me an example of how !!
works? The documentation says:
!!{filter} Filter [count] lines through the external program {filter}.
!!
(and more generally the !
operator) provide vim builtin support for all the unix filters that have evolved over the ages: this includes cut
, paste
, sort
, uniq
, awk
, sed
, even bash
. Basically a filter is anything that can transform stdin to stdout (possibly doing something meaningful—the identity filter is just cat
).
By providing access to these tools, vim avoids re-inventing them and allows you to combine them however you see fit. Table editing, cleaning a csv file, even interpreting lines of a shell script on the fly... the possibilities are about as limitless as the construction of *nix pipelines.
For a concrete example, type
echo Hello World
In a new file, then !!sh -
and hit enter (I think I have that syntax right).
Also see this answer of mine for more complex techniques.
!!
is like !
for a single line. !
can work on arbitrary ranges, so for example !3j
, !ap
or V/}<CR>!
– D. Ben Knoble
Mar 25 at 16:46
A classic example for this filter is to sort the input using the Shell command sort
. So vi does not have to implement its own sorting algorithm but could plugin external commands to do that.
Nowadays, Vim comes with its own sort implementation as :sort
command, mainly because some systems did not provide a sort binary.