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

Re: indenting python docstring in vim

Expand Messages
  • Zetah Ghamin
    ... Did not work. I already have filetype indent on. When I first noticed this problem, that s what I checked with the command filetype: filetype detection:ON
    Message 1 of 11 , Apr 4 10:12 AM
    • 0 Attachment
      On Tuesday, April 3, 2012 7:52:17 PM UTC-7, Zvezdan Petkovic wrote:
      > On Apr 3, 2012, at 10:08 PM, Zvezdan Petkovic wrote:
      >
      > > Now, I'll dig into this and find which setting fixes the issues you see by gradually returning things in place. I'll narrow this down this evening probably.
      >
      >
      > I found what's causing this behavior.
      > My customizations for Python are not doing anything special.
      > The docstring is indented correctly even when ~/.vim is empty.
      >
      > However, when I comment out one line in my .vimrc file the indentation changes.
      >
      > It seems that you are missing this kind of setting in your ~/.vimrc file (I put it at the very end of that file):
      >
      > if has("autocmd")
      > " Enable file type detection, plugins, and indentation rules.
      > filetype plugin indent on
      > " ^^^^^^ DOES NOT WORK WITHOUT THAT LINE ^^^^^^
      > " ...
      > " vvvvvv You mentioned you have something like this already vvvvvv
      > " C++, Java, JavaScript, Perl, Python and Tcl indent.
      > autocmd FileType cpp,java,javascript,perl,python,tcl setl sw=4 sts=4 et
      > " ...
      > " vvvvvv I keep also this for doctests vvvvvv
      > " reStructuredText (Python doctest) indent.
      > autocmd FileType rst setlocal sw=4 sts=4 et tw=72
      > " When editing a file, always jump to the last known cursor position.
      > autocmd BufReadPost *
      > \ if line("'\"") > 0 && line("'\"") <= line("$") |
      > \ execute "normal g`\"" |
      > \ endif
      > endif
      >
      > *****
      > You must have "filetype plugin indent on" to get the indent to work properly.
      > It's best to wrap it in 'if has("autocmd") ... endif' sequence.
      > *****
      >
      > That should solve your docstring indentation.
      >
      > Couple of things that I keep in my ~/.vim/ftplugin/python.vim, but they can be defined in ~/.vimrc as well (if one is not sure how to write a plugin startup and cleanup parts):
      >
      > These are useful to keep the indentation that conforms to PEP-8 style.
      >
      > " Indent any continuation line 'shiftwidth' spaces
      > let g:pyindent_open_paren = '&sw'
      > let g:pyindent_nested_paren = '&sw'
      > let g:pyindent_continue = '&sw'
      >
      > You can also add more highlight if you want:
      >
      > " Highlight more
      > let python_highlight_all = 1
      >
      > OK. I think this should help you.
      > Please, tell us if this solves your indentation problems.
      >
      > Regards,
      >
      > Zvezdan

      Did not work.

      I already have filetype indent on. When I first noticed this problem, that's what I checked with the command filetype:
      filetype detection:ON plugin:ON indent:ON

      I believe this is being turn on by /etc/vimrc.

      I will try to move rc files around to see if there is any effect.

      --
      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
    • Zvezdan Petkovic
      ... Something in your or system setup is changing the default indentation. ... Perhaps something else is being turned on that has a negative impact. ... This
      Message 2 of 11 , Apr 4 11:07 AM
      • 0 Attachment
        On Apr 4, 2012, at 1:12 PM, Zetah Ghamin wrote:

        > Did not work.
        >
        > I already have filetype indent on. When I first noticed this problem, that's what I checked with the command filetype:
        > filetype detection:ON plugin:ON indent:ON

        Something in your or system setup is changing the default indentation.

        > I believe this is being turn on by /etc/vimrc.

        Perhaps something else is being turned on that has a negative impact.

        > I will try to move rc files around to see if there is any effect.

        This should work with a bare default Vim setup. I suggest the following:

        - Put your function (and class) in a file and indent it manually to look right
        (e.g., four space indent for the whole docstring and a pass below it).
        - Move away your .vim, .vimrc, and .gvimrc files.
        - Run "touch .vimrc" from the command line to ensure "nocompatible" mode
        - Try to re-indent the content of the file with your function.

        This should cause bad indentation.

        - Add to .vimrc just:

        if has("autocmd")
        filetype plugin indent on
        autocmd FileType python setl sw=4 sts=4 et
        endif

        - Try the file with your function again.

        This must produce right indentation if filetype shows plugin and indent are on.

        If that produces the right indent, try to gradually add your personal Vim files, especially Python related features, until you find the culprit.

        If that doesn't produce the right indent, your personal Vim setup is probably fine and something is wrong with the system settings.
        Try reviewing and moving those until you find the one that causes the problem.

        The files to look at are: /usr/share/vim/vimrc and it seems /etc/vimrc on your Linux systems at least.

        Also check if anything is triggering /usr/local/share/vim/vimXY/indoff.vim where XY is your Vim version (e.g. 73)

        Regards,

        Zvezdan

        --
        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
      • Zetah Ghamin
        I suppose it s solved for now. I realized that I indeed did not have filetype indent on on the Ubuntu machine. It was on in the Arch machine, which now also
        Message 3 of 11 , Apr 5 10:09 AM
        • 0 Attachment
          I suppose it's solved for now. I realized that I indeed did not have filetype indent on on the Ubuntu machine. It was on in the Arch machine, which now also works.

          It seems though that the default indentation style is to not do any auto indentation for triple-quoted string. So, if I deliberately mess up the indentation, using 1GvG= would do nothing. But if I properly line up the string, 1GvG= no longer messes it up.

          On Wednesday, April 4, 2012 11:07:47 AM UTC-7, Zvezdan Petkovic wrote:
          > On Apr 4, 2012, at 1:12 PM, Zetah Ghamin wrote:
          >
          > > Did not work.
          > >
          > > I already have filetype indent on. When I first noticed this problem, that's what I checked with the command filetype:
          > > filetype detection:ON plugin:ON indent:ON
          >
          > Something in your or system setup is changing the default indentation.
          >
          > > I believe this is being turn on by /etc/vimrc.
          >
          > Perhaps something else is being turned on that has a negative impact.
          >
          > > I will try to move rc files around to see if there is any effect.
          >
          > This should work with a bare default Vim setup. I suggest the following:
          >
          > - Put your function (and class) in a file and indent it manually to look right
          > (e.g., four space indent for the whole docstring and a pass below it).
          > - Move away your .vim, .vimrc, and .gvimrc files.
          > - Run "touch .vimrc" from the command line to ensure "nocompatible" mode
          > - Try to re-indent the content of the file with your function.
          >
          > This should cause bad indentation.
          >
          > - Add to .vimrc just:
          >
          > if has("autocmd")
          > filetype plugin indent on
          > autocmd FileType python setl sw=4 sts=4 et
          > endif
          >
          > - Try the file with your function again.
          >
          > This must produce right indentation if filetype shows plugin and indent are on.
          >
          > If that produces the right indent, try to gradually add your personal Vim files, especially Python related features, until you find the culprit.
          >
          > If that doesn't produce the right indent, your personal Vim setup is probably fine and something is wrong with the system settings.
          > Try reviewing and moving those until you find the one that causes the problem.
          >
          > The files to look at are: /usr/share/vim/vimrc and it seems /etc/vimrc on your Linux systems at least.
          >
          > Also check if anything is triggering /usr/local/share/vim/vimXY/indoff.vim where XY is your Vim version (e.g. 73)
          >
          > Regards,
          >
          > Zvezdan

          --
          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
        • Zvezdan Petkovic
          ... I m really glad to hear that. It can be frustrating to get the help remotely from the mailing list, but the most important thing is that it worked for you
          Message 4 of 11 , Apr 5 5:33 PM
          • 0 Attachment
            On Apr 5, 2012, at 1:09 PM, Zetah Ghamin wrote:

            > I suppose it's solved for now. I realized that I indeed did not have filetype indent on on the Ubuntu machine. It was on in the Arch machine, which now also works.


            I'm really glad to hear that.
            It can be frustrating to get the help remotely from the mailing list, but the most important thing is that it worked for you in the end.


            > It seems though that the default indentation style is to not do any auto indentation for triple-quoted string.


            True. Because they are used for documentation they are basically interpreted as a reST (reStructuredText). You may want to indent parts of reST to get quoted blocks or similar effects. Thus, once you enter
            a triple-quoted string, indenter lets you to keep your own document formatting.


            > So, if I deliberately mess up the indentation, using 1GvG= would do nothing. But if I properly line up the string, 1GvG= no longer messes it up.


            Exactly. Once you set it up right it stays the way you wanted it.

            All the best,

            Zvezdan

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