From ad8cdc2f01605dda4f23372da61d186b01a85ed7 Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Tue, 9 Sep 2014 20:12:01 +0800 Subject: [PATCH 1/9] only map in normal mode --- plugin/SearchComplete.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/SearchComplete.vim b/plugin/SearchComplete.vim index 8e950c6..ba84ce4 100644 --- a/plugin/SearchComplete.vim +++ b/plugin/SearchComplete.vim @@ -39,7 +39,7 @@ let loaded_search_complete = 1 "-------------------------------------------------- " Key mappings "-------------------------------------------------- -noremap / :call SearchCompleteStart()/ +nnoremap / :call SearchCompleteStart()/ "-------------------------------------------------- From 919d32fc35ceefd8955ef1faba9ce963004a8ff5 Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Wed, 10 Sep 2014 09:55:27 +0800 Subject: [PATCH 2/9] add support for ? --- plugin/SearchComplete.vim | 47 ++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/plugin/SearchComplete.vim b/plugin/SearchComplete.vim index ba84ce4..4b7c891 100644 --- a/plugin/SearchComplete.vim +++ b/plugin/SearchComplete.vim @@ -1,35 +1,35 @@ " SearchComplete.vim " Author: Chris Russell " Version: 1.1 -" License: GPL v2.0 -" +" License: GPL v2.0 +" " Description: -" This script defineds functions and key mappings for Tab completion in +" 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 +" 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 @@ -38,22 +38,29 @@ let loaded_search_complete = 1 "-------------------------------------------------- " Key mappings -"-------------------------------------------------- -nnoremap / :call SearchCompleteStart()/ +"-------------------------------------------------- +nnoremap / :call SearchCompleteStart('f')/ +nnoremap ? :call SearchCompleteStart('b')? "-------------------------------------------------- " Set mappings for search complete -"-------------------------------------------------- -function! SearchCompleteStart() - cnoremap :call SearchComplete()/s +"-------------------------------------------------- +function! SearchCompleteStart(dir) + if a:dir == 'f' + let s:completecmd = "\" + cnoremap :call SearchComplete()/s + else + let s:completecmd = "\" + cnoremap :call SearchComplete()?s + endif cnoremap :call SearchCompleteStop() cnoremap :call SearchCompleteStop() endfunction "-------------------------------------------------- " Tab completion in / search -"-------------------------------------------------- +"-------------------------------------------------- function! SearchComplete() " get current cursor position let l:loc = col( "." ) - 1 @@ -65,10 +72,10 @@ function! SearchComplete() " get root search string let l:search = b:searchcomplete " increase number of autocompletes - let b:searchcompletedepth = b:searchcompletedepth . "\" + let b:searchcompletedepth = b:searchcompletedepth . s:completecmd else " one autocomplete - let b:searchcompletedepth = "\" + let b:searchcompletedepth = s:completecmd endif " store origional search parameter let b:searchcomplete = l:search @@ -91,7 +98,7 @@ endfunction "-------------------------------------------------- " Remove search complete mappings -"-------------------------------------------------- +"-------------------------------------------------- function! SearchCompleteStop() cunmap cunmap From 93ef187444f091a5ea6e366651c9a568d72389ee Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Wed, 10 Sep 2014 09:58:59 +0800 Subject: [PATCH 3/9] protect registers --- plugin/SearchComplete.vim | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugin/SearchComplete.vim b/plugin/SearchComplete.vim index 4b7c891..5aec80d 100644 --- a/plugin/SearchComplete.vim +++ b/plugin/SearchComplete.vim @@ -54,6 +54,7 @@ function! SearchCompleteStart(dir) let s:completecmd = "\" cnoremap :call SearchComplete()?s endif + let s:reg_s = @s cnoremap :call SearchCompleteStop() cnoremap :call SearchCompleteStop() endfunction @@ -103,5 +104,6 @@ function! SearchCompleteStop() cunmap cunmap cunmap + let @s = s:reg_s endfunction From accd0c253e943038f52bb41eadeea92a6464f993 Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Thu, 18 Dec 2014 15:01:36 +0800 Subject: [PATCH 4/9] Update README --- README | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README b/README index cae45fc..a9de3a4 100644 --- a/README +++ b/README @@ -1,3 +1,9 @@ This is a mirror of http://www.vim.org/scripts/script.php?script_id=474 Call me lazy but I wanted to be able to tab-complete words while typing in a search and I have always been up to a challange. After learning a lot more about vim and key mapping then I ever knew before, this is the result, working tab completion inside a search. + +*Some Fix* + +1. Only bind / in normal mode + +2. Also support complete in backward search (?) From e7853fd5f1e1f9ab46c508433e9a4207858623a2 Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Thu, 18 Dec 2014 15:02:15 +0800 Subject: [PATCH 5/9] Rename README to README.md --- README => README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README => README.md (100%) diff --git a/README b/README.md similarity index 100% rename from README rename to README.md From ba6e8cd3e914554bcd2eaa3210c58804cbbec746 Mon Sep 17 00:00:00 2001 From: Dewdrops Date: Thu, 18 Dec 2014 15:03:23 +0800 Subject: [PATCH 6/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a9de3a4..d2e5848 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a mirror of http://www.vim.org/scripts/script.php?script_id=474 Call me lazy but I wanted to be able to tab-complete words while typing in a search and I have always been up to a challange. After learning a lot more about vim and key mapping then I ever knew before, this is the result, working tab completion inside a search. -*Some Fix* +## Some Fix 1. Only bind / in normal mode From 32615153226cc76f76af6e512643b94c41b63483 Mon Sep 17 00:00:00 2001 From: Russell Pickett Date: Wed, 4 Nov 2015 17:09:56 -0800 Subject: [PATCH 7/9] Allow / in search history --- plugin/SearchComplete.vim | 82 ++++++++++++++++++++------------------- 1 file changed, 43 insertions(+), 39 deletions(-) diff --git a/plugin/SearchComplete.vim b/plugin/SearchComplete.vim index 5aec80d..5fa4907 100644 --- a/plugin/SearchComplete.vim +++ b/plugin/SearchComplete.vim @@ -19,9 +19,9 @@ " " Changelog: " 2002-11-08 v1.1 -" Convert to unix eol +" Convert to unix eol " 2002-11-05 v1.0 -" Initial release +" Initial release " " TODO: " @@ -55,55 +55,59 @@ function! SearchCompleteStart(dir) cnoremap :call SearchComplete()?s endif let s:reg_s = @s - cnoremap :call SearchCompleteStop() - cnoremap :call SearchCompleteStop() + cnoremap :call SearchCompleteStop() + cnoremap :call SearchCompleteStop() + " allow Up/Down arrows without breaking + cnoremap [A [A + cnoremap [B [B + 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 . s:completecmd - else - " one autocomplete - let b:searchcompletedepth = s:completecmd - 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 + " 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 . s:completecmd + else + " one autocomplete + let b:searchcompletedepth = s:completecmd + 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 + cunmap + cunmap + cunmap let @s = s:reg_s endfunction From 59bd57be13c7407026d31efa7a5632611999d39f Mon Sep 17 00:00:00 2001 From: Russell Pickett Date: Wed, 4 Nov 2015 17:19:07 -0800 Subject: [PATCH 8/9] emersonrp README update --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d2e5848..4dba596 100644 --- a/README.md +++ b/README.md @@ -7,3 +7,9 @@ Call me lazy but I wanted to be able to tab-complete words while typing in a sea 1. Only bind / in normal mode 2. Also support complete in backward search (?) + + +### emersonrp change: + +Explicitly map <Up> and <Down> so they work inside search mode to walk up and +down the search history. From 13bbc9c96aff7597b1a5f973f3739239c761309b Mon Sep 17 00:00:00 2001 From: DerWeh Date: Wed, 22 Mar 2017 10:49:04 +0100 Subject: [PATCH 9/9] Replace mapping by [search] to allow remapping. --- plugin/SearchComplete.vim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/plugin/SearchComplete.vim b/plugin/SearchComplete.vim index 5fa4907..dadcdf5 100644 --- a/plugin/SearchComplete.vim +++ b/plugin/SearchComplete.vim @@ -39,8 +39,13 @@ let loaded_search_complete = 1 "-------------------------------------------------- " Key mappings "-------------------------------------------------- -nnoremap / :call SearchCompleteStart('f')/ -nnoremap ? :call SearchCompleteStart('b')? + +noremap [search] +noremap [bsearch] +onoremap [search] /=SearchCompleteStart('f') +onoremap [bsearch] /=SearchCompleteStart('b') +nnoremap [search] :call SearchCompleteStart('f')/ +nnoremap [bsearch] :call SearchCompleteStart('b')? "--------------------------------------------------