Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Search in multiple split-windows

Tags:

vim

I want to search in VIM in multiple split-windows

Steps:

  1. Highlight word under the cursor with '*' in a split-window
  2. Press 'n' to jump to the next occurrence in all split-windows without changing windows via Ctrl-w-w

Is this possible?

like image 830
JAVH Avatar asked Jan 27 '12 11:01

JAVH


People also ask

How do I use multiple windows in vim?

To split the vim screen horizontally, or open a new workspace at the bottom of the active selection, press Ctrl + w , followed by the letter 's' . In the example below, the left section has been split into two workspaces. To navigate to the bottom section hit Ctrl + w , followed by the letter 'j' .

How do I switch between split screens in vim?

To switch to the right window, press “Ctrl + w”, then “l”. To go to the left window, it's “Ctrl + w”, then “h”. If you did a horizontal split, then going up and down is necessary. For going up, press “Ctrl + w”, then “k”.

How do I view two files side by side in vim?

You can either split vim windows by opening multiple files using -o , -O , -o2 parameters. Or if you're already editing multiple files in one window, you can use :ba to split horizontally or :vert ba to split vertically.

How do I resize a split window in vim?

To resize all windows to equal dimensions based on their splits, you can use Ctrl-w =. To increase a window to its maximum height, use Ctrl-w _. To increase a window to its maximum width, use Ctrl-w |.


1 Answers

nnoremap <silent> n :exe (search(@/, 'nW') == 0 ? "normal \<lt>c-w>\<lt>c-w>ggn" : "normal! n")<cr>
nnoremap <silent> N :exe (search(@/, 'bnW') == 0 ? "normal \<lt>c-w>\<lt>c-w>G$N" : "normal! N")<cr>

This answers the question, but I do not feel like it is in the spirit of vim. I prefer the feel of using the quickfix window.

After using * execute the following:

:cexpr []|exe "windo vimgrepadd//j %"|copen

Now you can use :cn and :cp to move through the searches. I personally use Tim Pope's unimpaired.vim, which provides nice mappings in the form of [q and ]q.

See

:h search(
:h quickfix
:h cexpr
:h windo
:h vimgrepadd
:h copen
:h cn
like image 122
Peter Rincker Avatar answered Oct 08 '22 04:10

Peter Rincker