Vim File Paths in the Shortcut Window

I made a function in Vim that compiles some things for me. It looks like this:

function! MyFunc(mode) lcd ./build pwd let &makeprg='the_command some_script_file' let &errorformat='some format'.',' let &errorformat.='%-G%.%#' silent make lcd .. cwindow endfunction 

I usually open vim in the project directory, then I can run this function, which cd in the assembly builds and back, so I stay in my project directory.

However, sometimes when the assembly fails and the quickfix window appears, it will show the file names relative to my dir (yay) project, but at another time in the same file it shows the absolute path. The result of the build script always shows the relative paths, and vim processes both correctly, that is, it finds the correct file.

I suspect that path processing is responding. My question is, what is the problem, and is there a better way to handle the transition to the assembly directory and vice versa? I always need relative paths.

Thanks!!

+8
vim
source share
2 answers

I think this is due to lcd . When the quickfix window opens from your function, it inherits the local directory from the current window. But when the quickfix window was opened from anywhere (or before your function started), it will support the global working directory. When there is a mismatch, Vim should display absolute paths.

If you really need to use :lcd , it would be better to use a list of locations ( :lmake ), because it will also be local to the window. But first, I will try to use the global :cd , since the switch is temporary, and still you do not need to restore the actual original value.

+3
source share

As Ingo pointed out, the paths refer to the current directory of the quickfix window that is inherited from the previous window.

You can use autocmd QuickFixCmdPre to set the correct path before doing make.

If you are using the Project Root plugin , add the following to your .vimrc :

 augroup changeQfCmdDir au! autocmd QuickFixCmdPre make ProjectRootCD augroup END 

then the path of the quick fix window will be fixed before it is filled with :make (you can also specify a number of other commands that use the quick access windows: grep,lgrep,cscope ).

0
source share

All Articles