Saturday, May 30, 2015

Re: quotation text object consternation

Hi Tim!

On Fr, 29 Mai 2015, Tim Chase wrote:

> One of the oddball frustrations I find with vim is that the
> outer-quotation objects eats leading space.
>
> To demonstrate the inconsistency, use the following document
>
> (parens)
> [square brackets]
> {braces}
> "double quotes"
> 'single quotes"
>
> and indent it (unless you copied the leading whitespace too)
>
> :%>
>
> then, on each line, use the associated outer-text-object to change it:
>
> ca(xxx<esc>
> ca[xxx<esc>
> ca{xxx<esc>
> ca"xxx<esc>
> ca'xxx<esc>
>
> Note how the ones with quotes also get un-indented while the others
> don't. I encounter this most frequently when coding in Python where
> I have something like
>
> my_map = {
> "foo": "bar",
> "baz": "whinge",
> "fred": "barney",
> }
>
> and I want to change the keys to constants:
>
> FOO = "foo"
> my_map = {
> FOO: "bar",
> # ...
> }
>
> so I go to the quote object and do
>
> ca"FOO<esc>
>
> only to then need to re-indent it back to the original level (not so
> bad if it's single indent, but when it's multiple levels, it's a
> pain). I've *never* had the eating-of-leading-whitespace as a desired
> behavior.
>
> Is there a way to make this consistent with the other "a" text
> objects? Some option I've missed?

I am not sure. But let's look at the documentation:

,----[ :h text-object (and scroll down a bit) ]-
| For non-block objects:
| For the "a" commands: The operator applies to the object and the white
| space after the object. If there is no white space after the object
| or when the cursor was in the white space before the object, the white
| space before the object is included.
`----

Here is an idea:
Perhaps you can try to always put some whitespace after the quotes, so
that accessing the objects won't use the whitespace in front of it.

Then doing ca' will not un-indent the object. Perhaps, you could even
map that to a function that first adds whitespace before trying to
access that object?

Best,
Christian
--
Was zugunsten des Staates begonnen wird, geht oft zuungunsten der Welt
aus.
-- Karl Kraus

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment