]> git.r.bdr.sh - rbdr/dotfiles/blob - vim/plugin/SearchComplete.vim
Move EasyMotion and LargeFile to pathogen bundle
[rbdr/dotfiles] / vim / plugin / SearchComplete.vim
1 " SearchComplete.vim
2 " Author: Chris Russell
3 " Version: 1.1
4 " License: GPL v2.0
5 "
6 " Description:
7 " This script defineds functions and key mappings for Tab completion in
8 " searches.
9 "
10 " Help:
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.
14 "
15 " If you want to match a tab, use the '\t' pattern.
16 "
17 " Installation:
18 " Simply drop this file into your $HOME/.vim/plugin directory.
19 "
20 " Changelog:
21 " 2002-11-08 v1.1
22 " Convert to unix eol
23 " 2002-11-05 v1.0
24 " Initial release
25 "
26 " TODO:
27 "
28
29
30 "--------------------------------------------------
31 " Avoid multiple sourcing
32 "--------------------------------------------------
33 if exists( "loaded_search_complete" )
34 finish
35 endif
36 let loaded_search_complete = 1
37
38
39 "--------------------------------------------------
40 " Key mappings
41 "--------------------------------------------------
42 noremap / :call SearchCompleteStart()<CR>/
43
44
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>
52 endfunction
53
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 )
63 " check if new search
64 if l:search == @s
65 " get root search string
66 let l:search = b:searchcomplete
67 " increase number of autocompletes
68 let b:searchcompletedepth = b:searchcompletedepth . "\<C-N>"
69 else
70 " one autocomplete
71 let b:searchcompletedepth = "\<C-N>"
72 endif
73 " store origional search parameter
74 let b:searchcomplete = l:search
75 " set paste option to disable indent options
76 let l:paste = &paste
77 setlocal paste
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
83 execute "normal! u0"
84 " return to cursor position
85 if l:loc > 0
86 execute "normal! ". l:loc . "l"
87 endif
88 " reset paste option
89 let &paste = l:paste
90 endfunction
91
92 "--------------------------------------------------
93 " Remove search complete mappings
94 "--------------------------------------------------
95 function! SearchCompleteStop()
96 cunmap <Tab>
97 cunmap <CR>
98 cunmap <Esc>
99 endfunction
100