Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable "Type :quit<Enter> to exit Vim" message when pressing Ctrl+C

Tags:

vim

I'm developing a Vim plugin That needs to run a shell command(targeted for running compilers and build systems) and capture it's output. I also want to display the command's stdout and stderr as it runs, so I'm using Ruby for running the command(though I'm still displaying with Vim's :echo command, so I can set the highlight for stderr)

Anyways, I want to allow the user to cancel the command in the middle. Canceling a program is traditionally done with Ctrl+C, and Vim's allows the user to use Ctrl+C to cancel the current running vimscript by throwing Vim:Interrupt. I want to use Vim's :sleep command to allow the user to press Ctrl+C if they want to cancel the command they are running, catch Vim:Interrupt, and proceed accordingly.

My problem is that pressing Ctrl+C in Vim while not in insert mode causes Vim to display Type :quit<Enter> to exit Vim - and to erase whatever messages were echoed before. This is a problem for me, because I want to keep whatever output the command put in stdout and stderr before the user canceled it displayed(and maybe add a message that the command was canceled).

Is there any way to temporarily disable this message and keep whatever was echoed before the user pressed Ctrl+C?

like image 261
Idan Arye Avatar asked Oct 29 '25 04:10

Idan Arye


1 Answers

You can prepend the left hand side of your mappings with <silent> to hide what they would normally output on the command line.

In this case, the following mapping should work (it seems to, here):

nnoremap <C-c> <silent> <C-c>
like image 118
romainl Avatar answered Oct 31 '25 01:10

romainl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!