sponsor Vim development Vim logo Vim Book Ad

betterSearch.vim : Provide better search functionality by capturing all matched line

 script karma  Rating 5/4, Downloaded by 1063    Comments, bugs, improvements  Vim wiki

created by
kn n
script type
This script will now only updated @ github
You may get it from

** note: tested in Linux/MS window environment using GVIM **
** note: BetterSearchVisualSelect command is found working in Linux, but might not working in MS Window environment at the moment **

Having a large file and you need to search for a few keywords from it?
And wish that you can at once glance all the search result?
Best with highlight on the keyword?
And you would wish to jump to that particular line when you see something interesting?
Here is a good news for you! : )
Solution approach: works somewhat similarly to notepad++ search function

Features offered by betterSearch:
- This script is written to copy all the search result and put it to window above the content.
- If the line number is switch on, the search result is 'jumpable' to the content window by just enter on that particular search line
- Search term highlight can be switched on and off
- Search keyword can be saved to clipboard

There are a few way to use the function of this script.
[ usage 1 ]  
User intended to type in the search words
then <ENTER>.
A window will pop up for user input.
The user input can consists of more than one search term. For example: search_A|search_B|search_C...

[ usage 2 ]
User intended to use the word under the cursor as the search term
then <ENTER>. and press <ENTER> again when the user input dialog box appear without type in any word

[ usage 3 ]
User intended to use the word highlighted in visual mode
Hightlight the word, then type
then <ENTER>.

[ jump to line ]
A search window will be open up on top of the current window.
Press <ENTER> on that particular line to jump to the content window.

[ other commands ]
Other command available by the script. (or press F1 when the focus/cursor is at the search window)
':BetterSearchSwitchWin'        - to switch between the 'Search Window' and the 'Content Window'
':BetterSearchVisualSelect'     - to search based on the visually selected word
':BetterSearchHighlighToggle'   - to toggle keyword highlight on off (default is on)
':BetterSearchHighlightLimit'    - to toggle line limit to switch off keyword highlight, for efficiency purpose,
                               - especially for large matched, default is 5000 line
':BetterSearchCopyToClipBoard' - to toggle whether to save to the search words to clipboard, default is off

[ mapping ]
Suggest to map following in .vimrc, e.g:
nnoremap <A-S-F7> :BetterSearchPromptOn<CR>
vnoremap <A-S-F7> :BetterSearchVisualSelect<CR>
nnoremap <A-w>  :BetterSearchSwitchWin<CR>
nnoremap <A-S-q>  :BetterSearchCloseWin<CR>
install details
### Using Pathogon

mkdir -p ~/.vim/bundle
cd ~/.vim/bundle
git clone https://github.com/kenng/vim-bettersearch.git

### The OLD way
1. Paste the betterSearch.vim script into plugin folder.
   E.g. Vim\vim73\plugin.
2. Restart the Vim session

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
betterSearch.vim 0.0.9 2014-05-01 7.0 kn n v0.0.9: highlight of result follows option ignorecase; custom highlight defined
v0.0.8: revert function gotoLine() as it is easy and accurate
betterSearch.vim 0.0.7 2014-03-29 7.0 kn n [ version ] 0.0.7 ( 29 Mar 2014 )
   - fixed bug not able to jump to line when line number is switched on
   - fixed bug not able to jump to line which contains certain regexp

betterSearch.vim 0.0.5 2014-03-02 7.0 kn n enable [Enter] to jump to particular line without line number switched on
betterSearch.vim 0.0.4 2013-01-03 7.0 kn n - enhanced help description
betterSearch.vim 0.0.3 2013-01-03 7.0 kn n - showed the file path
- added function to close the bettersearch window from anywhere
- fixed visual select search
betterSearch.vim 0.0.2 2012-10-01 7.0 kn n - able to set highlight syntax for search term
- change default shortcut for syntax=c, help=F1
- improve help description
betterSearch.vim 0.0.1 2012-09-27 7.0 kn n Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
SourceForge.net Logo