2 " Author: Chris Russell
7 " This script defineds functions and key mappings for Tab completion in
11 " This script catches the <Tab> character when using the '/' search
12 " command. Pressing Tab will expand the current partial word to the
13 " next matching word starting with the partial word.
15 " If you want to match a tab, use the '\t' pattern.
18 " Simply drop this file into your $HOME/.vim/plugin directory.
30 "--------------------------------------------------
31 " Avoid multiple sourcing
32 "--------------------------------------------------
33 if exists( "loaded_search_complete" )
36 let loaded_search_complete = 1
39 "--------------------------------------------------
41 "--------------------------------------------------
42 noremap / :call SearchCompleteStart()<CR>/
45 "--------------------------------------------------
46 " Set mappings for search complete
47 "--------------------------------------------------
48 function! SearchCompleteStart()
49 cnoremap <Tab> <C-C>:call SearchComplete()<CR>/<C-R>s
50 cnoremap <silent> <CR> <CR>:call SearchCompleteStop()<CR>
51 cnoremap <silent> <Esc> <C-C>:call SearchCompleteStop()<CR>
54 "--------------------------------------------------
55 " Tab completion in / search
56 "--------------------------------------------------
57 function! SearchComplete()
58 " get current cursor position
59 let l:loc = col( "." ) - 1
60 " get partial search and delete
61 let l:search = histget( '/', -1 )
62 call histdel( '/', -1 )
65 " get root search string
66 let l:search = b:searchcomplete
67 " increase number of autocompletes
68 let b:searchcompletedepth = b:searchcompletedepth . "\<C-N>"
71 let b:searchcompletedepth = "\<C-N>"
73 " store origional search parameter
74 let b:searchcomplete = l:search
75 " set paste option to disable indent options
78 " on a temporary line put search string and use autocomplete
79 execute "normal! A\n" . l:search . b:searchcompletedepth
80 " get autocomplete result
81 let @s = getline( line( "." ) )
82 " undo and return to first char
84 " return to cursor position
86 execute "normal! ". l:loc . "l"
92 "--------------------------------------------------
93 " Remove search complete mappings
94 "--------------------------------------------------
95 function! SearchCompleteStop()