0

I like to execute my scripts in the shell using

:! %

But once I do, I can't select the text from the shell in the output. I'm currently using neovim. When I click into the shell to select the text, I exit the shell. How can I get around this?

4
  • 1
    Not sure what the clicking issue is about, but consider using :terminal % instead
    – D. Ben Knoble
    Commented Dec 12, 2022 at 14:29
  • 2
    May be use r! % to load the op in buffer, do what you want with it and then press u to undo
    – balki
    Commented Jan 5, 2023 at 20:55
  • Does balki's suggestion work for you @pepperdreamteam ?
    – gildux
    Commented Feb 6, 2023 at 0:39
  • @gildux not quite Commented Feb 13, 2023 at 22:57

2 Answers 2

0

The % in ! % is a shortcut for the name of your current file, not the contents of the file.

If I name a file ls and open it in vim and run ! % the output of the ls command will be shown.

5
  • with all due respect, this information is completely unrelated to the question. there is nothing wrong with the question Commented Dec 16, 2022 at 16:51
  • 1
    I was just clarifying how you used the ! %. There are a couple ways to do this: 1. You can pipe the output of the command through xclip to copy it, and then simply paste it into a new vim buffer. 2. Another solution is to pipe the output of the command to vim with [command] | vim - to do some work there before copying/saving the output och parts of the output. 3. :%![command] to run the current file through the command and view the output in current buffer. Commented Dec 30, 2022 at 13:47
  • These suggestions only work for stdout. Terminal mode seems to be the only way so far Commented Dec 31, 2022 at 23:05
  • It works for gVim and Vim, Terminal and stand-alone version. Commented Jan 3, 2023 at 7:56
  • Yes, not for neovim. This was a Neovim question Commented Jan 5, 2023 at 19:23
0

Usually for this kind of stuff I use the vim function read

:read! ls

or

:read! date

It will print the output/results inside the current buffer

If the shell interaction needs a but more interaction, I do things in the shell, pipe to files, and use command line tool xclip for moving around the intersting stuffs from places to places as well inside as oustide vim

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.