When searching string with notepad++, new window opens and shows find results. I want to use this feature in vim. After googling I found out some suggestions:
I suggest lvimgrep (so you can use quickfix for :make)
:nnoremap <F6> :lvimgrep /\M\<<C-R><C-W>\m\>/ **/*.[ch]pp **/Makefile | lopen<CR>
Also, if you just wanted to find in the current file:
:g/<pattern>/
will invoke 'print' (default command) on each matching line.
:v// " non-matching lines
:g//-1 " lines preceding the matching line
:g//-1,+1 " lines around the matching line
etc.
:global is far more useful:
:g/foo/ join " join all lines containing foo
etc.
The requirement is actually easy. but to get user inputted pattern, you need a function.
function! FindAll()
call inputsave()
let p = input('Enter pattern:')
call inputrestore()
execute 'vimgrep "'.p.'" % |copen'
endfunction
if you want to have a mapping, add this line:
nnoremap <F8> :call FindAll()<cr>
but as I commented under your question. %
may not work for unamed buffer.
Those two commands can be shortened and chained: :vim foo %|co
. You can pull the word under the cursor like this: :vim <C-r><C-w> %|co
.
Here is a quick normal mode mapping that you can use to list all the occurrences of the word under your cursor in the quickfix window:
nnoremap <F6> :vimgrep /<C-r><C-w>/j % <bar> cwindow<cr>
You can also use :il[ist] foo
to display a list of all the occurrences of foo
or [I
to display the same list for the word under your cursor.
When the list is displayed, use :{line number}
to jump to the corresponding line.