" SearchComplete.vim " Author: Chris Russell " Version: 1.1 " License: GPL v2.0 " " Description: " This script defineds functions and key mappings for Tab completion in " searches. "-------------------------------------------------- " Avoid multiple sourcing "-------------------------------------------------- if exists( "loaded_search_complete" ) finish endif let loaded_search_complete = 1 "-------------------------------------------------- " Key mappings "-------------------------------------------------- noremap / :call SearchCompleteStart()/ "-------------------------------------------------- " Set mappings for search complete "-------------------------------------------------- function! SearchCompleteStart() cnoremap :call SearchComplete()/s cnoremap :call SearchCompleteStop() cnoremap :call SearchCompleteStop() endfunction "-------------------------------------------------- " Tab completion in / search "-------------------------------------------------- function! SearchComplete() " get current cursor position let l:loc = col( "." ) - 1 " get partial search and delete let l:search = histget( '/', -1 ) call histdel( '/', -1 ) " check if new search if l:search == @s " get root search string let l:search = b:searchcomplete " increase number of autocompletes let b:searchcompletedepth = b:searchcompletedepth . "\" else " one autocomplete let b:searchcompletedepth = "\" endif " store origional search parameter let b:searchcomplete = l:search " set paste option to disable indent options let l:paste = &paste setlocal paste " on a temporary line put search string and use autocomplete execute "normal! A\n" . l:search . b:searchcompletedepth " get autocomplete result let @s = getline( line( "." ) ) " undo and return to first char execute "normal! u0" " return to cursor position if l:loc > 0 execute "normal! ". l:loc . "l" endif " reset paste option let &paste = l:paste endfunction "-------------------------------------------------- " Remove search complete mappings "-------------------------------------------------- function! SearchCompleteStop() cunmap cunmap cunmap endfunction