0

I have been doing these operation and require to do it often.

step 1. Search for a string (SHFT + *)
step 2. Switch to previous view port (CTRL + w + h)
step 3. Find the string ( n )
step 4. Return to the other view port (CTRL + w + l)

With Vi(m), is it possible to automate above 4 steps in one go?

I searched the net and stackoverflow, I am NOT talking about :set scrollbind.

AjayKumarBasuthkar
  • 2,885
  • 2
  • 23
  • 27

2 Answers2

4

If you want to apply a :substitute to multiple buffers, you can use :windo, :bufdo, :argdo.


For searching, you can streamline the window switching with a mapping. For example, to move to the next match in the previous window (without staying in that window):

:nnoremap <C-w>n <C-w>pn<C-w>p

To make this support a [count]:

:nnoremap <silent> <C-w>n :<C-u>wincmd p<Bar>execute 'normal!' v:count1 . 'n'<Bar>wincmd p<CR>
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • I am learning to use vim, I read the help and understood very little, could you please explain, I did not succeed using the mapping yet... – AjayKumarBasuthkar Jul 09 '14 at 17:01
  • 1
    You put that mapping into your `~/.vimrc`, or type it into Vim (to try it out). It's triggered by first pressing `Ctrl+W`, followed by `n`. – Ingo Karkat Jul 10 '14 at 06:10
0

The answer and the clue by IngoKarkat about mapping lead to this
:nnoremap <F3> <S-*><C-w>hn<C-w>l
and this work like a charm.

Function key F3 is key mapping.

AjayKumarBasuthkar
  • 2,885
  • 2
  • 23
  • 27