VIM: Determine if function called from visual-block mode -
from within function, how can determined if function called visual-block mode. involves calling function both from:
- normal-mode mapping
- command-line mode
for precise function, luckily behaves identically under either normal/command mode or visual-mode single line selected. more 1 line - a:firstline/lastline
- function not called normal mode.
the problem need know if in visual-block mode, single line or not.
i've tried following no avail:
function! t() range echo [a:firstline, a:lastline] echo [getpos("'<")[1:2], getpos("'>")[1:2]] echo visualmode() echo mode() endfun vnoremap tt :call t()<cr> nnoremap tt :call t()<cr>
output visual-line mode (notice crazy max-int output):
[3, 4] [[3, 1], [4, 2147483647]] v n
i require answers of variety either "can't done" or "step-by-step". no vague do-this do-that finish this... i'm tired of jumping through obscure vim goldberg-esque loopholes accomplish simple tasks not provided built-in functionality, , vim-fu still young.
just invoke function this:
vnoremap tt :call t(visualmode())<cr> nnoremap tt :call t('')<cr>
with empty argument, function invoked normal mode. else, passed character represents visual mode (i.e. v
vs. v
vs. ^v
).
Comments
Post a Comment