Menu

#191 a" and a' grab extraneous whitespace

Major
closed-invalid
nobody
None
5
2016-09-23
2016-09-23
Alex Korn
No

When using v, c, or d (highlight, change, or delete), then a (around) quotation marks (", ', or backtick), extraneous whitespace around the quoted text will get highlighted or deleted, unlike what happens with [], {}, etc.

Examples are below on what gets highlighted/changed/deleted (using generic "highlighted" below) when running a command while the cursor is on "test".

// BAD
$var = 'test'; // 'test' is highlighted *as well as the space before it*
$var = "test"; // (same as above)
$var = `test`; // (same as above)
$var = "test" ; // "test" is highlighted *as well as the space after it*, but not the space before it
// GOOD
$var = [test]; // [test] is highlighted, and not the space before it
$var = (test); // (same as above)
$var = {test}; // (same as above)
$var = <test>;
$var = [test] ; // [test] is highlighted, and not the space before or after it

I would expect quotation marks to follow the same "a" rules as brackets.

Discussion

  • Ernie Rael

    Ernie Rael - 2016-09-23

    Yeah, I would expect that too. But it doesn't. Here's the help taken from vim8.0. In particular, note the sentence "Any trailing white space is included, unless there is none, then leading white space is included."

    a"                          *v_aquote* *aquote*
    a'                          *v_a'* *a'*
    a`                          *v_a`* *a`*
                "a quoted string".  Selects the text from the previous
                quote until the next quote.  The 'quoteescape' option
                is used to skip escaped quotes.
                Only works within one line.
                When the cursor starts on a quote, Vim will figure out
                which quote pairs form a string by searching from the
                start of the line.
                Any trailing white space is included, unless there is
                none, then leading white space is included.
                When used in Visual mode it is made characterwise.
                Repeating this object in Visual mode another string is
                included.  A count is currently not used.
    
     
    • Alex Korn

      Alex Korn - 2016-09-23

      Gotcha - I guess that rule makes sense for non-coding situations. At least I understand the justification and won't be cursing you for some off-by-one error or something!

      And in case anyone else stumbles across this, here's a link for the documentation:
      http://vimdoc.sourceforge.net/htmldoc/motion.html#v_aquote

       
  • Ernie Rael

    Ernie Rael - 2016-09-23
    • status: open --> closed-invalid
     

Log in to post a comment.