On 9月10日, 上午12时19分, "Benjamin R. Haskell" <[email protected]> wrote:
> On Thu, 9 Sep 2010, Christian Brabandt wrote:
> > On Thu, September 9, 2010 11:36 am, livim wrote:
> >> I can't understand " It might be nice to have tabs after the first non-
> >> blank inserted as spaces if you do this though. "
> >> Who can give me some illustration?
>
> > imap <expr> <tab> getline('.')[0:col('.')-1]=~'^\s*$'?'<tab>' : repeat(' ', 
> > &ts)
>
> Cool.  You lose the 'tabbyness', though.  This modification adds a tab
> (if no nonwhitespace so far) or enough spaces to put the cursor at the
> next tabstop:
>
> imap <expr> <tab> getline('.')[0:col('.')-1] !~ '\S' ? '<tab>'
> \ : repeat(' ', &ts-((col('.')-1) % &ts))
>
> To the OP, for an example of why the concept is useful, see the file
> below, which is indented with tabs.
>
> >> indicates where <tab> was pressed to insert spaces when 'tabstop' was 6 
> >> (using the above mapping).
>
> Set tabstop to different values:
> :se ts=2
> :se ts=9
> to see that the vertically aligned '=' signs stay aligned.
>
> ===> simple-tab-example.c <===
> int main(void) {
>         int i>>     = 10;
>         float f>>   = 20;
>         if (1) {
>                 int asdf>> = 1;
>                 int j>>    = 1;
>         }
>         return 0;}
>
> /* vim:set listchars=tab\:│_ ts=6 sts=0: */
>
> --
> Best,
> Ben




Thank you so much!

But it still has some problem:     repeat(' ', &ts-((col('.')-1) %
&ts))
when ts=8,
if the first character of the line is '\t' , then the second character
's  column position   (col('.'))   is 2 , not 9 !
Maybe we shall use a function which will return the virtual column
number.


Besides, in your simple-tab-example.c , if you have used that mapping,
why it didn't generate any '\t' at the beginning of lines?     "(if no
nonwhitespace so far)"

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

Reply via email to