开发者

Set makeprg to VIM function?

开发者 https://www.devze.com 2023-02-21 02:30 出处:网络
I\'m using VIM to work on Visual Studio solutions, and I have written a function that searches the filesystem upwards from the current file and locates the first *.sln file.

I'm using VIM to work on Visual Studio solutions, and I have written a function that searches the filesystem upwards from the current file and locates the first *.sln file.

What I want to do is something like this:

function! BuildSLN()
    " FindSLN is my function that locates the sln "
    let slnfile = FindSLN()
    if slnfile != ""
        execute "!devenv " .开发者_Python百科 slnfile . " /Build Debug"
    endif
endfunction

CompilerSet makeprg=:call BuildSLN()

This way, I could use my currently set keybindings for :make to build the solution file.

Is this possible?


I have found a solution, although not technically an answer to my own question :)

Since I am loading the compiler settings whenever I enter a C# or VB.net buffer, I am just going to do:

let &l:makeprg='"devenv.com "' . FindSLN() . '" /Build Debug"'

in the compiler settings file. This gives me the effect that I want, however it technically does not set the makeprg to a function that will be evaluated when :make is called, like originally requested.


You can define a mapping/function/command/whatver that:

  • ensure that your makeprg is correctly set
  • execute :make
  • execute a :copen if there was an error.

Personally, I'd rather have makeprg set when I edit a file from a directory (that I associate to a project). And a few mappings to toggle the compilation mode aspects (debug/release, background/or not, target (cross-compilation/or not), multithreaded compilation/or not, etc). Each time one of the aspects is changed, I update makeprg.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号