Skip to content

Commit 0ed4621

Browse files
committed
Merge branch 'fix-vcol'
2 parents 39abbf3 + f306da3 commit 0ed4621

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

autoload/EasyMotion.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ function! EasyMotion#JK(visualmode, direction) " {{{
205205
if g:EasyMotion_startofline
206206
call s:EasyMotion('^\(\w\|\s*\zs\|$\)', a:direction, a:visualmode ? visualmode() : '', 0)
207207
else
208-
let c = col('.')
209-
let pattern = printf('^.\{-}\zs\(\%%<%dv.\%%>%dv\|$\)', c + 1, c)
208+
let vcol = EasyMotion#helper#vcol('.')
209+
let pattern = printf('^.\{-}\zs\(\%%<%dv.\%%>%dv\|$\)', vcol + 1, vcol)
210210
call s:EasyMotion(pattern, a:direction, a:visualmode ? visualmode() : '', 0)
211211
endif
212212
return s:EasyMotion_is_cancelled

autoload/EasyMotion/helper.vim

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,24 @@ endif "}}}
158158
function! EasyMotion#helper#include_multibyte_char(str) "{{{
159159
return strlen(a:str) != EasyMotion#helper#strchars(a:str)
160160
endfunction "}}}
161+
162+
function! EasyMotion#helper#vcol(expr) abort
163+
let col_num = col(a:expr)
164+
let line = getline(a:expr)
165+
let before_line = col_num > 2 ? line[: col_num - 2]
166+
\ : col_num is# 2 ? line[0]
167+
\ : ''
168+
let vcol_num = 1
169+
for c in split(before_line, '\zs')
170+
let vcol_num += c is# "\t" ? s:_virtual_tab2spacelen(vcol_num) : len(c)
171+
endfor
172+
return vcol_num
173+
endfunction
174+
175+
function! s:_virtual_tab2spacelen(col_num) abort
176+
return &tabstop - ((a:col_num - 1) % &tabstop)
177+
endfunction
178+
161179
"}}}
162180

163181
" Restore 'cpoptions' {{{

0 commit comments

Comments
 (0)