sponsor Vim development Vim logo Vim Book Ad

basic Tip #374: VIM's Filtering Commands Summary

 tip karma   Rating 32/18, Viewed by 2372 

created:   November 24, 2002 14:54      complexity:   basic
author:   zzapper      as of Vim:   6.0

Vim's Filtering Commands or how to get text into or out of a file

# Redirection to Paste register * (or any other a-z)
:redir @*                    : start redirect commands to paste buffer
:history
:g/fred/
etc etc
:redir END                   : end redirect

# Redirection to a file
:redir >> out.txt            : redirect to a file
blahblah
:redir END                   : end redirect

# Storing glob results in register a (note must use APPEND)
:g/fred/y A                  : append all lines fred to register a
# to a file (must use >>)
:'a,'b g/^Error/ . w >> errors.txt

# Get output from external commands
:r!ls.exe                    : reads in output of ls
!!date                       : same thing

# Filtering current file using an external command
:%!sort -u                   : use an external program to sort current file
:'a,'b!sort -u               : use an external program to sort current file

These tips are "filtered" from vimtip #353

 rate this tip  Life Changing Helpful Unfulfilling 

<< Run find/replace/search on multiple files and subdirectories | autocmd for skeleton html file (BufFileNew) >>

Additional Notes

[email protected], November 24, 2002 14:59
Ahem I meant filtered from vimtip #305 of course
Anonymous, November 26, 2002 23:18
to sort the actual paragraph at cursorposition from normal mode with external sort program (-u deletes multiple lines):
    !1} sort -u
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
    stats
Sponsored by Web Concept Group Inc. SourceForge.net Logo