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?

  • 1
    Not sure what the clicking issue is about, but consider using :terminal % instead
    – D. Ben Knoble
    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
    Jan 5 at 20:55
  • Does balki's suggestion work for you @pepperdreamteam ?
    – gildux
    Feb 6 at 0:39
  • @gildux not quite Feb 13 at 22:57

2 Answers 2


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.

  • with all due respect, this information is completely unrelated to the question. there is nothing wrong with the question 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. Dec 30, 2022 at 13:47
  • These suggestions only work for stdout. Terminal mode seems to be the only way so far Dec 31, 2022 at 23:05
  • It works for gVim and Vim, Terminal and stand-alone version. Jan 3 at 7:56
  • Yes, not for neovim. This was a Neovim question Jan 5 at 19:23

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

:read! ls


: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 that you have read and understand our privacy policy and code of conduct.

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