vim :make automatically jumps to first file with error - vim

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.

Related

vim does not go back to the same file when exit from external command

I'm trying to compile my tex file inside vim. I have a Makefile to do the compilation, and I just type :make to call it. Usually it works well, but sometimes vim does not go back to the .tex file where I called make. Instead, I find I'm in a .cls file after pressing "ENTER or type command to continue".
I wonder what's happening? And how to make it work as I expected -- going back to the original file? Thanks.
Looks like Vim found some errors in your code and tries to be helpful by jumping to the related file and line. According to :help make you should be able to avoid that by using :make! (notice the exclamation mark) instead:
If [!] is not given the first error is jumped to.
You can also call :make and let it open the file with the first error, then jump back to the original file by typing Ctrlo.
There is another question that might be related: How do I disable the "Press ENTER or type command to continue" prompt in Vim?
I am using this configuration:
map <F10> :w<CR>:!make<CR><CR>
Pressing F10 key in normal mode saves me the tex file and calls make and returns to editing the file.

How to :bufdo only on modifiable buffers in vim?

Sometimes I need to substitute across multiple buffers. For the purpose I use :bufdo %s/old/new/gec. Recently I noticed that the command fails when there is non-modifiable buffer in the buffer list (in my case it's opened file explorer/netrw). After running the command vim leaves me with E21: Cannot make changes, 'modifiable' is off and opened Netrw window.
Are the ways to :bufdo only on modifiable buffers? I've already tried :bufdo!, but the behaviour was the same (just without showing the error).
UPDATE
I find the line of .vimrc that poses this problematic behaviour:
let g:netrw_liststyle=3
I don't know what the magic here, but when I set this option neither of the suggested solutions/commands work for me. Now, the question is how to keep this line and make the :bufdo behaviour skip the buffer created by Netrw.
Well, if :bufdo sil! :%s/old/new/gec does not work for you (this silently ignores errors). you need to wrap the command into an if statement. Something like this:
:bufdo if &ma | :%s/old/new/gec | endif
which checks for each buffer, if it is modifiable and only then attempts to replace old by new.
Note: You might also want to check for the 'readonly' option in addition to the 'modifiable' setting.

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

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.

Traversing directories with vim file name completion in insert mode (Ctrl-X Ctrl-F)

I’m trying to use vim’s compl-filename feature (Ctrl-XCtrl-F) to complete paths in INSERT mode, but I can’t work out how to traverse into directories without (temporarily) ending the completion mode:
Let’s say I want to complete the path /etc/sysconfig/network-scripts/ifup.
I would like to be able to do something like:
/eCtrl-XCtrl-F
/etc/
/etc/sysCtrl-F
/etc/sysconfig/
/etc/sysconfig/netCtrl-F
/etc/sysconfig/netconsoleCtrl-N
/etc/sysconfig/networkCtrl-N
/etc/sysconfig/network-scripts/
/etc/sysconfig/network-scripts/ifupCtrl-Y
/etc/sysconfig/network-scripts/ifup
The issue is, as soon as I start typing* after a path match (like /etc/), it ends file name completion. I would like it to stay in file name completion, so that I can still use Ctrl-F, Ctrl-N, etc. Since it ends completion, I have to type Ctrl-XCtrl-F again to restart it, and the helpful completion popup menu disappears in the meantime.
Is there an option I can set to change this?
* By ‘typing’ here, I am referring to characters in 'isfname' -- of course, typing other characters (like space or punctuation) should not continue file name completion.
I'm not sure exactly what you're saying, but you can just press Ctrl-XCtrl-F again on a directory while you're in the completion menu to expand it. You don't have to close out of the menu first. I just keep Ctrl held down and tap xf to traverse a directory, n and p to move up and down and w to go back up.
If you don't use :h i_CTRL-F then you could remap it. For example,
inoremap <C-f> <C-x><C-f>
Simple remap would be
inoremap / /<C-x><C-f>
So when you type slash(/) in insert mode you will get that auto completion popup :)
Place it in your .vimrc file (for vim) or in init.vim (for neovim)
Vim doesn't do auto-completion.
For that, you'll need a dedicated plugin like AutoComplPop or NeoComplCache
Please use insert "i" first before using cntr+x+f. I was in similar situation. :)

How do you use vim's quickfix feature?

