I'm writing what may become a plugin that needs to know what is currently visually selected.
To do it, I'm using the
autocmd CursorMoved event to detect the creation of
visual mode selections on the fly. So far, it works well enough, but for some
reason if I make a visual selection using
vap this isn't picked up
by the autocmd even though the cursor moves position.
I think this is because in my code below I only check for
mode() == 'v' (i.e.
is visual mode character-wise) and
vip could be a line-wise visual selection.
Other text objects (like
viw and the like) work fine as do regular
I wonder if perhaps it's a bug in Vim? If not, what is the correct way to
vip has been executed in visual mode? I can't find any other
autocmd that does the job.
Here are the relevant sections of code if it helps:
function! Update_visual_mark_list() if mode() ==# 'v' " exit visual mode normal! v " get end points of last visual selection let [_, l1, c1, _] = getpos("'<") let [_, l2, c2, _] = getpos("'>") " do some stuff " go back to last visual selection normal! gv endif endfunction augroup visual_walk autocmd! autocmd CursorMoved * call Update_visual_mark_list() augroup END