How to make pressing TAB key enter a single TAB character in a .py file?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make pressing TAB key enter a single TAB character in a .py file?

Peng Yu
Hi,

I have the following modline in a .py file. When I type TAB, two TAB
characters are entered into the file. How only let one TAB characters
entered? Thanks.

# vim: set noexpandtab tabstop=2:

--
Regards,
Peng

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Nikolay Aleksandrovich Pavlov
2015-08-16 1:27 GMT+03:00 Peng Yu <[hidden email]>:
> Hi,
>
> I have the following modline in a .py file. When I type TAB, two TAB
> characters are entered into the file. How only let one TAB characters
> entered? Thanks.
>
> # vim: set noexpandtab tabstop=2:

Default shiftwidth for Python files is 4 (which is &tabstop * 2 with
your settings, so two tabs). You need to set &shiftwidth option as
well.

>
> --
> Regards,
> Peng
>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Peng Yu
On Saturday, August 15, 2015 at 5:36:44 PM UTC-5, ZyX wrote:
> 2015-08-16 1:27 GMT+03:00 Peng Yu <[hidden email]>:
> > Hi,
> >
> > I have the following modline in a .py file. When I type TAB, two TAB
> > characters are entered into the file. How only let one TAB characters
> > entered? Thanks.
> >
> > # vim: set noexpandtab tabstop=2:

It seems that shiftwidth is not the problem, as I tried the following modline yet a TAB key still is two TAB characters. Could you try it and let me know what is the correct modline? Thanks.

# vim: set noexpandtab tabstop=2 shiftwidth=2:

> Default shiftwidth for Python files is 4 (which is &tabstop * 2 with
> your settings, so two tabs). You need to set &shiftwidth option as
> well.
>
> >
> > --
> > Regards,
> > Peng
> >
> > --
> > --
> > 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 [hidden email].
> > For more options, visit https://groups.google.com/d/optout.
--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Nikolay Aleksandrovich Pavlov
2015-08-16 2:59 GMT+03:00 Peng Yu <[hidden email]>:

> On Saturday, August 15, 2015 at 5:36:44 PM UTC-5, ZyX wrote:
>> 2015-08-16 1:27 GMT+03:00 Peng Yu <[hidden email]>:
>> > Hi,
>> >
>> > I have the following modline in a .py file. When I type TAB, two TAB
>> > characters are entered into the file. How only let one TAB characters
>> > entered? Thanks.
>> >
>> > # vim: set noexpandtab tabstop=2:
>
> It seems that shiftwidth is not the problem, as I tried the following modline yet a TAB key still is two TAB characters. Could you try it and let me know what is the correct modline? Thanks.

There is also &softtabstop. (Actually *it* is the one that contains
how many spaces *TAB* inserts, &shiftwidth is for other things like
`<` or `>` normal commands.) But it defaults to zero (noexpandtab
tabstop=2 shiftwidth=2 softtabstop=0 will make <TAB> insert 2-wide
tab) and I forgot that Python ftplugin modifies default.

>
> # vim: set noexpandtab tabstop=2 shiftwidth=2:
>
>> Default shiftwidth for Python files is 4 (which is &tabstop * 2 with
>> your settings, so two tabs). You need to set &shiftwidth option as
>> well.
>>
>> >
>> > --
>> > Regards,
>> > Peng
>> >
>> > --
>> > --
>> > 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 [hidden email].
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Bram Moolenaar
In reply to this post by Peng Yu

Peng Yu wrote:

> On Saturday, August 15, 2015 at 5:36:44 PM UTC-5, ZyX wrote:
> > 2015-08-16 1:27 GMT+03:00 Peng Yu <[hidden email]>:
> > > Hi,
> > >
> > > I have the following modline in a .py file. When I type TAB, two TAB
> > > characters are entered into the file. How only let one TAB characters
> > > entered? Thanks.
> > >
> > > # vim: set noexpandtab tabstop=2:
>
> It seems that shiftwidth is not the problem, as I tried the following modline yet a TAB key still is two TAB characters. Could you try it and let me know what is the correct modline? Thanks.
>
> # vim: set noexpandtab tabstop=2 shiftwidth=2:

You probably have 'softtabstop' set to the wrong value.

Note that most people recommend using a tabstop of 8 in Python files, or
no tabs at all.  Doing otherwise is likely to get you in trouble some
day.

--
There can't be a crisis today, my schedule is already full.

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Nikolay Aleksandrovich Pavlov
2015-08-16 16:23 GMT+03:00 Bram Moolenaar <[hidden email]>:

>
> Peng Yu wrote:
>
>> On Saturday, August 15, 2015 at 5:36:44 PM UTC-5, ZyX wrote:
>> > 2015-08-16 1:27 GMT+03:00 Peng Yu <[hidden email]>:
>> > > Hi,
>> > >
>> > > I have the following modline in a .py file. When I type TAB, two TAB
>> > > characters are entered into the file. How only let one TAB characters
>> > > entered? Thanks.
>> > >
>> > > # vim: set noexpandtab tabstop=2:
>>
>> It seems that shiftwidth is not the problem, as I tried the following modline yet a TAB key still is two TAB characters. Could you try it and let me know what is the correct modline? Thanks.
>>
>> # vim: set noexpandtab tabstop=2 shiftwidth=2:
>
> You probably have 'softtabstop' set to the wrong value.
>
> Note that most people recommend using a tabstop of 8 in Python files, or
> no tabs at all.  Doing otherwise is likely to get you in trouble some
> day.

I used &tabstop=4 in powerline with noexpandtab for years. No
troubles. Just don’t try to mix tabs and spaces, in case you do note
that Python thinks that 1 tab is 8 spaces. If all indentation is
consistent there will be no troubles.

>
> --
> There can't be a crisis today, my schedule is already full.
>
>  /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
> ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
> \\\  an exciting new programming language -- http://www.Zimbu.org        ///
>  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
>
> --
> --
> 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 [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: How to make pressing TAB key enter a single TAB character in a .py file?

Grady Martin
On 2015年08月16日 16時54分, Nikolay Pavlov wrote:
>2015-08-16 16:23 GMT+03:00 Bram Moolenaar <[hidden email]>:
>> Note that most people recommend using a tabstop of 8 in Python files, or
>> no tabs at all.  Doing otherwise is likely to get you in trouble some
>> day.
>
>I used &tabstop=4 in powerline with noexpandtab for years. No
>troubles. Just don’t try to mix tabs and spaces, in case you do note
>that Python thinks that 1 tab is 8 spaces. If all indentation is
>consistent there will be no troubles.

I concur.  Mixing tabs and spaces is what gets people into trouble, not the number of space characters a tab represents.  With regards to Python, I keep the following in $HOME/.vim/after/ftplugin/python.vim:

setlocal noexpandtab shiftwidth=4 softtabstop=0 tabstop=4

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.