Loading ...
Sorry, an error occurred while loading the content.

Re: Treat spaces as tabs only at the start of the line

Expand Messages
  • Gerardo Marset
    ... Thanks for the suggestion, but how could I insert a BS in the line without returning the function? -- You received this message from the vim_use
    Message 1 of 7 , Jul 1 11:12 AM
    • 0 Attachment
      On Sunday, July 1, 2012 1:29:49 PM UTC-3, Ben Fritz wrote:
      > On Saturday, June 30, 2012 5:34:35 PM UTC-5, Gerardo Marset wrote:
      > > I have sofftabstop (and shiftwidth) set to 4, and expandtab enabled. Thus, when deleting groups of spaces, vim treats them as tabs and deletes them 4 at a time. I want vim to do that only if from the start of the line and up to the cursor's position there's only spaces and nothing else.
      > > Currently I'm doing the following:
      > >
      > > inoremap <silent> <BS> <C-R>=fbs()<CR>
      > >
      > > function fbs()
      > > if getline('.') =~ '^ \{' . (col('.') - 1) . '}'
      > > return "\<BS>"
      > > endif
      > > return "\<Left>\<Del>"
      > > endfunction
      > >
      > > It works, but it breaks the repeat (dot) command, and I don't want that :). I think it's because of the <Left>. Any help (either modifying the previous code so that it doesn't break the dot command or coming up with a new one that doesn't) is appreciated.
      >
      > You might try determining how many characters got deleted (getline in combination with your cursor position command may help here) and insert enough characters after the BS to make up for the difference. The thing interrupting your undo sequence (and therefore messing up your repeat command, '.') is the <Left> key, so you just need to avoid doing that. Dropping out of insert mode (even temporarily with <C-O>) will do the same thing unfortunately, and using setline() or setpos() is possible but will not be reflected in the repeat sequence without a lot of effort and additional mappings.

      Thanks for the suggestion, but how could I insert a BS in the line without returning the function?

      --
      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
    • Ben Fritz
      ... You can return the , that s not one of the things that break insert mode. ... You should be able to use your current = mapping, or an
      Message 2 of 7 , Jul 1 9:21 PM
      • 0 Attachment
        On Sunday, July 1, 2012 1:12:05 PM UTC-5, Gerardo Marset wrote:
        >
        > Thanks for the suggestion, but how could I insert a BS in the line without returning the function?

        You can return the <BS>, that's not one of the things that break insert mode.

        :help ins-special-special gives the list of things that do.

        You should be able to use your current <C-R>= mapping, or an <expr> mapping, to return <BS> plus an appropriate number of spaces.

        --
        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
      • Gerardo Marset
        ... Hmm... yes, I guess I could do it, but determining the appropriate number of spaces seems to get quite complicated. Vim seems to remove a single space if,
        Message 3 of 7 , Jul 4 5:27 PM
        • 0 Attachment
          On Monday, July 2, 2012 1:21:57 AM UTC-3, Ben Fritz wrote:
          > On Sunday, July 1, 2012 1:12:05 PM UTC-5, Gerardo Marset wrote:
          > >
          > > Thanks for the suggestion, but how could I insert a BS in the line without returning the function?
          >
          > You can return the <BS>, that's not one of the things that break insert mode.
          >
          > :help ins-special-special gives the list of things that do.
          >
          > You should be able to use your current <C-R>= mapping, or an <expr> mapping, to return <BS> plus an appropriate number of spaces.

          Hmm... yes, I guess I could do it, but determining the appropriate number of spaces seems to get quite complicated.
          Vim seems to remove a single space if, between tab and space, space was the last key pressed in the current insert mode.
          I would have to map space to set a variable (l:space_last_pressed or something) to true, and also map Esc and Tab to set it to false, then use the variable's value to know how many spaces to make up for.
          A mess.

          As I said, I guess I could do it, but isn't there another way? :/

          --
          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
        Your message has been successfully submitted and would be delivered to recipients shortly.