Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switching to VIM window by name

Tags:

vim

windows

There are some excellent Vim plugins for switching to a specific file or buffer by typing part of the name. Does anyone know of a plugin like these that allows for quickly switching between open windows?

For example, if I had a vsplit with a file named 'a.txt' on one side and 'b.txt' on another I'd like to be able to switch between them by typing the filename (or just 'a' or 'b' with incremental searching). This might not be too useful for two windows, but I often have up to 5 windows open, so switching between them using the normal navigation buttons can be a pain.

WinWalker seems to support this type of functionality, but wrapped inside of a much larger framework for window navigation.

like image 870
Zack L Avatar asked Mar 14 '11 22:03

Zack L


People also ask

How do I switch between vim windows?

To move from the current Vim window to the next one, type CTRL-W j (or CTRL-W <down> or CTRL-W CTRL-J). The CTRL-W is the mnemonic for “window” command, and the j is analogous to Vim's j command, which moves the cursor to the next line.

How do I switch between files in vim?

Just remember these commands to easily switch between buffers: :bf # Go to first file. :bl # Go to last file :bn # Go to next file. :bp # Go to previous file. :b number # Go to n'th file (E.g :b 2) :bw # Close current file.

What is Wincmd Vim?

wincmd is the vimscript equivalent to Ctrl w in normal mode.


2 Answers

:b does that happily if you have :setswitchbuf+=useopen (in your vimrc). It supports file name completion, e.g. with Ctrl-D.

by MarcWeber et al from #vim

like image 199
Aaron Thoma Avatar answered Nov 10 '22 20:11

Aaron Thoma


@Aaron Thoma' s answer with switchbuf+=useopen did not work for me. Actually the doc does not mention that the setting is supported by :b comand.

I've used the following snippet:

let windowNr = bufwinnr(pattern)
if windowNr > 0
  execute windowNr 'wincmd w'
endif  

See bufwinnr()

like image 3
dre-hh Avatar answered Nov 10 '22 21:11

dre-hh