From d61f2bdf23c9483e9e2d1c97e156f818e4ace313 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Thu, 12 Jun 2014 16:41:14 +0900 Subject: [PATCH 1/2] Improve a variable name & add a comment --- autoload/EasyMotion.vim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index 53e94a0..7f63ee0 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -959,9 +959,9 @@ function! s:PromptUser(groups) "{{{ let lines[line_num]['marker'] .= ' ' endif "}}} - let target_col = '\%' . (col_num + col_add) . 'c.' + let target_col_regexp = '\%' . (col_num + col_add) . 'c.' let target_char = matchstr(lines[line_num]['marker'], - \ target_col) + \ target_col_regexp) let space_len = strdisplaywidth(target_char) \ - strdisplaywidth(marker_char) " Substitute marker character @@ -969,7 +969,7 @@ function! s:PromptUser(groups) "{{{ let lines[line_num]['marker'] = substitute( \ lines[line_num]['marker'], - \ target_col, + \ target_col_regexp, \ escape(substitute_expr,'&'), \ '') @@ -982,7 +982,7 @@ function! s:PromptUser(groups) "{{{ let _hl_group = g:EasyMotion_hl2_second_group_target endif call EasyMotion#highlight#add_highlight( - \ '\%' . line_num . 'l' . target_col, + \ '\%' . line_num . 'l' . target_col_regexp, \ _hl_group) "}}} @@ -1120,6 +1120,8 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive) " {{{ let win_first_line = line('w0') " visible first line num let win_last_line = line('w$') " visible last line num + " Store the target positions list + " e.g. targets = [ [line, col], [line2, col2], ...] let targets = [] " Store info for Repeat motion {{{ From 2d2b597ce39f6d134afc47e1301b136b1dc820db Mon Sep 17 00:00:00 2001 From: haya14busa Date: Thu, 12 Jun 2014 17:11:14 +0900 Subject: [PATCH 2/2] Fix dot repeat with count - Solution: Consider into the char on the cursor position while dot repeat. fix #164 --- autoload/EasyMotion.vim | 12 ++++++++++++ autoload/EasyMotion/helper.vim | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/autoload/EasyMotion.vim b/autoload/EasyMotion.vim index 7f63ee0..d5eff99 100644 --- a/autoload/EasyMotion.vim +++ b/autoload/EasyMotion.vim @@ -59,6 +59,7 @@ function! EasyMotion#reset() \ 'bd_t' : 0, \ 'find_bd' : 0, \ 'linewise' : 0, + \ 'count_dot_repeat' : 0, \ } " regexp: -> regular expression " This value is used when multi input find motion. If this values is @@ -70,6 +71,8 @@ function! EasyMotion#reset() " This value is used to recheck the motion is inclusive or exclusive " because 'f' & 't' forward find motion is inclusive, but 'F' & 'T' " backward find motion is exclusive + " count_dot_repeat: -> dot repeat with count + " https://github.com/Lokaltog/vim-easymotion/issues/164 let s:current = { \ 'is_operator' : 0, \ 'is_search' : 0, @@ -301,6 +304,7 @@ function! EasyMotion#DotRepeat(visualmode) " {{{ let s:flag.bd_t = s:dot_repeat.bd_t_flag let s:current.is_operator = 1 + let s:flag.count_dot_repeat = (i > 0 ? 1 : 0) silent call s:EasyMotion(re, direction, 0, is_inclusive) endfor return s:EasyMotion_is_cancelled @@ -1189,6 +1193,14 @@ function! s:EasyMotion(regexp, direction, visualmode, is_inclusive) " {{{ endif "}}} + " Handle dot repeat with count + if s:flag.count_dot_repeat + let cursor_char = EasyMotion#helper#get_char_by_coord(s:current.cursor_position) + if cursor_char =~# regexp + call add(targets, s:current.cursor_position) + endif + endif + " Construct match dict {{{ while 1 " Note: searchpos() has side effect which jump cursor position. diff --git a/autoload/EasyMotion/helper.vim b/autoload/EasyMotion/helper.vim index 547c45b..9a65fc3 100644 --- a/autoload/EasyMotion/helper.vim +++ b/autoload/EasyMotion/helper.vim @@ -33,6 +33,17 @@ function! EasyMotion#helper#mode(flag) "{{{ return mode(a:flag) == "\" ? "C-v" : mode(a:flag) endfunction "}}} +function! EasyMotion#helper#get_char_by_coord(coord) "{{{ + " @param coord: [lnum, col] or [bufnum, lnum, col, off] + if len(a:coord) == 4 + let [line_num, col_num] = [a:coord[1], a:coord[2]] + else + let [line_num, col_num] = a:coord + endif + let target_col_regexp = '\%' . (col_num) . 'c.' + return matchstr(getline(line_num), target_col_regexp) +endfunction "}}} + function! EasyMotion#helper#is_greater_coords(coords1, coords2) "{{{ " [line_num, col_num] < [line_num, col_num] "