Is there a text object for current line?
Is there a text object for
Here is a crude "line" text-objects:
xnoremap il g_o0 onoremap il :normal vil<CR> xnoremap al $o0 onoremap al :normal val<CR>
And a crude "buffer" text-object:
xnoremap i% GoggV onoremap i% :normal vi%<CR>
An "operator" is a command that doesn't do anything by itself:
Pressing those keys put you in "operator-pending mode", where Vim waits for you to tell it what you want it to operate on… with an "operator-pending motion".
You can use
:onoremap to define custom operator-pending motions. The technique used here is inspired by
- you define a visual mode mapping that covers the desired area,
- you use that mapping in an operator-pending mapping.
Note that I used
i% don't already exist. If you are overriding an existing motion or text-object — say
ip — you must use a recursive mapping:
:help :map-operator describes a slightly more advanced method.
:help v_o for
o in visual mode.
I would suggest an additional solution, to use ^ instead of 0 (so the line starts at the beginning of the first character:
xnoremap il g_o^ onoremap il :normal vil<CR> xnoremap al $o^ onoremap al :normal val<CR>
This way if we do "change in line" it will respect the indentation level.