I would like to modify the behavior of one of my mapping but only when Vim is reading data which were piped to it by
The mapping closes/quits the current window/session depending on certain conditions. When Vim is reading data which were piped to it, I would like the mapping to execute
:cquit, so that it reports an error to the shell and the output of the shell command is not displayed in the terminal when I quit (or the rest of the pipeline is not processed).
$ vipe is a shell utility, included in the
moreutils package, whose man page contains this:
NAME vipe - edit pipe SYNOPSIS command1 | vipe | command2 DESCRIPTION vipe allows you to run your editor in the middle of a unix pipeline and edit the data that is being piped between programs. Your editor will have the full data being piped from command1 loaded into it, and when you save, that data will be piped into command2. ENVIRONMENT VARIABLES EDITOR Editor to use. VISUAL Also supported to determine what editor to use.
As an example, one could use it to count the number of files/directories in the current working directory with
$ ls and
$ wc -l, using Vim in the middle to interactively remove some entries:
$ ls | vipe | wc -l
But, I don't know how to detect that Vim has been invoked by
I tried to use the
StdinReadPost event like this:
augroup standard_input autocmd! autocmd StdinReadPre * nno cd :echo 'hello'<cr> autocmd StdinReadPost * nno cd :echo 'hello'<cr> augroup END
But it didn't work, when hitting
hello was not displayed.
The reason why it didn't worked is probably because Vim wasn't invoked with the
- argument, because this works:
$ ls | vim -
:h StdinReadPre and
:h StdinReadPost seems to confirm this:
*StdinReadPost* StdinReadPost After reading from the stdin into the buffer, before executing the modelines. Only used when the "-" argument was used when Vim was started |--|. *StdinReadPre* StdinReadPre Before reading from stdin into the buffer. Only used when the "-" argument was used when Vim was started |--|.
I also tried to check the contents of the internal variables
v:progpath but they both report
Is there a way to detect whether Vim has been invoked by another shell command (
git commit, ...)?