It seems to be somewhat useful, but:
- What is the differences between a_ and i_?
- Currently iw on spaces serves as your a_/i_.
Isn't it enough? If not so, why?
--
To Vim, or not to Vim.
http://whileimautomaton.net/
Does iw (diw, ciw, etc) do what you want? iw it has odd behavior when
using newlines which might not be what you want, but it might work for
tabs and spaces.
* This behaviour is not consistent with the definition of W|word and
paragraph (it seems that when the cursor resides in whitespace the
definition of word and paragraph, bounded from both sides by
corresponding whitespace and not vice versa, are negated)
* This behaviour does not seem to be documented, and is thus not
quite anticipated by the user
* Finally, as objects are not part of the classical vi,
it seems to be easier to introduce whitespace as a new object and free
the def of W|word and paragraph of context dependence.
One gains consistence while not braking backward compatibility.
You can use dviw instead. This will leave the last character of the
whitespace sequence (can be a Tab - type "r " to turn it into a Space).
:h o_v
> * Does not trim vertical whitespace (newlines)
You can use dvip instead. If this leaves a blank line (instead of an
empty line), you can type 0D to make it empty.
> What i had in mind was approximately that
>
> * di_ is the same as diw + additional space, e.g.
>
> textbefore_____<cursor>______textafter --> textbefore
> textafter
See dviw above.
> * while da_ trims also vertical whitespace (if present), e.g.,
>
> _______textbefore______
> ____\n
> ______ \n
> <cursor>
> ___\n
> ___\n
> _______textafter --> textbefore textafter
This is not how text objects work. You can select text, but not edit
text. If the selection between "textbefore" and "textafter" doesn't
contain a Space, there is no way to make "da_" leave a Space afterwards.
> If there is not vertical whitespace, da_ should double the
> functionality of di_.
---------------------------------------------------------------------
The following mapping trims whitespace around the cursor, leaving one
Space or one empty line.
This has been for a long time in my vimrc (note the many bug fixes) ...
nn <silent> drw :<C-U>call DeleteRubbishWhitespace()<CR>
func! DeleteRubbishWhitespace()
" Former "delete reduced word" (a word but one character); but, only
" useful to reduce many SPACES or BLANK LINES to one, as it works
" now. This is a safe command, it does not delete real text!
" BF: now works if some of the blank lines are within a folded area
" BF: now keeps the buffer unmodified if there is no actual change
" BF: does no longer unwanted scrolling
" NF: repeatable with "." (Vimscript #2136)
" BF: didn't work with 've=all'
" BF: '] is bad when no change was made
let savopt = [&ve]
set virtualedit=
let line = getline(".")
if line =~ '^\s*$'
let sav_pos = winsaveview()
let sav_fen = &fen
setlocal nofoldenable
normal! dvip0D
let sav_pos.lnum = line(".")
let &l:fen = sav_fen
call winrestview(sav_pos)
elseif line[col(".")-1] =~ '\s'
normal! zvyiw
if @@ != " "
normal! dviwr m[
" m[ is just to avoid a trailing space
endif
endif
let [&ve] = savopt
silent! call repeat#set("drw")
endfunc
--
Andy