I need to pass some selected text in vim to a curl command as a parameter value. For example. I need to be able to run
curl -sSd css="body { border-radius: 5px; }" http://prefixr.com/api/index.php
from vim. Obviously, the "body { border-radius: 5px; }" part will be dynamic. Usually, a visual mode selection in vim.
How do I get the selected text and pass it as a parameter to curl?
Press y to replace the match or l to replace the match and quit. Press n to skip the match and q or Esc to quit substitution. The a option substitutes the match and all remaining occurrences of the match.
Change and repeat Search for text using / or for a word using * . In normal mode, type cgn (change the next search hit) then immediately type the replacement. Press Esc to finish. From normal mode, search for the next occurrence that you want to replace ( n ) and press . to repeat the last change.
To quickly change a word you can use cw , caw or ciw . Use c$ or just C to quickly change from the cursor to the end of a line, cc to change an entire line, or cis for a sentence. The standard change word command requires you to type cw , then a new word, then press Escape.
Position the cursor over the character and type r , followed by just one replacement character. After the substitution, vi automatically returns to command mode (you do not need to press Esc).
You can use the :!
command to filter selected text through an external program.
The text is fed to stdin and substituted with the results from stdout.
In this case you'll have to use cat and command substitution to feed the lines as a parameter to curl, like so:
:'<,'>!curl -sSd css="`cat`" http://prefixr.com/api/index.php
By selecting one or more rows and using :! you can pass these lines to a command, for example:
So sort an entire file using the sort
command, try this: ggVG !sort, which should look like this in your editor:
B
C
A
:'<,'>!sort
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With