I'm a pretty new Vim user and I've found that its learning curve is quite steep (at least for me). I just installed this vim script for JavaScriptLint error checking, which shows errors in vim's quickfix window once I save a buffer.
However, I don't know what to do next.. How do I 'scroll' through all the errors? How do I close the quickfix 'window'? How do I get it to check for errors after I've made changes to my code?
I've looked at the vim quickfix docs but the amount of commands are overwhelming and I can't seem to find what I want. Any help would be appreciated.
A side question: is there any way to have javascriptlint check for js errors for code residing in a .html file?
There are a lot of commands for quickfix as you have said, but I tend to find I only use a small subset of them:
:copen " Open the quickfix window
:ccl " Close it
:cw " Open it if there are "errors", close it otherwise (some people prefer this)
:cn " Go to the next error in the window
:cp " Go to the previous error in the window
:cnf " Go to the first error in the next file
:.cc " Go to error under cursor (if cursor is in quickfix window)
I tend to use this with :make and :vimgrep, so I can't comment on the Javascript lint checker, but this should give you something to get started.
Regarding the general use of JavascriptLint, I'm not a javascript programmer, but it looks like the script exposes a function called "JavascriptLint", so if you want to call it manually, you can use :call JavascriptLint(). However, it works on the disk copy of the file, so it'll have to be saved first. If (and only if) the command line jsl works on html files, you should be able to use :call JavascriptLint() on an html file to check the internal javascript. You could also do:
autocmd BufWritePost,FileWritePost *.html call JavascriptLint()
to automate it. If jsl doesn't support html files, then (short of patching the application or asking the author to change it), it's probably a lost cause...
The easiest way to navigate the quickfix list (or the location list, for that matter) is the unimpaired plugin.
Once the quickfix window is populated, [q and ]q go forward and back (respectively) in the quickfix list. [Q and ]Q go to the beginning and end (which is especially handy if you only have one item in the list; this makes vim complain about [q and ]q). So the workflow is:
Run whatever command populates the quickfix list
Type [Q to go to the first item
Scroll through subsequent items (if any) with [q and ]q
If you're using Syntastic, you'll get the location list instead of the quickfix list. No problem; just use [L, ]L, [l, and ]l in the same way.
unimpaired has loads of other handy mappings too -- [e and ]e "bubble" lines up and down, [<Space> and ]<Space> insert blank lines above and below, etc. I was surprised nobody mentioned it here before; that's probably because it didn't exist until January 2010, though the question was asked in 2009.
Put the following two lines in your .vimrc file:
map <C-j> :cn<CR>
map <C-k> :cp<CR>
Now you can navigate through the errors using ctrl-j and ctrl-k, which mimics the standard down and up motion commands j and k.
You can also use :cc 2 (or any other number) to jump to, in this case, the second error in the quickfix window. Navigating with :cn, :cc 4, etc will put the cursor on the line in question.
In addition to #DrAl's great answer about how to open and close the quick window and navigate between entries, I made an image to show some of the other quick fix navigation commands.
Each group of 3 files below represents a set of quickfix results, e.g. from a vimgrep. cnewer and colder are for going through historic result sets.
Maybe this option didn't exist when this question was written (or maybe I'm embarrassing myself because there's something in my .vimrc that makes this happen) but when I get a Quickfix List, I just navigate it with j and k then hit <CR> (i.e. the Enter key) to jump to that place in the file.
Then, to get back to the Quickfix List I type Ctrl+W j for "move down a window" and I'm back.
Finally, when I'm done, I just type :q, like I would to close any normal window.
The best-practice way of integrating JavaScript syntax-checking is using the Syntastic Vim plugin, which is using Vim's location-list (which is parallel to the quickfix) window.
I've written answers for this question and this question explaining how to do it, plus also how to get source-code browsing / tag-list for Vim using the community-driven jshint.com (which is way better than JSLint IMO) and Mozilla's DoctorJS (formerly jsctags).
the quickfix window is operated mostly like any other vim window: j down a line, k up a line, :cn to jump to the next error/warning, etc.
experiment!
Although this requires > Vim 7.4.858, the cdo (or ldo for location lists) command allows updating a non-contiguous set of lines in a way you could once only do with sed:
:vimgrep /re/ %:p
:cdo! norm #a
# or
:cdo! s/re/repl/
The above shows running a recorded macro or a simple search and replace. Missing seems to a be a way to pipe through and external command as you can with :range! command

Resources