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

                    Wikipedia:Vital articles Мазмуну Biography - Өмүр баян Philosophy and psychology - Философия жана психология Religion - Дин Social sciences - Коомдук илимдер Language and literature - Тил жана адабият Science - Илим Technology - Технология Arts and recreation - Искусство жана эс алуу History and geography - Тарых жана география Навигация менюсу

                    Bruxelas-Capital Índice Historia | Composición | Situación lingüística | Clima | Cidades irmandadas | Notas | Véxase tamén | Menú de navegacióneO uso das linguas en Bruxelas e a situación do neerlandés"Rexión de Bruxelas Capital"o orixinalSitio da rexiónPáxina de Bruselas no sitio da Oficina de Promoción Turística de Valonia e BruxelasMapa Interactivo da Rexión de Bruxelas-CapitaleeWorldCat332144929079854441105155190212ID28008674080552-90000 0001 0666 3698n94104302ID540940339365017018237

                    What should I write in an apology letter, since I have decided not to join a company after accepting an offer letterShould I keep looking after accepting a job offer?What should I do when I've been verbally told I would get an offer letter, but still haven't gotten one after 4 weeks?Do I accept an offer from a company that I am not likely to join?New job hasn't confirmed starting date and I want to give current employer as much notice as possibleHow should I address my manager in my resignation letter?HR delayed background verification, now jobless as resignedNo email communication after accepting a formal written offer. How should I phrase the call?What should I do if after receiving a verbal offer letter I am informed that my written job offer is put on hold due to some internal issues?Should I inform the current employer that I am about to resign within 1-2 weeks since I have signed the offer letter and waiting for visa?What company will do, if I send their offer letter to another company