I want to search in VIM in multiple split-windows
Steps:
Is this possible?
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' .
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”.
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.
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 |.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With