Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to silently run a bash command after a file save in vim?

Tags:

vim

Right now I'm using the following command to compile a coffeescript file each time I save:

au BufWritePost widget.coffee ! ./compile_widget.sh

However each time I save I'm asked the following:

Press ENTER or type command to continue

Is there any way I can save and not have to hit enter to continue?

like image 933
Gary Haran Avatar asked May 04 '12 15:05

Gary Haran


People also ask

What is Vim silent?

<silent> tells vim to show no message when this key sequence is used. <leader> means the key sequence starts with the character assigned to variable mapleader -- a backslash, if no let mapleader = statement has executed yet at the point nmap executes.

How do I run a Vim command in terminal?

You can run the shell commands from inside of Vim by just using :! before the command, : means you have to be in command mode. Just after being in command mode, the ! or bang operator will execute the command typed after it from the terminal(Linux/ macOS) or your default shell(Windows -> CMD/Powershell).


1 Answers

I'd suggest using something like syntastic.

To address the explicit question however, you would need to do

au BufWritePost widget.coffee silent !./compile_widget.sh | redraw

The prompt is triggered by the output from the command. The silent suppresses the prompt, but when you do that then Vim doesn't redraw the screen after the shell command so that you're able to see the output from the command. So, the | redraw forces Vim to redraw the screen.

This is discussed at :help :!

like image 144
jamessan Avatar answered Nov 16 '22 02:11

jamessan