How to disable jumping to warning location after compile in vim-latex? - vim

After compilation, vim-latex opens a quickfix buffer, lists errors and warnings, and jumps to the first error or warning in the list. How do I make it not jump for warnings? or better yet, for certain warnings?
If this is not possible, is there some shortcut for returning the cursor back to its position before the jump?
NOTE: Ignoring warnings via let g:TexIgnoredWarnings = ... is not adequate since I do want to see the warnings.

If you're compiling via Vim-Latex's \ll command as I do, then adding the following option in either your vimrc or the ftplugin tex.vim should solve your problem:
let g:Tex_GotoError=0
This will leave your cursor where it was, but still populate the QuickFix window with warnings and errors. The documentation (linked below) says that it defaults to on, so switching it off should accomplish what you want.
http://vim-latex.sourceforge.net/documentation/latex-suite.html#Tex_GotoError

I assume you are compiling LaTeX with the :make command. The help for that command gives a list detailing exactly what the command does, including:
If [!] is not given the first error is jumped to.
If you trigger your compilation with :make! or the abbreviation :mak! instead of :make, then the cursor will not jump.
vim also saves a list of places your cursor has been recently. You can jump back to your previous location with Ctrl-O, and then jump forward again with Ctrl-I Use :help jump-motions to see more about this feature.

Related

Jump to make errors in source files with vim similar to a mouse click in VS Code terminal

I'm trying to make the jump from VS Code to pure terminal+vim development and I'm missing one efficiency booster from VS Code I used often. When I make some project, and errors are present, the stdout shows the path to the source file with the error, along with the line:column number. In the VS Code terminal I could just left-click with a mouse on that and it would open the VS Code text editor (with the VIM emulator enabled of course), to that location. Is there any similar time saver in the terminal and/or vim? I.e. something that would enable me to go directly from make error to editing that location in vim rather than reading the error log, memorizing the path:line:column and opening that file manually?
For example, lets say I had the following line within the make output:
/home/myusername/someProject/src/foo.c:30:5: warning: implicit declaration of function 'bar'; did you mean 'barr'? [-Wimplicit-function-declaration]
30 | bar(26);
| ^~~~~~~~~~~~~
| barr
Is there any easy way to jump to /home/myusername/someProject/src/foo.c:30:5 without highlighting it with a mouse and copy/pasting it?
The closest thing I found on SO so far was this but I'm guessing the make output will catch errors that only occur after attempting to compile, whereas something in live time like Syntastic is only going to catch syntax errors. I haven't used Syntastic yet, but I'm guessing what they catch has some union of items, but it obviously would be to costly to continuously be compiling in the background to check for compile errors.
I also note the errors themselves, i.e. -Wimplicit-function-declaration are hyperlinks. Maybe there is some setting in make/cmake to generate links for the src files as well?
The user manual, a mandatory read if you are serious about using Vim, dedicates a whole section to compiling: :help 30.1.
In a nutshell…
You choose what Vim calls a "compiler" with the :help :compiler command:
:compiler gcc
It tells Vim:
what external command to execute for compiling your code,
how to interpret the eventual error output.
You execute the :help :make command:
:make %
It tells Vim:
to execute the external command defined above,
and to capture any output in case there are errors to report.
You use the :help quickfix feature to display, navigate, and interact with eventual errors:
:cwindow " opens the quickfix window if there are valid errors
:cn " jump to next error
etc.
FWIW, Vim has very strong roots in C and it shows all over the place. Since running make is the default behavior of the :make command and the default :help 'errorformat' already handles most common C compilers, doing:
:make
followed by:
:cw
in your current project should give you a taste of what to expect:
Real life considerations…
Setting the compiler manually for each file you edit is a PITA. It makes a lot more sense to spend a few minutes putting together an autocommand.
Vim comes with a large and growing collection of "compilers". Check out $VIMRUNTIME/compilers.
Vim provides the basics of the "edit, compile, run" cycle but the experience may not be polished enough out of the box. For example, you might want to open the quickfix list automatically when there are errors, etc. There are basically two ways to address this: using some third-party plugins and/or writing your stuff yourself. I tend to like the latter the most (see this and this for example) but the third-party plugin path is valid, too.

Import/Load list of compiler warnings/errors to highlight in buffers?

In vim you can start a build process using the :make command. Now I'd like to start the build process from outside of Vim (for example a nightly build) and load the compiler error/warning log, highlighting all the errors and warnings in the opened buffers.
Can Vim do this with built-in functionality or do I need a vimscript for that; and if so, which one?
You're looking for :cfile / :cgetfile:
:cf[ile][!] [errorfile] Read the error file and jump to the first error.
The file you're reading naturally must be in a format that can be parsed by the 'errorformat' option.
For Vimscript, there's also a setqflist() function.
Highlighting
Once the errors are properly parsed in the quickfix list, there are a couple of plugins that can highlight the locations, for example the cuteErrorMarker plugin.

