Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autosave buffer on :make in vim?

Tags:

vim

macvim

Is there any way to autosave the buffer before issuing :make? I use MacVim and make is bound to Command-B, which is very helpful but I cannot seem to figure out how to write the buffer before a make. I looked at all the autocmd events and nothing seemed to fit.

There's a QuickFixCmdPre which should be called before a make but can't seem to get it to work:

~/.vimrc

function! AutoSaveOnMake ()
    if &modified
        write
    endif
endfunction

autocmd QuickFixCmdPre *.c :call AutoSaveOnMake()  
like image 550
Chris Avatar asked Aug 22 '12 16:08

Chris


1 Answers

Vim has a built-in setting for that:

:set autowrite

Write the contents of the file, if it has been modified, on each :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!, :make, CTRL-] and CTRL-^ command; and when a :buffer, CTRL-O, CTRL-I, '{A-Z0-9}, or `{A-Z0-9} command takes one to another file.

like image 132
Ingo Karkat Avatar answered Sep 30 '22 01:09

Ingo Karkat