commit
e1b70995a2
@ -3,7 +3,7 @@
|
|||||||
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
|
" Author: Kim Silkebækken <kim.silkebaekken+vim@gmail.com>
|
||||||
" haya14busa <hayabusa1419@gmail.com>
|
" haya14busa <hayabusa1419@gmail.com>
|
||||||
" Source: https://github.com/Lokaltog/vim-easymotion
|
" Source: https://github.com/Lokaltog/vim-easymotion
|
||||||
" Last Change: 22 Feb 2014.
|
" Last Change: 24 Feb 2014.
|
||||||
"=============================================================================
|
"=============================================================================
|
||||||
" Saving 'cpoptions' {{{
|
" Saving 'cpoptions' {{{
|
||||||
scriptencoding utf-8
|
scriptencoding utf-8
|
||||||
@ -828,13 +828,27 @@ function! s:PromptUser(groups) "{{{
|
|||||||
let coord_key_dict = s:CreateCoordKeyDict(a:groups)
|
let coord_key_dict = s:CreateCoordKeyDict(a:groups)
|
||||||
|
|
||||||
for dict_key in sort(coord_key_dict[0])
|
for dict_key in sort(coord_key_dict[0])
|
||||||
let target_key = coord_key_dict[1][dict_key]
|
" NOTE: {{{
|
||||||
|
" let g:EasyMotion_keys = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
||||||
|
" Perform <Plug>(easymotion-w)
|
||||||
|
"
|
||||||
|
" lines[line_num]['orig']:
|
||||||
|
" Lorem ipsum dolor sit amet consectetur adipisicing
|
||||||
|
"
|
||||||
|
" {target_char}:
|
||||||
|
" {L}orem {i}psum {d}olor {s}it {a}met {c}onsectetur {a}dipisicing
|
||||||
|
"
|
||||||
|
" lines[line_num]['marker'], {marker_chars}:
|
||||||
|
" {A}orem {B}psum {C}olor {D}it {E}met {F}onsectetur {G}dipisicing
|
||||||
|
" 2-key-combo: {marker_chars} could be 1 or 2 chars like {AB}
|
||||||
|
"
|
||||||
|
" }}}
|
||||||
|
|
||||||
|
" Prepare original line and marker line {{{
|
||||||
let [line_num, col_num] = split(dict_key, ',')
|
let [line_num, col_num] = split(dict_key, ',')
|
||||||
|
|
||||||
let line_num = str2nr(line_num)
|
let line_num = str2nr(line_num)
|
||||||
let col_num = str2nr(col_num)
|
let col_num = str2nr(col_num)
|
||||||
|
|
||||||
" Add original line and marker line
|
|
||||||
if ! has_key(lines, line_num)
|
if ! has_key(lines, line_num)
|
||||||
let current_line = getline(line_num)
|
let current_line = getline(line_num)
|
||||||
let lines[line_num] = {
|
let lines[line_num] = {
|
||||||
@ -842,63 +856,71 @@ function! s:PromptUser(groups) "{{{
|
|||||||
\ 'marker': current_line,
|
\ 'marker': current_line,
|
||||||
\ 'mb_compensation': 0,
|
\ 'mb_compensation': 0,
|
||||||
\ }
|
\ }
|
||||||
endif
|
" mb_compensation -> multibyte compensation
|
||||||
|
endif "}}}
|
||||||
|
|
||||||
|
" Multibyt Compensation: {{{
|
||||||
" Solve multibyte issues by matching the byte column
|
" Solve multibyte issues by matching the byte column
|
||||||
" number instead of the visual column
|
" number instead of the visual column
|
||||||
let col_num -= lines[line_num]['mb_compensation']
|
|
||||||
|
|
||||||
" Compensate for byte difference between marker
|
" Compensate for byte difference between marker
|
||||||
" character and target character
|
" character and target character
|
||||||
"
|
"
|
||||||
" This has to be done in order to match the correct
|
" This has to be done in order to match the correct
|
||||||
" column; \%c matches the byte column and not display
|
" column; \%c matches the byte column and not display
|
||||||
" column.
|
" column.
|
||||||
let target_char_len = strdisplaywidth(
|
let col_num -= lines[line_num]['mb_compensation']
|
||||||
\ matchstr(lines[line_num]['marker'],
|
"}}}
|
||||||
\ '\%' . col_num . 'c.'))
|
|
||||||
let target_key_len = strdisplaywidth(target_key)
|
|
||||||
|
|
||||||
|
" Prepare marker characters {{{
|
||||||
|
let marker_chars = coord_key_dict[1][dict_key]
|
||||||
|
let marker_chars_len = EasyMotion#helper#strchars(marker_chars)
|
||||||
|
let marker_chars_first = matchstr(marker_chars, '^.')
|
||||||
|
let marker_chars_first_byte_len = strlen(marker_chars_first)
|
||||||
|
"}}}
|
||||||
|
|
||||||
let target_line_byte_len = strlen(lines[line_num]['marker'])
|
" Prepare targets characters {{{
|
||||||
|
" Get target_char by compensated line.
|
||||||
" let target_char_byte_len = strlen(matchstr(
|
let target_char = matchstr(lines[line_num]['marker'],
|
||||||
" \ lines[line_num]['marker'],
|
\ '\%' . col_num . 'c.')
|
||||||
" \ '\%' . col_num . 'c.'))
|
let target_char_disp_len = strdisplaywidth(target_char)
|
||||||
|
let target_char_byte_len = strlen(target_char)
|
||||||
|
" Original target_line
|
||||||
|
let target_line_byte_len = strlen(lines[line_num]['orig'])
|
||||||
|
"}}}
|
||||||
|
|
||||||
if strlen(lines[line_num]['marker']) > 0
|
if strlen(lines[line_num]['marker']) > 0
|
||||||
" Substitute marker character if line length > 0
|
" Substitute marker character if line length > 0
|
||||||
let c = 0
|
let col_add = 0 " Column add byte length
|
||||||
|
" Disable two-key-combo feature?
|
||||||
let marker_max_length = g:EasyMotion_disable_two_key_combo == 1
|
let marker_max_length = g:EasyMotion_disable_two_key_combo == 1
|
||||||
\ ? 1 : 2
|
\ ? 1 : 2
|
||||||
while c < target_key_len && c < marker_max_length
|
let marker_limit = min([marker_chars_len, marker_max_length])
|
||||||
if strlen(lines[line_num]['marker']) >= col_num + c
|
for i in range(marker_limit)
|
||||||
|
if strlen(lines[line_num]['marker']) >= col_num + col_add
|
||||||
" Substitute marker character if line length > 0
|
" Substitute marker character if line length > 0
|
||||||
if c == 0
|
let substitute_expr = i == 0
|
||||||
let lines[line_num]['marker'] = substitute(
|
\ ? marker_chars_first .
|
||||||
\ lines[line_num]['marker'],
|
\ repeat(' ', target_char_disp_len - 1)
|
||||||
\ '\%' . (col_num + c) . 'c.',
|
\ : split(marker_chars, '\zs')[i]
|
||||||
\ strpart(target_key, c, 1) . repeat(' ', target_char_len - 1),
|
|
||||||
\ '')
|
let lines[line_num]['marker'] = substitute(
|
||||||
else
|
\ lines[line_num]['marker'],
|
||||||
let lines[line_num]['marker'] = substitute(
|
\ '\%' . (col_num + col_add) . 'c.',
|
||||||
\ lines[line_num]['marker'],
|
\ escape(substitute_expr,'&'),
|
||||||
\ '\%' . (col_num + c) . 'c.',
|
\ '')
|
||||||
\ strpart(target_key, c, 1),
|
|
||||||
\ '')
|
|
||||||
endif
|
|
||||||
else
|
else
|
||||||
let lines[line_num]['marker'] .= strpart(target_key, c, 1)
|
" EOL
|
||||||
|
let lines[line_num]['marker'] .= split(marker_chars, '\zs')[i]
|
||||||
endif
|
endif
|
||||||
let c += 1
|
let col_add += strlen(split(marker_chars, '\zs')[i])
|
||||||
endwhile
|
endfor
|
||||||
else
|
else
|
||||||
" Set the line to the marker character if the line is empty
|
" Set the line to the marker character if the line is empty
|
||||||
let lines[line_num]['marker'] = target_key
|
let lines[line_num]['marker'] = matchstr(marker_chars, '^.\{,2}')
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" -- Highlight targets ------------------- {{{
|
" -- Highlight targets ------------------- {{{
|
||||||
if target_key_len == 1
|
if marker_chars_len == 1
|
||||||
call EasyMotion#highlight#add_highlight(
|
call EasyMotion#highlight#add_highlight(
|
||||||
\ '\%' . line_num . 'l\%' . col_num . 'c',
|
\ '\%' . line_num . 'l\%' . col_num . 'c',
|
||||||
\ g:EasyMotion_hl_group_target)
|
\ g:EasyMotion_hl_group_target)
|
||||||
@ -908,7 +930,7 @@ function! s:PromptUser(groups) "{{{
|
|||||||
\ g:EasyMotion_hl2_first_group_target)
|
\ g:EasyMotion_hl2_first_group_target)
|
||||||
if g:EasyMotion_disable_two_key_combo != 1
|
if g:EasyMotion_disable_two_key_combo != 1
|
||||||
call EasyMotion#highlight#add_highlight(
|
call EasyMotion#highlight#add_highlight(
|
||||||
\ '\%' . line_num . 'l\%' . (col_num + 1) . 'c',
|
\ '\%' . line_num . 'l\%' . (col_num + marker_chars_first_byte_len) . 'c',
|
||||||
\ g:EasyMotion_hl2_second_group_target)
|
\ g:EasyMotion_hl2_second_group_target)
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
@ -916,7 +938,7 @@ function! s:PromptUser(groups) "{{{
|
|||||||
|
|
||||||
" Add marker/target length difference for multibyte
|
" Add marker/target length difference for multibyte
|
||||||
" compensation
|
" compensation
|
||||||
let lines[line_num]['mb_compensation'] +=
|
let lines[line_num]['mb_compensation'] =
|
||||||
\ (target_line_byte_len - strlen(lines[line_num]['marker']))
|
\ (target_line_byte_len - strlen(lines[line_num]['marker']))
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user