From 0df8dac0532e7e72a07c43480c1193a81e5a644e Mon Sep 17 00:00:00 2001 From: David Perry Date: Sun, 19 Jan 2020 18:10:45 -0500 Subject: [PATCH] Support `move-[nNpP]` when patterns is a list This patch allows `move-n` etc. to work when a textobject is defined using a list with separate start and end patterns. Without this fix, an error is generated when the keybind is pressed for moving between these objects. --- autoload/textobj/user.vim | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/autoload/textobj/user.vim b/autoload/textobj/user.vim index 9518b09..19e7dfd 100644 --- a/autoload/textobj/user.vim +++ b/autoload/textobj/user.vim @@ -523,10 +523,10 @@ function! s:plugin.do_by_pattern(spec_name, obj_name, previous_mode) endfunction let s:PATTERN_IMPL_TABLE = { -\ 'move-n': 's:move_wrapper', -\ 'move-N': 's:move_wrapper', -\ 'move-p': 's:move_wrapper', -\ 'move-P': 's:move_wrapper', +\ 'move-n': 's:move_wrapper_start', +\ 'move-N': 's:move_wrapper_end', +\ 'move-p': 's:move_wrapper_start', +\ 'move-P': 's:move_wrapper_end', \ 'select': 'textobj#user#select', \ 'select-a': 's:select_pair_wrapper', \ 'select-i': 's:select_pair_wrapper', @@ -542,10 +542,27 @@ let s:PATTERN_FLAGS_TABLE = { \ 'select-i': 'i', \ } -function! s:move_wrapper(patterns, flags, previous_mode) +function! s:move_wrapper_start(patterns, flags, previous_mode) " \x16 = CTRL-V + let pat = a:patterns + if type(pat) == type([]) + let pat = pat[0] + endif + call textobj#user#move( + \ pat, + \ substitute(a:flags, '[vV\x16]', '', 'g'), + \ a:previous_mode + \ ) +endfunction + +function! s:move_wrapper_end(patterns, flags, previous_mode) + " \x16 = CTRL-V + let pat = a:patterns + if type(pat) == type([]) + let pat = pat[1] + endif call textobj#user#move( - \ a:patterns, + \ pat, \ substitute(a:flags, '[vV\x16]', '', 'g'), \ a:previous_mode \ )