problem with backspace

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

problem with backspace

rameo
I would like to have tabstop = 4 and only spaces (no tabs).
I added this in my vimrc:
set tabstop = 4
set expandtab

Everything works fine... however.
The backspace key goes only 1 space back now and not 4 spaces.

How can I change this?
Is there a solution?

--
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 | Threaded
Open this post in threaded view
|

Re: problem with backspace

Tim Chase
On 10/25/2010 08:48 AM, rameo wrote:
> I would like to have tabstop = 4 and only spaces (no tabs).
> I added this in my vimrc:
> set tabstop = 4
> set expandtab
>
> Everything works fine... however.
> The backspace key goes only 1 space back now and not 4 spaces.

Well, you're deleting the one-space which is there, which is both
the behavior I would expect and the behavior I'd want since
backspace deletes one character.

A couple ideas:

1) less palatable may be to use tabs instead of spaces (i.e. set
'noexpandtab') where one backspace deletes one tab.  This could
be pared with post-read and pre-write auto-commands to exchange
tabs for spaces so the file-contents are what you want.

2) learn to love ^D and ^T

   :help i_CTRL-D
   :help i_CTRL-T

(in the same place, the help also describes the "0" and "^"
prefixes to ^D  clearing leading whitespace)  I use ^D and 0^D
regularly, and ^T occasionally.  These also have the added
benefit that they can be used anywhere in the line, not just at
the break between leading-whitespace and the start-of-text.

3) write a more complex mapping for backspace-in-insert-mode that
will sniff the character(s) before the cursor and if there are
&shiftwidth space-characters, delete that many of them.  This is
more complex, apt to hit odd edge-cases, leading to noisome breakage.

Hope this gives you some ideas you can use,

-tim



--
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 | Threaded
Open this post in threaded view
|

Re: problem with backspace

Nikolay Aleksandrovich Pavlov
In reply to this post by rameo
Reply to message «problem with backspace»,
sent 17:48:14 25 October 2010, Monday
by rameo:

> I would like to have tabstop = 4 and only spaces (no tabs).
> I added this in my vimrc:
> set tabstop = 4
> set expandtab
>
> Everything works fine... however.
> The backspace key goes only 1 space back now and not 4 spaces.
See «:h 'backspace'»: you need to include `indent' in this option:
    set backspace+=indent

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: problem with backspace

rameo
On Oct 25, 4:19 pm, ZyX <[hidden email]> wrote:

> Reply to message «problem with backspace»,
> sent 17:48:14 25 October 2010, Monday
> by rameo:
>
> > I would like to have tabstop = 4 and only spaces (no tabs).
> > I added this in my vimrc:
> > set tabstop = 4
> > set expandtab
>
> > Everything works fine... however.
> > The backspace key goes only 1 space back now and not 4 spaces.
>
> See «:h 'backspace'»: you need to include `indent' in this option:
>     set backspace+=indent
>
>  signature.asc
> < 1KViewDownload

Hi Zyx,

This is what I have in my _vimrc:
set backspace=2
set backspace=indent,eol,start whichwrap+=<,>,[,]

Rameo


--
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 | Threaded
Open this post in threaded view
|

Re: problem with backspace

Nikolay Aleksandrovich Pavlov
Reply to message «Re: problem with backspace»,
sent 19:00:10 25 October 2010, Monday
by rameo:

> Hi Zyx,
>
> This is what I have in my _vimrc:
> set backspace=2
> set backspace=indent,eol,start whichwrap+=<,>,[,]
>
> Rameo
I tested my answer and it appears that you should also set «softtabstop» option:
this is the minimal configuration that allows backspace to delete four spaces:
    vim -u NONE --cmd 'set backspace=indent expandtab softtabstop=4'

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: problem with backspace

hsitz-2
In reply to this post by rameo
On Oct 25, 6:48 am, rameo <[hidden email]> wrote:

> I would like to have tabstop = 4 and only spaces (no tabs).
> I added this in my vimrc:
> set tabstop = 4
> set expandtab
>
> Everything works fine... however.
> The backspace key goes only 1 space back now and not 4 spaces.
>
> How can I change this?
> Is there a solution?

I'm not sure why nobody has mentioned the 'smarttab' option, which
seems to be exactly what you're looking for.  It requires you to set
'shiftwidth' to same value as your 'tabstop', but otherwise is
basically dead easy.  Here's help for 'smarttab':

'smarttab' 'sta' boolean (default off)
                        global
                        {not in Vi}
        When on, a <Tab> in front of a line inserts blanks according to
        'shiftwidth'.  'tabstop' or 'softtabstop' is used in other places.  A
        <BS> will delete a 'shiftwidth' worth of space at the start of the
        line.
        When off, a <Tab> always inserts blanks according to 'tabstop' or
        'softtabstop'.  'shiftwidth' is only used for shifting text left or
        right |shift-left-right|.
        What gets inserted (a <Tab> or spaces) depends on the 'expandtab'
        option.  Also see |ins-expandtab|.  When 'expandtab' is not set, the
        number of spaces is minimized by using <Tab>s.
        NOTE: This option is reset when 'compatible' is set.

--
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 | Threaded
Open this post in threaded view
|

Re: problem with backspace

rameo
Zyx, Tim, hsitz, thank you all for your help.
I tried sofftabstop and it works fine!
I learned also from the other messages. :)

Regards,
Rameo

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