Vim function hints for C

I'm trying to achieve something simple, usually called "function hints". For example, scintilla-based editors have it:
You type a name, and just get the prototype. There are a few problems with that in vim:
You have to rebuild the ctags to keep it up to date
You can't type C-X C-O after the (, you'll just get "Pattern not found"
You can't type C-X C-O in normal mode, the cursor will just jump around
You get the annoying preview window at the top
I've tried a few plugins; most of them mess things up even more [^1].Can anyone recommend a simple way to get just that ? A simple rectangle containing the function prototype and nothing more.
[^1] It's really mind-numbing how idiotic some of these plugins are. One plugin (I won't mention it) actually contained in the .vim file a list of functions from libc.
ctags for autocompletion is a mess. I suggest you try a compiler based plugin such as clang-complete or gcc-sense (haven't tried this one). Advantages are:
more accuracy as what they do is pretty much compiling
compile errors are marked on the fly over the source code
You have to rebuild the ctags to keep it up to date
you don't need to deal with ctags (they are still useful to jump around though)
You can't type C-X C-O after the (, you'll just get "Pattern not found"
what would you expect?
You can't type C-X C-O in normal mode, the cursor will just jump around
you can always remap that sequence if you think it's a frequent mistake (something like nnoremap <C-x><C-o> a<C-x><C-o>)
You get the annoying preview window at the top
You can disable this by removing preview fromcompleteopt option. see :help completeopt
I'm using the following setup:
clang-complete for completion
supertab to complete with tab key
ultisnips for function signature placeholders. (also works with snipmate)
and some vimrc settings:
set pumheight=10 " so the complete menu doesn't get too big
set completeopt=menu,longest " menu, menuone, longest and preview
let g:SuperTabDefaultCompletionType='context'
let g:clang_complete_auto=0 " I can start the autocompletion myself, thanks..
let g:clang_snippets=1 " use a snippet engine for placeholders
let g:clang_snippets_engine='ultisnips'
let g:clang_auto_select=2 " automatically select and insert the first match
Enjoy!
Try to use eclim (plugin for integration with Eclipse).
This solution is overheaded a lot but it works in all cases.

Jump to next error / code highlighted in red

When dealing with merge conflicts it is common that the >>>>>> and ====== inserted by DCVS are syntactically incorrect for the file I'm in and show up as highlighted in red. When dealing with merge conflicts it would be useful to have commands to jump to these error. When I type :cnext I just get the message "No Errors". These are Mercurial merge conflicts so I can't use Fugitive, but I generally prefer editing merge conflicts by hand anyway.
Is there a way to jump to the next syntax error in the file? I think these errors are dictated by the syntax highlighting file.
You can use :lopen to open window containing error/warning lines. After that, navigate to each of them.
The actual answer is that you can use :lnext to jump to the next error, or :lprev, or ]l and [l (those are lowercase Ls) if you have vim-unimpaired, which you do, because you shouldn't use Vim without it.
This will not actually jump to the next red/error highlighted text group, but will jump to whatever your syntax plugin dictates is an error (and populates the location list). It is impossible in Vim to jump to a specific highlighting group, because no one has bothered to figure out how yet.
The plugin SRDispHiGrp comes close, but if you couldn't tell from the name, is too convulted and confusing for human use.
I think you were on the right track with :cnext.
:cnext and :cprevious are Vim QuickFix commands; you can take advantage of them by using a code validation plugin that uses QuickFix mode, like pyflakes.vim for Python, and jslint.vim/jshint.vim for JavaScript.
This will result in syntax errors being marked with squiggly red underlines, as opposed to the solid red syntax error highlighting I believe you are seeing. You should then be able to use :cnext and :cprevious to skip to the next and previous marked errors.
:cn - next compiler message
:cp - previous
:cl - list
You can use ]s (backwards) or [s (forward) depending on which direction you want to go in finding the next error. You need to be in normal mode for this to work but this is just build in vim, no extensions needed.

vim :make automatically jumps to first file with error

When executing :make from vim, after make is complete it automatically jumps to a file with errors. Is there a way to avoid this
EDIT
This is usecase i want to achieve
I want :make to execute then quicklist to open but the current file which i am working on should not be switched to the one with errors
with default settings after :make execution quicklist opens and the current file also changes
From the docs:
7. If [!] is not given the first error is jumped to.
So, just invoke it as :make!.
You can run :make! | copen, which should place your cursor in the quickfix list instead of changing the current buffer. You can make this even easier by putting command Mymake make! | copen in your .vimrc, so you only have to run :Mymake to do this.
Note that when selecting errors from the quickfix list, they will scroll a buffer with the file already open rather than change the current window if possible, and you can open the files in new windows with <C-w> Enter.
It might not be the cleanest solution, but setting the errorformat to an empty string should do the trick, ie.
:set errorformat=""
That should keep it from matching the compiler error strings.

Resources