Skip to content

Commit

Permalink
Make ',' and ';' work as documented (fixes #5)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbra committed Jun 5, 2015
1 parent 23ddb00 commit a40bdb4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ vim_passfile
*.vba
# ignore *.orig files
*.orig
*.vmb
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Functionality
This plugin tries to improve the existing behaviour of the |f|, |F|, |t| and
|T| command by letting them move the cursor not only inside the current line,
but move to whatever line, where the character is found. Also the |,| and |;|
command should just work as expected.
command should consistently by default, but can be enabled to work as usual
(see |improvedft-consistent_comma|).

It does consider counts given and should work simply as a user would be
expecting.
Expand Down
27 changes: 11 additions & 16 deletions autoload/ftimproved.vim
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ fun! <sid>ColonPattern(cmd, pat, off, f, fwd) "{{{1
if !exists("s:colon")
let s:colon = {}
endif
let pat = a:pat
let cmd = a:cmd
let pat = a:pat
let opp = <sid>Opposite(a:cmd[-1:])
let opp_off = <sid>Opposite(a:off[0])
if a:cmd == 'f'
if a:cmd ==# 'f' || a:cmd ==# 't'
let cmd = '/'
elseif a:cmd == 'F'
elseif a:cmd == 'F' || a:cmd ==# 'T'
let cmd = '?'
endif
let s:colon[';'] = cmd[-1:]. pat.
Expand Down Expand Up @@ -203,11 +203,7 @@ fun! ftimproved#ColonCommand(f, mode) "{{{1
if !exists("s:searchforward")
let s:searchforward = 1
endif
if s:searchforward
let fcmd = (a:f ? ';' : ',')
else
let fcmd = (!a:f ? ';' : ',')
endif
let fcmd = (a:f ? ';' : ',')
if !exists("s:colon")
let s:colon={}
let s:colon[';']=''
Expand All @@ -218,13 +214,13 @@ fun! ftimproved#ColonCommand(f, mode) "{{{1
let res = (empty(s:colon[fcmd]) ? fcmd : s:colon[fcmd])

if get(g:, 'ft_improved_consistent_comma', 0)
let fcmd = (a:f ? ',' : ';')
if (a:f && res[0] !=? '/')
let res = (empty(s:colon[fcmd]) ? fcmd : s:colon[fcmd])
elseif (!a:f && res[0] !=? '?')
let res = (empty(s:colon[fcmd]) ? fcmd : s:colon[fcmd])
if a:f
let res = '/'.res[1:-2]. '/'
else
let res = '?'.res[1:-2]. '?'
endif
endif

let oldsearchpat = @/
if a:mode =~ 'o' &&
\ s:colon['cmd'] " last search was 'f' command
Expand All @@ -238,7 +234,7 @@ fun! ftimproved#ColonCommand(f, mode) "{{{1
let spat = pat[2]
if pat[1] =~ '[?/]'
let pat[2] = escape(pat[2], pat[1])
if !s:colon['cmd'] && pat[1] == '?' " t or T command
if !s:colon['cmd'] && pat[1] == '?'
" T command
let res = pat[1]. '\('. pat[2]. '\m\)\@<=.' . pat[1]
elseif !s:colon['cmd']
Expand Down Expand Up @@ -279,6 +275,7 @@ fun! ftimproved#FTCommand(f, fwd, mode) "{{{1
" fwd: forward motion
" mode: mapping mode
try
let s:searchforward = a:fwd
let char = nr2char(getchar())
if char == s:escape
" abort when Escape has been hit
Expand Down Expand Up @@ -351,15 +348,13 @@ fun! ftimproved#FTCommand(f, fwd, mode) "{{{1
" Check if normal f/t commands would work:
if search(matchstr(pat.'\C', '^\%(\\c\)\?\zs.*'), 'nW') == line('.')
\ && a:fwd
let s:searchforward = 1
let cmd = (a:f ? 'f' : 't')
call <sid>ColonPattern(<sid>SearchForChar(cmd),
\ pat, '', a:f, a:fwd)
return <sid>DebugOutput(cmd.orig_char)

elseif search(matchstr(pat.'\C', '^\%(\\c\)\?\zs.*'), 'bnW') == line('.')
\ && !a:fwd
let s:searchforward = 0
let cmd = (a:f ? 'F' : 'T')
call <sid>ColonPattern(<sid>SearchForChar(cmd),
\ pat, '', a:f, a:fwd)
Expand Down
6 changes: 5 additions & 1 deletion doc/ft_improved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ Functionality
This plugin tries to improve the existing behaviour of the |f|, |F|, |t| and
|T| command by letting them move the cursor not only inside the current line,
but move to whatever line, where the character is found. Also the |,| and |;|
command should just work as expected.
command should consistently by default, but can be enabled to work as usual
(see |improvedft-consistent_comma|).

It does consider counts given and should work simply as a user would be
expecting.
Expand Down Expand Up @@ -176,6 +177,9 @@ third line of this document.
==============================================================================
4. History *improvedft-history*

0.10: (unreleased) "{{{
- Make |,| and |;| work as documented (reported by JonnyRa in
https://github.com/chrisbra/improvedft/issues/5, thanks!)
0.9: Jan 15, 2015 "{{{
- do not mess up highlighting for |;| and |,| commands
- make count work correctly with multi-highlight match, so that only the
Expand Down

0 comments on commit a40bdb4

Please sign in to comment.