A combination of Vim and command-line tools is a handy text-processing toolkit for many tasks. This entry provides some examples. It makes coding and writing convenient and enjoyable.
The magic of | allows the output of a function to be the input of another.
This is analogy to one of cores of functional programming: with different combination of functions,
one can achieve different results easily without rewriting the partial codes.
Some list of linux or python text tools are natually integrated with Vim:
awk: a powerful pattern scanning and processing languagecolumn: columnate lists(print "PERM LINKS OWNER GROUP SIZE MONTH DAY HH:MM NAME" && ls -l | sed 1d) | column -tcurl: access a webpage to vimfind: search for files in a directory hierarchygpg:used to encrypt/decrypt some textgrep: search for a pattern under directoryjoin: join lines of two files on a common fieldperl: a powerful text processing languagepython: provide all kinds of text processing toolssed: stream editor for filtering and transforming textsort: sort (in reverse) lines of texttree: pretty print directory structureuniq: remove duplicate lines or count the number of occurrencesbase64: encode/decode text with base64In Vim, just use :!{cmdtool} or :read {cmdtool} to pipe the output into current buffer.
:<,>!python -m json.tool: format jsonNote use visual-select for the portion of JSON text, then :<,>!python -m json.tool
:<,>!uniq or sort
!cat % | sort -t{DELIMITER_CHAR} -k2
!cat % | sort -t\# -k2
cat file | sort -t{DELIMITER_CHAR} -k{ColToSort}
:'<,'>!base64, :'<,'>!base64 --decode:<,>!column -t# before: a b cc d 1 2 3 4 i ii iii iv # after: a b cc d 1 2 3 4 i ii iii iv # before: |name|age|height|weight| |john|17|187|78| |tom|8|144|43| |peter|18 |178|57| # after: name age height weight john 17 187 78 tom 8 144 43 peter 18 178 57
It provides more granular control of shell output to register, under the cursor, or external file.
:vnew|put=execute('scriptnames'):vnew|put=execute('ls'):put=execute('ls'):put=execute('echo expand(\"%:p\")'):put=expand('%'):redir
:redir > {file}
"do kinds of things, but the output are still printed in command window
:redir END " only write to file until `:redir END` called
Vim works well with many powerful cmd tools. The synergy makes Vim and other cmd tools great again!