From 9b88b794a1e5015c7aaa3e76968854004798b597 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Sun, 31 Aug 2014 19:51:59 +0200 Subject: [PATCH] Added SearchComplete --- .../SearchComplete/plugin/SearchComplete.vim | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 vim/bundle/SearchComplete/plugin/SearchComplete.vim diff --git a/vim/bundle/SearchComplete/plugin/SearchComplete.vim b/vim/bundle/SearchComplete/plugin/SearchComplete.vim new file mode 100644 index 0000000..8e950c6 --- /dev/null +++ b/vim/bundle/SearchComplete/plugin/SearchComplete.vim @@ -0,0 +1,100 @@ +" 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. +" +" Help: +" This script catches the character when using the '/' search +" command. Pressing Tab will expand the current partial word to the +" next matching word starting with the partial word. +" +" If you want to match a tab, use the '\t' pattern. +" +" Installation: +" Simply drop this file into your $HOME/.vim/plugin directory. +" +" Changelog: +" 2002-11-08 v1.1 +" Convert to unix eol +" 2002-11-05 v1.0 +" Initial release +" +" TODO: +" + + +"-------------------------------------------------- +" 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 +