Cyrille
Cyrille

Reputation: 25144

Vim — running external command bound to F5 inserts result in source

I'm currently developing a webapp that need a "compilation" phase to be tested. For this, I have a simple shell script, which is designed to run from a precise directory.

So in Vim, when I enter command mode and issue this, it works:

:lcd /my/script/directory
:!./build debug

My build script writes some logs in the command window, everything is fine, and tells me to press return to go back editing my stuff. Fine.

Now I'd like to bind this to F5 to speed things up. In my ~/.vimrc, I have added this:

map <F5> :lcd /my/script/directory<CR>! ./build debug<CR>

But after source'ing my ~/.vimrc, when I press F5, my script runs correctly... but strangely Vim replaces the current line I'm on with the output of the script. The same if I do map <silent> <F5> …

If i change ./build debug with a simple ls, the problem arises too. The output of the ls is inserted in my current document, overwriting the current line.

Does anybody know where the problem comes from? I really need to see the output of my build script, so there's no way I could just add a "undo" command after my bind, that would simply erase the inserted output of my command.

FWIW, I'm running MacVim snapshot 63 on OSX 10.7.2, but it also occurs when I use the plain old command-line vim (v7.3) from iTerm2 (1.0.0.20111020).

Upvotes: 1

Views: 1241

Answers (2)

Birei
Birei

Reputation: 36282

Use a colon before !, like:

map <F5> :lcd /my/script/directory<CR>:! ./build debug<CR>

Upvotes: 0

romainl
romainl

Reputation: 196886

Try

map <silent> <F5> :lcd /my/script/directory \| !./build debug<CR>

The escaped pipe is here to chain commands.

Upvotes: 4

Related Questions