简体   繁体   English

将makeprg设置为VIM功能?

[英]Set makeprg to VIM function?

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. 我正在使用VIM处理Visual Studio解决方案,我编写了一个函数,从当前文件向上搜索文件系统并找到第一个* .sln文件。

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 " . 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. 这样,我可以使用我当前设置的键绑定:make来构建解决方案文件。

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: 因为每当我进入C#或VB.net缓冲区时我都会加载编译器设置,我只是这样做:

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. 这给了我想要的效果,但是从技术上讲它并没有将makeprg设置为一个函数,该函数将在以下情况下进行评估:make被调用,就像最初请求的那样。

You can define a mapping/function/command/whatver that: 您可以定义映射/函数/命令/ whatver:

  • ensure that your makeprg is correctly set 确保正确设置makeprg
  • execute :make 执行:make
  • execute a :copen if there was an error. 如果出现错误,执行a:copen。

Personally, I'd rather have makeprg set when I edit a file from a directory ( that I associate to a project ). 就个人而言,当我从一个目录( 我与一个项目关联 )编辑一个文件时,我宁愿设置makeprg。 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. 每次更改其中一个方面时,我都会更新makeprg。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM