Sunday, March 27, 2011

Filtering text through external commands

How do I set up a mapping to make the currently selected text (visual
mode) get processed by an external command?

I have a bunch of scripts that do text processing (mostly perl and bash)
that I want to process the current buffer in vim.

To process the whole file, I can do:

map <leader>x :%! external_prog.pl<CR>

But how do I set it up so that if there is something highlighted via
visual mode then only that text gets processed.

Is there a way to set this up so that the same mapping will process the
highlighted text, or if nothing is selected process the whole file?

Alternatively, can it be set up to process either the highlighted text,
or the current line?

Thanks,
Matt


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: