Tuesday, November 27, 2012

Re: Custom whitespace handling for cut and paste

Am 27.11.2012 15:26, schrieb KamilS:
> I primarily use Vim for LaTeX, i.e. for editing text rather than code,
> and I was wondering if it's possible to make Vim handle whitespace in
> a smarter way when cutting and pasting in in .tex files.
>
> In particular, I would like to see the kind of behaviour I know and
> love from Adobe InDesign. Let me give you an example:
>
> Sentence one. Sentence two. Sentence three.
>
> Now, if I select "Sentence two." (just this much, without the
> surrounding spaces) and cut it, InDesign will automatically delete one
> of the two remaining subsequent spaces. If I then paste it between
> "Sentence" and "three", never mind on which side of the space between
> them, InDesign will automatically add the missing space before or
> after it.
>
> The same happens with single words. Which makes sense because when you
> write text, you want to cut and paste words most of the time, not just
> bits of words.
>
> Is it possible to implement this kind of behaviour in Vim and limit it
> to .tex files? Or is there perhaps a plugin for it already, only I
> couldn't find it?

I've created smartput.vim for this purpose. It adjusts spaces when text
is pasted (or `put' in vimspeak) (rather than when text is deleted).

That works fine with Vim's sentence text objects
:h as
:h is
and motions
:h (
:h )
which (when deleting text) either let you decide how much whitespace to
include (`is' vs. `as') or include the whitespace after a sentence
(`)').

When putting a word between other words (or in the middle of a word),
smartput inserts spaces around the inserted word.

Smartput is a global plugin, you can enable/disable it globally (by a
key `<Leader>st') or turn it off for a filetype where it is unwanted
(this is a little different from what you want).

There are rules (global or buffer-local variables) to adjust when to
insert/remove a space ... yet this system is not as flexible (and user
friendly ^^) as it could be.

Yep, smartput.vim is quite old (omg, last update 2007-12-16, sorry), but
it should do what you want. I use it myself all the time (a modified,
half-way-ready unreleased version though).

--
Andy

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: