How to efficiently “make” with Vim

后端 未结 6 402
栀梦
栀梦 2020-12-06 05:07

What I am trying to do seems a very basic stuff, but I can\'t find anything about it. I am working on a project built as usual:

project
|-- bin
|-- inc
`-- s         


        
6条回答
  •  既然无缘
    2020-12-06 05:27

    Another approach can be used if you have a single makefile on project root directory:

    project
    |-- bin
    |-- inc
    |-- src
    | Makefile
    

    With your project path in variable like b:projectDir it is possible to use an "autocommand" to change to that directory before start executing :makeor :lmake:

    augroup changeMakeDir
        au!
        autocmd QuickfixCmdPre *make
                    \ if exists("b:projectDir") &&
                                        \ b:projectDir != expand("%:p:h") |
                        \ exe 'cd ' . b:projectDir |
                    \ endif
    augroup END
    

    Projectroot plugin can be used to set b:projectDir; it also provides the commands to change the current directory to the project root directory:

    augroup changeMakeDir
        au!
        autocmd QuickfixCmdPre make ProjectRootCD
    augroup END
    

提交回复
热议问题