cscope shortcuts not showing all results of search - vim

I am using shortcuts of cscope in vim editor as per http://cscope.sourceforge.net/cscope_vim_tutorial.html
Shortcuts are not showing all results of the search but it is directly moving to one of the results.
At the end it goes to a specific result from the search and shows below result if I searched for my_func using shortcut:
(1 of 6): <<>> * my_func:
Can anyone please let me know how to show all the results as the result of cscope shortcut in vim editor.

All results are available in the Quickfix Window.
Type :cope to open the Quickfix Window.
There you will find all your results. Navigate over them with normal Vim movement. <ENTER> jumps to the result.

Related

Vim: Configure vim to show autocomplete suggestions from current open files

I had this vim configuration some time back which shows autocomplete suggestions on pressing Ctrl + N from all the files I have opened during a session, not just the current file I am editing. Unfortunately I lost the vimrc and now I can't figure out what was making it do so.
Searched over internet and found results related to omnicomplete. But I didn't understand how it works. Any help would be appreciated. Thanks.
From :help i_ctrl-n:
CTRL-N Find next match for words that start with the
keyword in front of the cursor, looking in places
specified with the 'complete' option. The found
keyword is inserted in front of the cursor.
From :help 'complete' (or <C-]> on 'complete'):
b scan other loaded buffers that are in the buffer list
Don't google, :help.

Cscope result handling with Quickfix window

I am using cscope with quickfix support to display the result by setting set cscopequickfix=s-,c-,d-,i-,t-,e- ~/.vimrc file
I can move between results with :cnext and :cprevious commands
What I want is to display the result in quickfix window first and do a preview before jumping to the file.
I tried using set switchbuf+=usetab,newtab but that gives a different result and not helping.
Is there a plugin or command available to get this behaviour.
I ran into the same issue and fixed it by closing the buffer it opens (1st result) and then opening the results in a quickfix window by calling :cwindow.
Here's what my key remap looks like:
nnoremap <leader>s yiw:cs find s <C-R>=expand("<cword>")<CR><CR>:bd<CR>:cwindow<CR>/<C-R>0<CR>
Explanation:
yiw- Yank the word under cursor for highlighting later
:cs find s <C-R>=expand("<cword>")<CR><CR>- Standard cscope command to find a symbol
:bd<CR>- Delete the buffer, so this closes the first search result
:cwindow<CR>- Open search results in a new quickfix window
/<C-R>0<CR>- Search for the symbol, so I get the symbol I looked up for highlighted in quickfix window and I can move within quickfix window using n and N.
I ended up writing a small plugin for this. You can check it out here - https://github.com/ronakg/quickr-cscope.vim

How can I get cscope results to appear in a split window in gvim7?

I have tried the tutorial here: Vim/Cscope tutorial. After changing the #'s in the cscope_maps.vim file to SPACE I got Ctrl-SPACE s to launch cscope in gVim. However, it takes over the whole window rather than splitting the window for the cscope info.
I then tried as suggested in the comments to the cscope_maps.vim file changing nmap <C-SPACE>s :scs find s <C-R>=expand("<cword>")<CR><CR> to nmap <C-SPACE>s <C-W><C-S> :cs find s <C-R>=expand("<cword>")<CR><CR> because it appears that my gVim does nto support the :scs command. However, this still displays the cscope info in a full window, blocking out my code. When I exit the cscope interface, I return to two split screens.
Any help on how to craft a command in gVim 7.3 that will launch cscope in a split window?
scscope find c foo does what it's supposed to do: display a list of functions calling foo in the command line and open the chosen one in an horizontal split.
But that is not what you want, is it?
The list of possible targets is always displayed in the command line which is expanded as needed: it can't be displayed in a window at all.
That said, you can use the quickfix window to display the list instead of the command line, see :help cscope-options.

Does cscope support history list recording?

I use < C-\ >C to get the callers of one function, then I can press one number to jump to one caller. But if I want to jump to another caller, I had to press < C-T> to jump back, and press < C-\ >C again to get the caller list. Does cscope support history list recording ?
If you are using VIM, you can try quick fix
:se cscopequickfix=s-,c-,d-,i-,t-,e-
Navigate next or previous result with :cn :cp
Use :cw to display cscope search result.
For one thing, you can use
:se cscopetag
or
:lcscope ....
:lopen
With the latter you can even use :lolder and :lnewer to switch back and forth between previous cscope queries.
he cscopetag:
If 'cscopetag' set, the commands ":tag" and CTRL-] as well as "vim -t" will
always use |:cstag| instead of the default :tag behavior. Effectively, by
setting 'cst', you will always search your cscope databases as well as your
tag files. The default is off. Examples:
:set cst
:set nocst
That way you you just
:tnext
:tprev
like always.
Alternatively, you can use
I have no real experience with cscope but take a look at :help cscopequickfix: with this option set the <C-\>c results are supposed to appear in the quickfix window.

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