Tip #442: Show all lines that contain keyword under cursor
tip karma |
Rating 95/40, Viewed by 2471
|
created: |
|
March 15, 2003 4:56 |
|
complexity: |
|
basic |
author: |
|
Dopey |
|
as of Vim: |
|
5.7 |
Started finding this one pretty useful.
If you want to view a list of all the lines in the current buffer that contain a word, place your cursor over the word and press [I
Handy to see where you last used variables, functions, etc.
<< Toggle auto-wrap using txtwidth in INSERT mode |
A better interfacing of (La)TeX with the quickfix mode >>
Additional Notes
Anonymous,
March 15, 2003 19:48
|
This is kind of useful but is there any way so that you can run [I on all loaded buffers (or all files in a directory)?
|
Anonymous,
March 17, 2003 2:55
|
Actually, the [I is even more powerfull than that. It does not search only current buffer, but also included files, where meaning of 'included' depends on settings, but defaults are set for C (i.e., #included files, searched in ., /usr/include and maybe elsewhere). It is really good thing.
To previous comment, :grep would be probably more appropriate...
|
Anonymous,
March 18, 2003 23:14
|
" grep for word under cursor in c/cpp/h-files
map <F9> <ESC>:exec("grep ".expand("<cword>")." ../*/*.c* ../*/*.h")<CR>
You can omit '<CR>' for manual changing the file pattern before searching.
if you have configured 'set grepprg=mygrep\ -n ' then you can use quickfix mode for jumping to the found locations.
Thomas
|
VimUser,
March 20, 2003 23:06
|
When I get the results from [I, how do I scroll between them or navigate the list and perhaps jump to an item on the list?
|
shawn@deleurme.com,
March 23, 2003 10:16
|
to jump to those results, just use
# to go to the first match
[ CNTR-I
# to go to the others.
] CTRL-I
This follows the C-I/C-O jumping patterns. Also, try prepending the windowing operator (CTRL-W) and a new window will open into the appropriate file.
|
wnatter@nortelnetworks.com,
March 25, 2003 10:18
|
Hi,
With regard to the above notes, is there a way to add include directories? In this way, all files of importance to me would be searched... I currently have a grep-like solution that uses make (:make search S='search string'), where the "search" target uses "grep -n" on a bunch of files.
William
|
Anonymous,
January 16, 2007 1:25
|
It's fine!
but
how to save the result?
|
|
|