vim change base of relative path to source to other dir - vim

I have a local Makefile which simply calls make -C ... As a result I get the output from the compiler with filenames and path to the directory relative to ...
Now vim isn't able to get the correct path for quickfix.
Q: How can I set the base path for vim quickfix to .. ?
My path structure:
<bla>/base/proj1/<localMakeFile>
<bla>/base/<globalMakefile>
<bla>/src/source1.cpp
I compile inside /base/proj1/
Compiler output for a error is like:
src/source1.cpp|141 col 54| Error: ....
But I am working in
/proj1/ so vim is unable to get the file src/source1.cpp
EDIT:
I see that the problem is basically related to the output of gnu make
make[4]: Entering directory '<bla>/...'
which is not parsed correctly if I use not an English environment. Setting the shell with export LANG= all works fine.
Q: Can vim parse also the German output of gnu make?

Appending the localized version with set errorformat+=<localized version> should work.
I am not aware that VIM supports it out of the box. After looking at the output of :set errorformat, which on my machine is a scary...
errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Ea
ch undeclared identifier is reported only once,%-G%f:%l: for ea
ch function it appears in.),%-GIn file included from %f:%l:%c:,
%-GIn file included from %f:%l:%c\,,%-GIn file included from %f
:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G
%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:
%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%
*\d]: Entering directory %*[`']%f',%X%*\a[%*\d]: Leaving direct
ory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leav
ing directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
...and by changing the output of the build process from
make: Entering directory `<directory>`
to
make: Entering `<directory>`
i got it to work by extending errorformat like this:
:set errorformat+=%D%*\\a:\ Entering\ %*[`']%f'

Related

Blank file after make in vim

When I run :make in vim, and if I have an error in my one and only cpp file (main.cpp) vim shows me the errors and when I press enter it opens a file named
^[[H^[[Jmain.cpp
instead of
main.cpp
And I have to manually reopen my file. Any idea how to tell vim to open the right file?
I'm running
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Apr 20 2016 11:17:28)
MacOS X (unix) version
Included patches: 1-1655 Compiled by Homebrew
Error output:
main.cpp:40:2: error: unknown type name 'obvious'
obvious error
^
main.cpp:40:15: error: expected ';' at end of declaration
obvious error
^
;
2 errors generated.
rm: main: No such file or directory
make: *** [all] Error 1
Press ENTER or type command to continue
vim errorformat (as reported by :echo &errorformat)
%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GIn file included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]:Entering directory %*[`']%f',
%X%*\a[%*\d]: Leaving directory %*[`']%f',%D%*\a: Entering directory %*[`']%f',%X%*\a: Leaving directory %*[`']%f',%DMaking %*\a in %f,%f|%l| %m
Makefile looked something like this:
all:
clear && g++ main.cpp -o main
And the clear seems to be throwing it off. Workaround is to remove the clear or add an echo after
all:
g++ main.cpp -o main
all2:
clear && echo "" && g++ main.cpp -o main

Override syntax highlighting in vim file

I am trying to override a markdown file syntax by placing the following file md.vim in my after/syntax directory. md.vim contains the following code:
syntax region mdNote start=/\<\cNOTE\>/ end=/\r/
highlight def link mdNote Todo
I have tested that the code works by sourcing it directly but when I launch a file with an extension .md, the mdNote syntax does not work. For example, given the following markdown file:
# Main Heading
Note: This is a note
If I put the cursor inside the word Note and get the syntax group, I get:
mkdNonListingItemBlock which comes from the plasticboy/markdown plugin that I have installed.
Does anyone know why my syntax file is not working?
Markdown files will reference the markdown.vim file in after/syntax. To get this information for any file, you can open a file of the desired format and run :set syntax?. Rename your file to markdown.vim and it should work.

how to expand directory with awk files

I have created a scriptdirectory
let $MYSCRIPTS = $VIM."/vimfiles/my_scripts-docs"
($VIM = C:\Program Files\Vim)
this works fine:
exe "e ".expand('$MYSCRIPTS/vim-calc_vb.txt')
This doesn't work and I can't find out why:
exe "!awk -f ".expand('$MYSCRIPTS/my-awk-script.awk')
exe "!awk -f ".expand('$MYSCRIPTS\my-awk-script.awk')
error:
awk: fatal: can't open source file 'C:/Program'
It works fine when I put the .awk file in the root but not when
I put it in a vim directory or whatever directory under C:\program files
Why does .txt files expand and .awk files not?
How can I let vim know where the awk file is under vimfiles?
Why do you need expand() and not just
fnameescape($MYSCRIPTS.'/vim-calc_vb.txt')
(for the exe "e") and
shellescape($MYSCRIPTS.'/my-awk-script.awk, 1)
(for !awk …)?
Based on your
awk: fatal: can't open source file 'C:/Program'
It works fine when I put the .awk file in the root but not when
I put it in a vim directory or whatever directory under C:\program files
I see that absence of shellescape() is the problem here, not expand(), but it does not make the former useful. It is useful for changing \ to / on windows. Just surround your expand() calls with fnameescape()/shellescape(…, 1):
" None is needed here: `:e` expands `$` on its own
e $MYSCRIPTS/vim-calc_vb.txt
exe "!awk -f ".shellescape(expand('$MYSCRIPTS\my-awk-script.awk'), 1)

Vim tries to jump to nonexistent file after :make

I'm using :make from vim and ending up jumping to the file with issues.
Recently, at least I noticed with gcc 4.6.1, vim jumps to incorrect file/line because it goes to the first reported line which has "In file included from ABC.h|5| 0," and there is no file called "In file included from ABC.h".
There is a solution to extract just the file name from the above line, ABC.h in this case, but that does not solve the problem as the problematic file is only included there.
Usually the next line indicates where the issue is and that's where I would like to jump:
MyDir/FGH.h|56 col 32| error: 'bad bad thing happened here'
Is there a known fix for this in vim?
This a bug that is solved on new versions of Vim: Bug report logs - #62169.
You can use the following setting to solve the problem without upgrading Vim:
set errorformat^=%-GIn\ file\ included\ from\ %f:%l:%c:,%-GIn\ file
\\ included\ from\ %f:%l:%c\\,,%-GIn\ file\ included\ from\ %f
\:%l:%c,%-GIn\ file\ included\ from\ %f:%l
(setting extracted from latest Vim source code, from file src/option.h)
:make! doesn't jump to the first result.
The problem is with slight differences in the errorformat required for recent versions of gcc.
I believe this was mentioned in C++ Lounge (chat) the other day, and an errorformat was posted that supposedly works better. I haven't tested that it does:
https://chat.stackoverflow.com/search?q=errorformat&room=10
errorformat=%*[^"]"%f"%*\D%l: %m,"%f"%*\D%l: %m,%-G%f:%l: (Each undeclared identifier is reported only once,%-G%f:%l: for each function it appears in.),%-GInfile included from %f:%l:%c:,%-GIn file included from %f:%l:%c\,,%-GIn file included from %f:%l:%c,%-GIn file included from %f:%l,%-G%*[ ]from %f:%l:%c,%-G%*[ ]from %f:%l:,%-G%*[ ]from %f:%l\,,%-G%*[ ]from %f:%l,%f:%l:%c:%m,%f(%l):%m,%f:%l:%m,"%f"\, line %l%*\D%c%*[^ ] %m,%D%*\a[%*\d]: Entering directory `%f',%X%*\a[%*\d]: Leaving directory `%f',%D%*\a: Entering directory `%f',%X%*\a: Leaving directory `%f',%DMaking %*\a in %f,%f|%l| %m

Vim problem with gf command

I am using Vim and I have set the path (set path+= c:/work/etc/etc) to my project directory (for C#), but still using command 'gf' give me error:
E:447 Can't find file.
Is there anything I am doing wrong over here?
G'day,
To get a bit more detail on your current path settings you can see what's being included and the files vim can't find by entering the command:
:checkpath
and you'll get a dump of the files not found, e.g.
--- Included files not found in path ---
<io.h>
vim.h -->
<functions.h>
<clib/exec_protos.h>
Or you can get a listing of all included files, both found and not found, by entering
:checkpath!
Enter
:help path
to get more info on the path syntax.
Edit: Don't forget that using the syntax
set path=/work
will completely reset your path variable to what you've just declared. I'd suggest using
set path+=/work
instead. This won't clobber the current path and will just add your /work directory instead.
HTH
I also found out that
:set path+=./foo/bar
adds a search location relative to the directory of the current file, just like '.' does.
My vim didn't want to search for such include
#include <common/util/string.h>
So what I needed to do was
:set path+=foo/bar
instead of
:set path+=./foo/bar
The former adds a search path relative to current working directory. Hopefully it helps someone.
First can you open the file using :find file.name ? (:help find for more info). If this does not work then your path is wrong. If :find does locate your file then do the following:
Insure that you are not in Visual/Insert mode
Place cursor on the first letter of the filename and press gf
I know this is an old question, but I also had some troubles with this for another reason and it took me some time to find out why. I hope this might be helpful to someone.
When a directory is matched with wildignore, gf does not work for files in it, nor does :find.
This is obvious if you read wildignore's documentation, but I forgot I ever changed this variable, and what it was for exactly. Also I used a glob, and it was not immediately apparent to me that the directory I was using gf in, was also matched with this glob.
Make sure there is no leading character to the file name if you press gf, i.e. using gf when the cursor is on help.txt will not work here:
file=help.txt
If you are talking about the gf tool wri††en by tomnomnom then here's how to set-up:
Setting PATH for GO (if you have not setup yet).
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
Step 1: Download tool from github
Step 2: cp -r path/to/tomnomnom/gf/examples ~/.gf
Step 3: source ~/tools/gf/gf-completion.bash
Now gf should work along with auto-completion from anywhere.
Source: Original sources are present at his repo.

Resources