Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit 92f879d4e97ebc3a760ff0ebfe5a3e4b74122ac2 1 parent 0cfba1d
@chrisbra authored
Showing with 19 additions and 1 deletion.
  1. +19 −1 autoload/ftimproved.vim
View
20 autoload/ftimproved.vim
@@ -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)
Please sign in to comment.
Something went wrong with that request. Please try again.