Vi/Vim: How to pipe visually selected text to a UNIX command and append output to current file?

If you do not want to repeat the same commands over and over again, you can record the sequence by using q or add a new command. I have tried the latter as follows.

Up vote 6 down vote favorite 3 share g+ share fb share tw.

Using Vim, I'm trying to pipe visually selected text to a UNIX command and have the output appended to the end of the current file. For example, say we have a SQL command such as: SELECT * FROM mytable; I want to do something like the following: V # select text :'! Mysql -uuser -ppass mydb But instead of having the output overwrite the currently selected text, I would like to have the output appended to the end of the file.

You probably see where this is going. I'm working on using VIM as a simple SQL editor. That way, I don't have to leave VIM to edit, tweak, test SQL code.

Thanks! Sql vim editor vi link|improve this question asked Oct 23 '08 at 15:45drsnyder40129.

Thanks! That worked as expected. Here is the actual command I used: com -range C ,yank | $ | put | .

,$! /usr/local/mysql/bin/mysql -uuser mydb I had a "select * from table;" line in the text file and I just :C and it dumped the output at the end of the file. – drsnyder Oct 23 '08 at 17:42.

If you do not want to repeat the same commands over and over again, you can record the sequence by using q or add a new command. I have tried the latter as follows: :com -range C ,yank | $ | put | . ,$!

Rev With it you can select some lines and then type :C. This will first yank the selection, then go to the end of the file, paste the yanked text and run the command (rev in this case) over the new text.

What I'm really trying to do: Pipe the selected text to a pastebin-type shell command and I want to receive the output of the shell cmd (which is the http link to the pastebin). Is this possible?

R | YourCommand For example: :r! Echo foo adds foo to your buffer.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions