:h motion.txt, it says:
FORCING A MOTION TO BE LINEWISE, CHARACTERWISE OR BLOCKWISE When a motion is not of the type you would like to use, you can force another type by using "v", "V" or CTRL-V just after the operator. Example: > dj deletes two lines > dvj deletes from the cursor position until the character below the cursor > d<C-V>j deletes the character under the cursor and the character below the cursor. >
To ignore the starting cursor position and select different text, you can have the omap start Visual mode to select the text to be operated upon. Example that operates on a function name in the current line: > onoremap <silent> F :<C-U>normal! 0f(hviw<CR>
:h movement for what can be used as a motion
- Ex commands can be used to move the cursor. This can be used to call a function that does some complicated motion. The motion is always characterwise exclusive, no matter what ":" command is used. This means it's impossible to include the last character of a line without the line break (unless 'virtualedit' is set).
However, when these are combined:
- the motion is an Ex command; and
- the Ex command select an visual area;
the overwrite will not has an effect; e.g. the overwrite
V in the following command
will not be able to change the motion to be linewise.
Now I want to define an textobject, for example
function! s:motion() " set the marks here return ":\<c-u>normal! `[v`]\<cr>" endfunction omap <expr> X s:motion()
to visually select the area. But I still want the motion wiseness of the textobject can be overwritten by
<C-V>. For example:
dX " to work characterwise dvX " to work characterwise, exclusive dVX " to work linewise d<c-v>X " to work blockwise " can we get the overwrite v or V or <c-v> inside s:motion()? so that we can do function! s:motion() " set the marks here let overwrite = ?? return printf(":\<c-u>normal! `[%s`]\<cr>", overwrite) endfunction
- Is it possible to achieve this without defining four different maps for
- If the overwritten mode
<c-v>can be returned by a function, then the problem solves. But I cannot find such a function.
- Alternatively, can we select an area without using Ex command such as