4

When I'm editing my vimrc, if I gg=G vim autoindents nicely except where augroup is involved

I end up with

augroup movingBackup
    au!
    au BufWritePost * call WriteBackupFile(expand("%:t"), expand("%:p:h"))
    augroup end

        augroup dotFile
            au!
            au BufWritePost *.dot :silent !start cmd /c "dot -T png %:t > %:r.png"
            augroup end

                nmap j gj
                nmap k gk

when I really want

augroup movingBackup
    au!
    au BufWritePost * call WriteBackupFile(expand("%:t"), expand("%:p:h"))
augroup end

augroup dotFile
    au!
    au BufWritePost *.dot :silent !start cmd /c "dot -T png %:t > %:r.png"
augroup end

nmap j gj
nmap k gk
  • 3
    can you try using END instead of end for the closing part of augroup ? It should act the same, but with the lower-case version it would not work whereas with the uppercase it works – nobe4 Apr 19 '16 at 15:19
  • 2
    @Nobe4 that does it! (do you want to 'answer' it so I can mark you and the solution?) – Charlie Wynn Apr 19 '16 at 15:20
6

You should use END instead of end for the closing augroup statement.

Apparently it's a bug (cf Carpetsmoker's comment), it should behave the same but it does not. From the documentation (:h :aug):

                        *:aug* *:augroup*
:aug[roup] {name}       Define the autocmd group name for the
                        following ":autocmd" commands.  The name "end"
                        or "END" selects the default group.
                        To avoid confusion, the name should be
                        different from existing {event} names, as this
                        most likely will not do what you intended.

Edit: I opened an issue regarding this question on the vim's github repo, and got an answer:

Although both "end" and "END" work, using "END" is recommended.

I'll change the indent script to also accept "end" (negatively) for incrementing the indent.

  • 5
    This is because the indent/vim.vim file does: elseif prev_text =~ '^\s*aug\%[roup]' && prev_text !~ '^\s*aug\%[roup]\s*!\=\s\+END'. This is a bug; the check should be case-insensitive. – Martin Tournoij Apr 19 '16 at 16:07
  • 2
    Do you know if it's already acknowledged by the vim-team as a bug ? – nobe4 Apr 19 '16 at 16:07
  • 2
    No, that's just my own conclusion ;-) – Martin Tournoij Apr 19 '16 at 16:10
  • 2
    haha, it's strange that for the indent only the regex is messed up, because for the syntax file, they use [eE][nN][dD] each time... I'll open an issue on the github repo. – nobe4 Apr 19 '16 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.