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

Auto indent lost when opening a new file?

Expand Messages
  • François Ingelrest
    Hello all, This is something that annoys me a lot, and I don t know how to get rid of it: as soon as I open a new file, auto indentation is lost. Suppose I am
    Message 1 of 4 , Mar 1, 2007
    View Source
    • 0 Attachment
      Hello all,

      This is something that annoys me a lot, and I don't know how to get
      rid of it: as soon as I open a new file, auto indentation is lost.
      Suppose I am editing a Python file:

      def func():

      If I hit enter after this line, the cursor will be placed on the next
      line with correct indentation. Now suppose I open a new Python file by
      using :E. If I try to do the same thing, the cursor is no longer
      correctly indented when I create new lines, i.e., it is always placed
      at the beginning of the new line. Syntax highlight is still ok, only
      auto indentation is lost.

      Is it possible to correct that behavior?
    • Yakov Lerner
      ... Do you have autocommands in the spirit of au BufNewFile ... in your vimrc that disable autoindenting ? You can try to find and erase those autocommands.
      Message 2 of 4 , Mar 1, 2007
      View Source
      • 0 Attachment
        On 3/1/07, François Ingelrest <athropos@...> wrote:
        > Hello all,
        >
        > This is something that annoys me a lot, and I don't know how to get
        > rid of it: as soon as I open a new file, auto indentation is lost.
        > Suppose I am editing a Python file:
        >
        > def func():
        >
        > If I hit enter after this line, the cursor will be placed on the next
        > line with correct indentation. Now suppose I open a new Python file by
        > using :E. If I try to do the same thing, the cursor is no longer
        > correctly indented when I create new lines, i.e., it is always placed
        > at the beginning of the new line. Syntax highlight is still ok, only
        > auto indentation is lost.
        >
        > Is it possible to correct that behavior?

        Do you have autocommands in the spirit of 'au BufNewFile ...'
        in your vimrc that disable autoindenting ?

        You can try to find and erase those autocommands. Or you
        you can try to fix it without searching for the culprit:

        au BufRead * set autoindent cindent smartindent " add to vimrc
        au BufRead * filetype plugin indent on " add to vimrc

        Does it work for you ?
        Yakov
      • François Ingelrest
        Thank you very much for your answer. I have these lines in my .vimrc: if has( autocmd ) au BufRead,BufNewFile *.cls set filetype=tex au BufRead,BufNewFile
        Message 3 of 4 , Mar 1, 2007
        View Source
        • 0 Attachment
          Thank you very much for your answer. I have these lines in my .vimrc:

          if has("autocmd")
          au BufRead,BufNewFile *.cls set filetype=tex
          au BufRead,BufNewFile sconstruct set filetype=python

          " Nes C syntax (used by TinyOS)
          au BufRead,BufNewFile *.nc set filetype=nesc
          au! Syntax nesc source ~/.vim/nesc.vim
          endif

          I use them to force a filetype for some files. Shouldn't I do that?
          I added your line among mine:

          au BufRead * set autoindent cindent smartindent

          And now it's working correctly. As I understand it, these options are
          disabled because I didn't add them to my other lines? But in this
          case, why other options aren't also disabled?
        • Yakov Lerner
          ... It s not abvious whether any of your commands above break auto-indenting or not. The only way to know is if you comment them all out (first all of them,
          Message 4 of 4 , Mar 1, 2007
          View Source
          • 0 Attachment
            On 3/1/07, François Ingelrest <athropos@...> wrote:
            > Thank you very much for your answer. I have these lines in my .vimrc:
            >
            > if has("autocmd")
            > au BufRead,BufNewFile *.cls set filetype=tex
            > au BufRead,BufNewFile sconstruct set filetype=python
            >
            > " Nes C syntax (used by TinyOS)
            > au BufRead,BufNewFile *.nc set filetype=nesc
            > au! Syntax nesc source ~/.vim/nesc.vim
            > endif
            >
            > I use them to force a filetype for some files. Shouldn't I do that?

            It's not abvious whether any of your commands above
            break auto-indenting or not. The only way to know is if you
            comment them all out (first all of them, them one-by one)
            and see if it changes anything wrt auto-indenting.
            (Also comment out the new command you added today for this check),

            Yakov

            > I added your line among mine:
            >
            > au BufRead * set autoindent cindent smartindent
            >
            > And now it's working correctly. As I understand it, these options are
            > disabled because I didn't add them to my other lines? But in this
            > case, why other options aren't also disabled?
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.