pepegnu schrieb:
> You're quite right,  though diw does the job
>
>       * only for spaces and tabs, but does not trim, i.e. it leaves
> the words glued together, e.g.,
>
>         textbefore_____<cursor>______textafter   -->
> textbeforetextafter
>
>          which requires typing an aditional space

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

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui