Write buffer to command and append stdout back to same bufferHow to execute selected lines in bash and print the output in the next line?External command on unsaved bufferhow to perform multiple grep passes by using piping in external shell?Vimfiler (a plugin): how to open .doc file using MS WordHow can I write a range to a command, and then read the resulting output?Why does vim add ^J to the end of my macros?Text manipulation by calling external binaries or scriptsHow to get line numbers of selected textDiffsplit with output of external command in Vim?Execute selection and redirect output to new buffer/tabPass character-wise visual selection to an external command

Understanding Deutch's Algorithm

Wifi is sometimes soft blocked by unknown service

the correct order of manual install WP and SSL on server

Will there be more tax deductions if I put the house completely under my name, versus doing a joint ownership?

What metal is most suitable for a ladder submerged in an underground water tank?

Developers demotivated due to working on same project for more than 2 years

I recently started my machine learning PhD and I have absolutely no idea what I'm doing

How to rename multiple files in a directory at the same time

How do I know which cipher suites can be disabled?

Why did Varys remove his rings?

Were any of the books mentioned in this scene from the movie Hackers real?

Slice a list based on an index and items behind it in python

Why did the UK remove the 'European Union' from its passport?

Does addError() work outside of triggers?

My bread in my bread maker rises and then falls down just after cooking starts

Single word that parallels "Recent" when discussing the near future

Will consteval functions allow template parameters dependent on function arguments?

Could there be something like aerobatic smoke trails in the vacuum of space?

Why when I add jam to my tea it stops producing thin "membrane" on top?

Meaning of "legitimate" in Carl Jung's quote "Neurosis is always a substitute for legitimate suffering."

What do the "optional" resistor and capacitor do in this circuit?

How does Ctrl+c and Ctrl+v work?

Why does SSL Labs now consider CBC suites weak?

Capital gains on stocks sold to take initial investment off the table



Write buffer to command and append stdout back to same buffer


How to execute selected lines in bash and print the output in the next line?External command on unsaved bufferhow to perform multiple grep passes by using piping in external shell?Vimfiler (a plugin): how to open .doc file using MS WordHow can I write a range to a command, and then read the resulting output?Why does vim add ^J to the end of my macros?Text manipulation by calling external binaries or scriptsHow to get line numbers of selected textDiffsplit with output of external command in Vim?Execute selection and redirect output to new buffer/tabPass character-wise visual selection to an external command













3















I've opened an empty buffer with just vim.



I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.



In my empty buffer, I wrote the following.



select * from foo;


I want to pass the entire contents of the file over to my script, exec-sql.sh, then append the stdout of the shell script back into my buffer.



I tried this first.



% !exec-sql.sh


This replaced the contents of my buffer with the result of the SQL query. Not what I want.



Next, I tried this.



w !exec-sql.sh


This didn't replace the SQL query in by buffer, but it also didn't append the result of the query to my buffer. This also isn't what I want.



I want both the query and the result to end up in my buffer like this.



select * from foo;
id
---
1
2


Is there a way to do this in vanilla Vim?



Update:
I'd also like to just select a range to pass to exec-sql.sh, maybe by selecting some SQL statements in visual mode and piping just those statements.



:'<,'> !exec-sql.sh


I'd like to keep the selected lines, while also appending the result of executing the SQL commands right below the selected lines.



exec-sql.sh doesn't read files. You must pipe data to it. In the regular shell I have to do this: cat my.sql | exec-sql.sh.



I know how to do a regular read from an external command. But I want to do a write first, then a read. Write to the external command's stdin and then read from the external command's stdout.










