Using the quickfix window with vim+jslint - vim

I'm using the vim+jslint combo described here, and am having problems figuring out how to use the two together. I'm guessing that the list of errors is supposed to show on the top half and the second half has the actual page? If so, how do I go about doing this? (Caution, I am completely new to the quickfix window, and the documentation isn't exactly the best at describing how to use it).

The quickfix documentation in the user manual section of Vim's help is good. You have to remember, that Vim's help has both a user manual and a reference manual. The latter is more terse.
The general run down is, after running :make the quickfix list is populated with anything the 'errorformat' option has been configured to parse. You use the :cn and :cN commands to move forward/backward through the quickfix list, respectively.

In the end I hacked the jslint script to output in the format for the quickfix window. I replaced:
//print((e.evidence||'').replace(/^\s*(\S*(\s+\S+)*)\s*$/,"$1"));print('');
with
print(a[0]+':'+e.line+':'+e.reason)
I think

Related

Filter vim's quickfix window per file

I'm using the cquery language server in my Neovim instance. In conjunction with the Languageclient-neovim plugin. This automatically also checks the code for errors in the file that I'm working. However, this also means it checks all the files in my workspace.
I was wondering if there was a possibility to only show errors that are specific to the file that I am working in. See the example below:
I'm working in the file src/bag_rotation.cpp and I only want to filter the quickfix window to only show errors from that file.
yes, I wrote a vim plugin, can do ":Keep" and ":Reject" on quickfix window (among other things).
https://github.com/romainl/vim-qf
You can just give the suitable pattern to do your filtering.
yes, I wrote a vim plugin, can do "grep" on quickfix window.
https://github.com/sk1418/QFGrep
You can just give the suitable pattern to do your filtering.
yes, I wrote a vim plugin gist, can do :Cfilter and :Cfilter! (invert search)
https://gist.github.com/PeterRincker/33345cf7fdeb9038611e4a338a0067f3
You can just give the suitable pattern to do your filtering.
:Cfilter /foo/

Vim cscope show results in split buffer

I am looking to show the results of cscope in a split window. This question is the closet thing I found to an answerbut it doesn't explain fully how to resolve the issue.
I also found this question where in the comments section they explain how to use the cscope to get a split window. But I just get an error No matches found for the global symbol
I thought I would make myself clear. I want to view the cscope results like this:
You can use the quickfix window for this. See :h cscopequickfix.
I wrote a small plugin around this that makes the experience slightly better. For example, it doesn't jump automatically to first result, it maintains the splits layouts etc.
https://github.com/ronakg/quickr-cscope.vim

How to i show omnicomplete's autocomplete list without autocompleting current text

I am learning vim with omnicomplete. I am wondering whether I can show the omnicomplete list without autocompleting current text. For example,
If I type "str.c" and then invoke omnicomplete, it will show a list containing possible words starting with "c", and autocomplete the current text to, say "capitalize".
If, for example, the method I am looking for is count, I have to scroll all the way down the list to find it, or delete the "apitalize" part, and then type o, etc. Is it possible to just show the list, so that if I invoke it after c, it will show the list without autocompleting to capitalize? For example to something like below, where I can still type o to quickly go to count
Thanks to #romainl comment, I looked up completeopt, and I found the answer Make Vim completion popup menu work just like in an IDE. It has a bunch of other related tips. To make the behaviour as described in the question,
:set completeopt=longest,menuone
You can also just stick with the basic vim functionality, and use C-e while in completion to have vim remove the list and go back to the point you initiated the completion.
Alternatively, you can press <C-P> right after <C-X><C-O> to go back to what you typed while keeping the completion menu open.
Check out :h ins-completion-menu for more information.
I think that the initial problem was the lack of noinsert in completeopt option.

How to quit Vim quickfix?

I know that when you run :make in Vim, you can use commands to go through each error like :cn and :cp. However, I often find myself scrolling through warnings that I don't need to fix. Is there a way to quit scrolling through the errors/warnings and resume editing? (I have heard that you can set Vim to ignore warnings, but I've been told it's difficult so I'm looking for something easier).
You can close the quickfix window by running:
:ccl[ose]
If you want to open the quickfix window again (without having to run :make) you can run:
:cope[n]
Even if the quickfix window is not visible, you can still move forwards and backwards through the items in it with the commands :cn and :cp.
Personally, I find the :cn and :cp commands quite laborious to type, so I would recommend mapping them to something more convenient if you use them often. The unimpaired plugin provides sensible mappings for moving through the quickfix list:
[q :cprevious
]q :cnext
[Q :cfirst
]Q :clast
If quitting from that window is all you want you can do as suggested above
:ccl
or even simply
:q
in the errors window.
Or you can simply switch windows ctrl-w+w ctrl-w+k...
I often find myself scrolling through
warnings that I don't need to fix
Two solutions:
The very very best solution: Set your compiler to the highest warning level and change
your code to get rid of all warnings.
The very very worst solution: Set 'errorformat' so that warnings do not hit. See
:help errorformat. How to do this is specific to your compiler output format.
Is there a way to quit scrolling
through the errors/warnings and resume
editing?
Hmmm, maybe I get your question wrong but I would do it this way:
Open at least two windows. One shows the erros/warnings (quickfix window) and the
other shows your code. Just change focus from quickfix to code window in order
to continue typing code.

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