Permalink
Browse files

when typing several chars and the match is unique, directly jump to it

  • Loading branch information...
1 parent 0cfba1d commit 92f879d4e97ebc3a760ff0ebfe5a3e4b74122ac2 @chrisbra committed Mar 27, 2013
Showing with 19 additions and 1 deletion.
  1. +19 −1 autoload/ftimproved.vim
View
@@ -153,6 +153,13 @@ fun! <sid>Unmap(lhs) "{{{1
endif
endfun
+fun! <sid>CountMatchesWin(pat) "{{{1
+ " Return number of matches of pattern within the current windows viewport
+ " TODO: filter folded lines?
+ let buf = join(getline('w0', 'w$'), '')
+ return len(split(buf, a:pat.'\zs')) - 1
+endfu
+
fun! ftimproved#ColonCommand(f, mode) "{{{1
" should be a noop
if !exists("s:searchforward")
@@ -221,7 +228,8 @@ fun! ftimproved#FTCommand(f, fwd, mode) "{{{1
if !get(g:, "ft_improved_ignorecase", 0)
let char = '\c'.char
endif
- if get(g:, "ft_improved_multichars", 0)
+ if get(g:, "ft_improved_multichars", 0) &&
+ \ <sid>CountMatchesWin(char) > 1
call <sid>HighlightMatch(char, a:fwd)
let next = getchar()
" break on Enter, Esc or Backspace
@@ -239,6 +247,16 @@ fun! ftimproved#FTCommand(f, fwd, mode) "{{{1
let char .= <sid>EscapePat(nr2char(next),0)
endif
+ " Get matches of pattern within the windows viewport
+ let matches = <sid>CountMatchesWin(char)
+
+ if matches == 0
+ " no match within the windows viewport, abort
+ return s:escape
+ elseif matches == 1
+ break
+ endif
+
if char =~# '^\%(\\c\)\?\\V$'
" don't highlight empty pattern
call <sid>HighlightMatch('', a:fwd)

0 comments on commit 92f879d

Please sign in to comment.