share|improve this question




























    3















    I've opened an empty buffer with just vim.



    I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.



    In my empty buffer, I wrote the following.



    select * from foo;


    I want to pass the entire contents of the file over to my script, exec-sql.sh, then append the stdout of the shell script back into my buffer.



    I tried this first.



    % !exec-sql.sh


    This replaced the contents of my buffer with the result of the SQL query. Not what I want.



    Next, I tried this.



    w !exec-sql.sh


    This didn't replace the SQL query in by buffer, but it also didn't append the result of the query to my buffer. This also isn't what I want.



    I want both the query and the result to end up in my buffer like this.



    select * from foo;
    id
    ---
    1
    2


    Is there a way to do this in vanilla Vim?



    Update:
    I'd also like to just select a range to pass to exec-sql.sh, maybe by selecting some SQL statements in visual mode and piping just those statements.



    :'<,'> !exec-sql.sh


    I'd like to keep the selected lines, while also appending the result of executing the SQL commands right below the selected lines.



    exec-sql.sh doesn't read files. You must pipe data to it. In the regular shell I have to do this: cat my.sql | exec-sql.sh.



    I know how to do a regular read from an external command. But I want to do a write first, then a read. Write to the external command's stdin and then read from the external command's stdout.










    share|improve this question


























      3












      3








      3








      I've opened an empty buffer with just vim.



      I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.



      In my empty buffer, I wrote the following.



      select * from foo;


      I want to pass the entire contents of the file over to my script, exec-sql.sh, then append the stdout of the shell script back into my buffer.



      I tried this first.



      % !exec-sql.sh


      This replaced the contents of my buffer with the result of the SQL query. Not what I want.



      Next, I tried this.



      w !exec-sql.sh


      This didn't replace the SQL query in by buffer, but it also didn't append the result of the query to my buffer. This also isn't what I want.



      I want both the query and the result to end up in my buffer like this.



      select * from foo;
      id
      ---
      1
      2


      Is there a way to do this in vanilla Vim?



      Update:
      I'd also like to just select a range to pass to exec-sql.sh, maybe by selecting some SQL statements in visual mode and piping just those statements.



      :'<,'> !exec-sql.sh


      I'd like to keep the selected lines, while also appending the result of executing the SQL commands right below the selected lines.



      exec-sql.sh doesn't read files. You must pipe data to it. In the regular shell I have to do this: cat my.sql | exec-sql.sh.



      I know how to do a regular read from an external command. But I want to do a write first, then a read. Write to the external command's stdin and then read from the external command's stdout.










      share|improve this question
















      I've opened an empty buffer with just vim.



      I have a shell script in the same directory that I can pipe SQL to. That script will print the result of the execution to stdout.



      In my empty buffer, I wrote the following.



      select * from foo;


      I want to pass the entire contents of the file over to my script, exec-sql.sh, then append the stdout of the shell script back into my buffer.



      I tried this first.



      % !exec-sql.sh


      This replaced the contents of my buffer with the result of the SQL query. Not what I want.



      Next, I tried this.



      w !exec-sql.sh


      This didn't replace the SQL query in by buffer, but it also didn't append the result of the query to my buffer. This also isn't what I want.



      I want both the query and the result to end up in my buffer like this.



      select * from foo;
      id
      ---
      1
      2


      Is there a way to do this in vanilla Vim?



      Update:
      I'd also like to just select a range to pass to exec-sql.sh, maybe by selecting some SQL statements in visual mode and piping just those statements.



      :'<,'> !exec-sql.sh


      I'd like to keep the selected lines, while also appending the result of executing the SQL commands right below the selected lines.



      exec-sql.sh doesn't read files. You must pipe data to it. In the regular shell I have to do this: cat my.sql | exec-sql.sh.



      I know how to do a regular read from an external command. But I want to do a write first, then a read. Write to the external command's stdin and then read from the external command's stdout.







      external-command shell






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 4 at 17:59







      425nesp

















      asked May 4 at 6:14









      425nesp425nesp

      1234




      1234




















          3 Answers
          3






          active

          oldest

          votes


















          2














          Two methods you tried:




          • % !exec-sql.sh
            :h :range! filter range lines through the external program. also check :h ! .


          • w !exec-sql.sh
            :h :w_c execute cmd with [range] lines as standard input.

            Beware that w ! and w! have total different meaning.

          If you want to read external command output:



           :read !exec-sql.sh


          :h :read! execute cmd and insert its standard output below the cursor or the specified line.



          If you want to pass file name to external command, add % to the end, it will be replaced with current filename.



          :read !exec-sql.sh %


          Note that external command knows nothing about vim buffer, you need to save it before you execute above command.



          If you want to use buffer content as input for external command and add the output to the end of the buffe ( doesn't work well on vim8, see update ):



          :$put =execute('%w !exec-sql.sh')


          % is default range of :w, Replace it with whatever rang you like. check :h :put



          At last you can create a map to send selected lines to external command and add the output to the end of the buffer.



          vnoremap <leader>ex :<c-u>$put =execute('''<,''>w !exec-sql.sh')<cr>


          also check wiki



          update



          :h :put Put the text [from register x] after [line], :h '> marks the end of your selection, to output after selected lines:



          vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>


          There are always 2 leading blank lines in the output, if that bothers you, use
          :h '[ to move to there, and change it:



          vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>'[cj--------<esc>



          update



          Just tested this on vim8.1, include patches 1-1142, execute() doesn't read output form :w ! style command, redir doesn't work neither. Not sure if it's a bug.






          share|improve this answer

























          • Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

            – 425nesp
            May 5 at 4:16












          • Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

            – dedowsdi
            May 5 at 5:04


















          0














          Based on my answer to a similar question:



          nnoremap _X :put ="---n" . system('exec-sql.sh', getline('.'))<cr>
          vnoremap _X :<C-U>'>put ="---n" . system('exec-sql.sh', getline('''<','''>'))<cr>



          The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")) and uses it as stdin for the execution of exec-sql.sh. The resulting output is put below the current line with a divider ---.



          The visual mode mapping works similar, but getline('''<', '''>') fetches the list of selected lines and feeds it to exec-sql.sh.






          share|improve this answer






























            0














            One way to cheat is to duplicate the line I want to execute and replace the duplicate with the output.



            My file starts off like this.



            // notes.txt
            select * from foo;
            select * from foo;


            Then, I highlight the second select statement in visual mode and do this.



            :'<,'> !exec-sql.sh


            Which leaves me with this.



            // notes.txt
            select * from foo;
            id
            ---
            1
            2


            Which is exactly what I want.






            share|improve this answer























            • Consider @Ralf's answer, it works on both vim8 and neovim.

              – dedowsdi
              May 5 at 5:18












            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "599"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19836%2fwrite-buffer-to-command-and-append-stdout-back-to-same-buffer%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            Two methods you tried:




            • % !exec-sql.sh
              :h :range! filter range lines through the external program. also check :h ! .


            • w !exec-sql.sh
              :h :w_c execute cmd with [range] lines as standard input.

              Beware that w ! and w! have total different meaning.

            If you want to read external command output:



             :read !exec-sql.sh


            :h :read! execute cmd and insert its standard output below the cursor or the specified line.



            If you want to pass file name to external command, add % to the end, it will be replaced with current filename.



            :read !exec-sql.sh %


            Note that external command knows nothing about vim buffer, you need to save it before you execute above command.



            If you want to use buffer content as input for external command and add the output to the end of the buffe ( doesn't work well on vim8, see update ):



            :$put =execute('%w !exec-sql.sh')


            % is default range of :w, Replace it with whatever rang you like. check :h :put



            At last you can create a map to send selected lines to external command and add the output to the end of the buffer.



            vnoremap <leader>ex :<c-u>$put =execute('''<,''>w !exec-sql.sh')<cr>


            also check wiki



            update



            :h :put Put the text [from register x] after [line], :h '> marks the end of your selection, to output after selected lines:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>


            There are always 2 leading blank lines in the output, if that bothers you, use
            :h '[ to move to there, and change it:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>'[cj--------<esc>



            update



            Just tested this on vim8.1, include patches 1-1142, execute() doesn't read output form :w ! style command, redir doesn't work neither. Not sure if it's a bug.






            share|improve this answer

























            • Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

              – 425nesp
              May 5 at 4:16












            • Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

              – dedowsdi
              May 5 at 5:04















            2














            Two methods you tried:




            • % !exec-sql.sh
              :h :range! filter range lines through the external program. also check :h ! .


            • w !exec-sql.sh
              :h :w_c execute cmd with [range] lines as standard input.

              Beware that w ! and w! have total different meaning.

            If you want to read external command output:



             :read !exec-sql.sh


            :h :read! execute cmd and insert its standard output below the cursor or the specified line.



            If you want to pass file name to external command, add % to the end, it will be replaced with current filename.



            :read !exec-sql.sh %


            Note that external command knows nothing about vim buffer, you need to save it before you execute above command.



            If you want to use buffer content as input for external command and add the output to the end of the buffe ( doesn't work well on vim8, see update ):



            :$put =execute('%w !exec-sql.sh')


            % is default range of :w, Replace it with whatever rang you like. check :h :put



            At last you can create a map to send selected lines to external command and add the output to the end of the buffer.



            vnoremap <leader>ex :<c-u>$put =execute('''<,''>w !exec-sql.sh')<cr>


            also check wiki



            update



            :h :put Put the text [from register x] after [line], :h '> marks the end of your selection, to output after selected lines:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>


            There are always 2 leading blank lines in the output, if that bothers you, use
            :h '[ to move to there, and change it:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>'[cj--------<esc>



            update



            Just tested this on vim8.1, include patches 1-1142, execute() doesn't read output form :w ! style command, redir doesn't work neither. Not sure if it's a bug.






            share|improve this answer

























            • Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

              – 425nesp
              May 5 at 4:16












            • Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

              – dedowsdi
              May 5 at 5:04













            2












            2








            2







            Two methods you tried:




            • % !exec-sql.sh
              :h :range! filter range lines through the external program. also check :h ! .


            • w !exec-sql.sh
              :h :w_c execute cmd with [range] lines as standard input.

              Beware that w ! and w! have total different meaning.

            If you want to read external command output:



             :read !exec-sql.sh


            :h :read! execute cmd and insert its standard output below the cursor or the specified line.



            If you want to pass file name to external command, add % to the end, it will be replaced with current filename.



            :read !exec-sql.sh %


            Note that external command knows nothing about vim buffer, you need to save it before you execute above command.



            If you want to use buffer content as input for external command and add the output to the end of the buffe ( doesn't work well on vim8, see update ):



            :$put =execute('%w !exec-sql.sh')


            % is default range of :w, Replace it with whatever rang you like. check :h :put



            At last you can create a map to send selected lines to external command and add the output to the end of the buffer.



            vnoremap <leader>ex :<c-u>$put =execute('''<,''>w !exec-sql.sh')<cr>


            also check wiki



            update



            :h :put Put the text [from register x] after [line], :h '> marks the end of your selection, to output after selected lines:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>


            There are always 2 leading blank lines in the output, if that bothers you, use
            :h '[ to move to there, and change it:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>'[cj--------<esc>



            update



            Just tested this on vim8.1, include patches 1-1142, execute() doesn't read output form :w ! style command, redir doesn't work neither. Not sure if it's a bug.






            share|improve this answer















            Two methods you tried:




            • % !exec-sql.sh
              :h :range! filter range lines through the external program. also check :h ! .


            • w !exec-sql.sh
              :h :w_c execute cmd with [range] lines as standard input.

              Beware that w ! and w! have total different meaning.

            If you want to read external command output:



             :read !exec-sql.sh


            :h :read! execute cmd and insert its standard output below the cursor or the specified line.



            If you want to pass file name to external command, add % to the end, it will be replaced with current filename.



            :read !exec-sql.sh %


            Note that external command knows nothing about vim buffer, you need to save it before you execute above command.



            If you want to use buffer content as input for external command and add the output to the end of the buffe ( doesn't work well on vim8, see update ):



            :$put =execute('%w !exec-sql.sh')


            % is default range of :w, Replace it with whatever rang you like. check :h :put



            At last you can create a map to send selected lines to external command and add the output to the end of the buffer.



            vnoremap <leader>ex :<c-u>$put =execute('''<,''>w !exec-sql.sh')<cr>


            also check wiki



            update



            :h :put Put the text [from register x] after [line], :h '> marks the end of your selection, to output after selected lines:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>


            There are always 2 leading blank lines in the output, if that bothers you, use
            :h '[ to move to there, and change it:



            vnoremap <leader>ex :<c-u>'>put =execute('''<,''>w !exec-sql.sh')<cr>'[cj--------<esc>



            update



            Just tested this on vim8.1, include patches 1-1142, execute() doesn't read output form :w ! style command, redir doesn't work neither. Not sure if it's a bug.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited May 5 at 5:17

























            answered May 4 at 7:42









            dedowsdidedowsdi

            1,03749




            1,03749












            • Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

              – 425nesp
              May 5 at 4:16












            • Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

              – dedowsdi
              May 5 at 5:04

















            • Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

              – 425nesp
              May 5 at 4:16












            • Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

              – dedowsdi
              May 5 at 5:04
















            Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

            – 425nesp
            May 5 at 4:16






            Huh. So this doesn't work for me. I see the output flash, but it doesn't make it into my buffer... :/ If it's relevant, exec-sql.sh is actually a Makefile that runs sudo docker exec --interactive, but I don't pass the --tty flag, so that's why this works with plain ol' !make exec-sql. And I'm on Vim 8.1.

            – 425nesp
            May 5 at 4:16














            Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

            – dedowsdi
            May 5 at 5:04





            Yes, it doesn't work on vim8.1 include patches 1-1142. Not sure if it's a bug.

            – dedowsdi
            May 5 at 5:04











            0














            Based on my answer to a similar question:



            nnoremap _X :put ="---n" . system('exec-sql.sh', getline('.'))<cr>
            vnoremap _X :<C-U>'>put ="---n" . system('exec-sql.sh', getline('''<','''>'))<cr>



            The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")) and uses it as stdin for the execution of exec-sql.sh. The resulting output is put below the current line with a divider ---.



            The visual mode mapping works similar, but getline('''<', '''>') fetches the list of selected lines and feeds it to exec-sql.sh.






            share|improve this answer



























              0














              Based on my answer to a similar question:



              nnoremap _X :put ="---n" . system('exec-sql.sh', getline('.'))<cr>
              vnoremap _X :<C-U>'>put ="---n" . system('exec-sql.sh', getline('''<','''>'))<cr>



              The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")) and uses it as stdin for the execution of exec-sql.sh. The resulting output is put below the current line with a divider ---.



              The visual mode mapping works similar, but getline('''<', '''>') fetches the list of selected lines and feeds it to exec-sql.sh.






              share|improve this answer

























                0












                0








                0







                Based on my answer to a similar question:



                nnoremap _X :put ="---n" . system('exec-sql.sh', getline('.'))<cr>
                vnoremap _X :<C-U>'>put ="---n" . system('exec-sql.sh', getline('''<','''>'))<cr>



                The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")) and uses it as stdin for the execution of exec-sql.sh. The resulting output is put below the current line with a divider ---.



                The visual mode mapping works similar, but getline('''<', '''>') fetches the list of selected lines and feeds it to exec-sql.sh.






                share|improve this answer













                Based on my answer to a similar question:



                nnoremap _X :put ="---n" . system('exec-sql.sh', getline('.'))<cr>
                vnoremap _X :<C-U>'>put ="---n" . system('exec-sql.sh', getline('''<','''>'))<cr>



                The first mapping is to execute a single line. Just put the cursor in the line and hit _X. This takes the current line (getline(".")) and uses it as stdin for the execution of exec-sql.sh. The resulting output is put below the current line with a divider ---.



                The visual mode mapping works similar, but getline('''<', '''>') fetches the list of selected lines and feeds it to exec-sql.sh.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered May 4 at 11:03









                RalfRalf

                3,9851319




                3,9851319





















                    0














                    One way to cheat is to duplicate the line I want to execute and replace the duplicate with the output.



                    My file starts off like this.



                    // notes.txt
                    select * from foo;
                    select * from foo;


                    Then, I highlight the second select statement in visual mode and do this.



                    :'<,'> !exec-sql.sh


                    Which leaves me with this.



                    // notes.txt
                    select * from foo;
                    id
                    ---
                    1
                    2


                    Which is exactly what I want.






                    share|improve this answer























                    • Consider @Ralf's answer, it works on both vim8 and neovim.

                      – dedowsdi
                      May 5 at 5:18
















                    0














                    One way to cheat is to duplicate the line I want to execute and replace the duplicate with the output.



                    My file starts off like this.



                    // notes.txt
                    select * from foo;
                    select * from foo;


                    Then, I highlight the second select statement in visual mode and do this.



                    :'<,'> !exec-sql.sh


                    Which leaves me with this.



                    // notes.txt
                    select * from foo;
                    id
                    ---
                    1
                    2


                    Which is exactly what I want.






                    share|improve this answer























                    • Consider @Ralf's answer, it works on both vim8 and neovim.

                      – dedowsdi
                      May 5 at 5:18














                    0












                    0








                    0







                    One way to cheat is to duplicate the line I want to execute and replace the duplicate with the output.



                    My file starts off like this.



                    // notes.txt
                    select * from foo;
                    select * from foo;


                    Then, I highlight the second select statement in visual mode and do this.



                    :'<,'> !exec-sql.sh


                    Which leaves me with this.



                    // notes.txt
                    select * from foo;
                    id
                    ---
                    1
                    2


                    Which is exactly what I want.






                    share|improve this answer













                    One way to cheat is to duplicate the line I want to execute and replace the duplicate with the output.



                    My file starts off like this.



                    // notes.txt
                    select * from foo;
                    select * from foo;


                    Then, I highlight the second select statement in visual mode and do this.



                    :'<,'> !exec-sql.sh


                    Which leaves me with this.



                    // notes.txt
                    select * from foo;
                    id
                    ---
                    1
                    2


                    Which is exactly what I want.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered May 5 at 4:25









                    425nesp425nesp

                    1234




                    1234












                    • Consider @Ralf's answer, it works on both vim8 and neovim.

                      – dedowsdi
                      May 5 at 5:18


















                    • Consider @Ralf's answer, it works on both vim8 and neovim.

                      – dedowsdi
                      May 5 at 5:18

















                    Consider @Ralf's answer, it works on both vim8 and neovim.

                    – dedowsdi
                    May 5 at 5:18






                    Consider @Ralf's answer, it works on both vim8 and neovim.

                    – dedowsdi
                    May 5 at 5:18


















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Vi and Vim Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fvi.stackexchange.com%2fquestions%2f19836%2fwrite-buffer-to-command-and-append-stdout-back-to-same-buffer%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Club Baloncesto Breogán Índice Historia | Pavillón | Nome | O Breogán na cultura popular | Xogadores | Adestradores | Presidentes | Palmarés | Historial | Líderes | Notas | Véxase tamén | Menú de navegacióncbbreogan.galCadroGuía oficial da ACB 2009-10, páxina 201Guía oficial ACB 1992, páxina 183. Editorial DB.É de 6.500 espectadores sentados axeitándose á última normativa"Estudiantes Junior, entre as mellores canteiras"o orixinalHemeroteca El Mundo Deportivo, 16 setembro de 1970, páxina 12Historia do BreogánAlfredo Pérez, o último canoneiroHistoria C.B. BreogánHemeroteca de El Mundo DeportivoJimmy Wright, norteamericano do Breogán deixará Lugo por ameazas de morteResultados de Breogán en 1986-87Resultados de Breogán en 1990-91Ficha de Velimir Perasović en acb.comResultados de Breogán en 1994-95Breogán arrasa al Barça. "El Mundo Deportivo", 27 de setembro de 1999, páxina 58CB Breogán - FC BarcelonaA FEB invita a participar nunha nova Liga EuropeaCharlie Bell na prensa estatalMáximos anotadores 2005Tempada 2005-06 : Tódolos Xogadores da Xornada""Non quero pensar nunha man negra, mais pregúntome que está a pasar""o orixinalRaúl López, orgulloso dos xogadores, presume da boa saúde económica do BreogánJulio González confirma que cesa como presidente del BreogánHomenaxe a Lisardo GómezA tempada do rexurdimento celesteEntrevista a Lisardo GómezEl COB dinamita el Pazo para forzar el quinto (69-73)Cafés Candelas, patrocinador del CB Breogán"Suso Lázare, novo presidente do Breogán"o orixinalCafés Candelas Breogán firma el mayor triunfo de la historiaEl Breogán realizará 17 homenajes por su cincuenta aniversario"O Breogán honra ao seu fundador e primeiro presidente"o orixinalMiguel Giao recibiu a homenaxe do PazoHomenaxe aos primeiros gladiadores celestesO home que nos amosa como ver o Breo co corazónTita Franco será homenaxeada polos #50anosdeBreoJulio Vila recibirá unha homenaxe in memoriam polos #50anosdeBreo"O Breogán homenaxeará aos seus aboados máis veteráns"Pechada ovación a «Capi» Sanmartín e Ricardo «Corazón de González»Homenaxe por décadas de informaciónPaco García volve ao Pazo con motivo do 50 aniversario"Resultados y clasificaciones""O Cafés Candelas Breogán, campión da Copa Princesa""O Cafés Candelas Breogán, equipo ACB"C.B. Breogán"Proxecto social"o orixinal"Centros asociados"o orixinalFicha en imdb.comMario Camus trata la recuperación del amor en 'La vieja música', su última película"Páxina web oficial""Club Baloncesto Breogán""C. B. Breogán S.A.D."eehttp://www.fegaba.com

                    Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

                    Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020