Amit
Amit

Reputation: 1006

Quickly search for a specific window in vim based on filename

Many times I end up opening a large number of files in vim using split and vsplit. In such a situation, is there some way by which I can search (by filename) for the window that has a specific file open?

I am looking for functionality similar to tmux find window where we can activate a window by searching for text in that window's scroll buffer. However, in case of of vim, I want to be able to set focus on a window by searching for the filename.

Upvotes: 3

Views: 823

Answers (2)

Kent
Kent

Reputation: 195269

first of all, opening multiple files in split makes file editing easier. However if you open "a large number of files" in split..... I don't know what reason makes you do it. If you want to batch process files, you can considering sed/awk/...

Anyway, you can execute this cmd line in your vim, you give the filename, and this cmd will bring you to the window containing the buf.

:call win_gotoid(bufwinid('YourFileName'))

Upvotes: 4

Lix
Lix

Reputation: 48006

You can use the buffer command and append the start of your file name - you'll then be able to tab complete the full name. To make tab completion a little more useful (IMO), you can add these settings to your vimrc file:

" first tab completed to the longest common match, or full match,
" second tab completed to show list of all matches,
" third tab starts to cycle through matches
set wildmode=longest,list,full

If you have 3 buffers open - install.sh, readme.md, app.js -

:b in<TAB> will complete the command to :b install.sh - pressing enter will open the buffer containing the install.sh file. If your search term has multiple matches, keep hitting TAB to cycle through all the results.

For more info, checkout :help buffer

Upvotes: -2

Related Questions