On 2013-09-24, Christian Brabandt wrote:
> On Di, 24 Sep 2013, Gary Johnson wrote:
> 
> > I've discovered that with 'cindent' set and with 'cinkeys'
> > containing 0# as it does by default, the >> command has no effect on
> > a line having a # in column 1.
> > 
> > To demonstrate this, start Vim as
> > 
> >     vim -N -u NONE
> > 
> > and enter this line with the # in column 1:
> > 
> >     #define this
> > 
> > Type >> and <<.  Note that the line shifts to the right and left.
> > 
> > Now execute
> > 
> >     :set cindent
> > 
> > and type >>.  Note that the line does not move.
> > 
> > Execute
> > 
> >     :set cinkeys-=0#
> > 
> > and type >> again.  The line shifts to the right.
> > 
> > I've observed this on Linux using vim version 7.2.148 as well as
> > 7.4.27, so this is not a new problem and may well have existed from
> > the beginning.
> > 
> > Granted, this is a minor problem that I've just now encountered
> > after having used Vim for many years; it's just annoyingly
> > interfering with what I'm trying to do at the moment.
> 
> That happens on purpose. See op_shift():
> 
> ,----[ ops.c ]-
> | [...]
> | 248     for (i = oap->line_count; --i >= 0; )
> | 249     {
> | 250         first_char = *ml_get_curline();
> | 251         if (first_char == NUL)                          /* empty line */
> | 252             curwin->w_cursor.col = 0;
> | 253 #ifdef FEAT_VISUALEXTRA
> | 254         else if (oap->block_mode)
> | 255             shift_block(oap, amount);
> | 256 #endif
> | 257         else
> | 258             /* Move the line right if it doesn't start with '#', 
> 'smartindent'
> | 259              * isn't set or 'cindent' isn't set or '#' isn't in 'cino'. 
> */
> | 260 #if defined(FEAT_SMARTINDENT) || defined(FEAT_CINDENT)
> | 261             if (first_char != '#' || !preprocs_left())
> | 262 #endif
> | 263         {
> | 264             shift_line(oap->op_type == OP_LSHIFT, p_sr, amount, FALSE);
> | 265         }
> | 266         ++curwin->w_cursor.lnum;
> | 267     }
> | [...]
> `----
> 
> I guess, the intention is, that in C code the defines need to be in the 
> first column.

Thanks for checking that.

It's odd, though.  K&R, 2nd Ed., says:

    A12.  Preprocessing

    A preprocessor performs macro substitution, conditional
    compilation, and inclusion of named files.  Lines beginning with
    #, perhaps preceded by white space, communicate with this
    preprocessor.

Vim's behavior looks to me like a mistake in someone's understanding
of C.

I could see an indentation function moving lines beginning with # to
the left, but preventing the user from executing a command to
deliberately shift a line seems a little extreme.

Regards,
Gary

-- 
-- 
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Raspunde prin e-mail lui