1

I have this go code snippet that I am working on in vim with vim-go enabled. | is where my cursor is at.

// PlayerServer is a HTTP interface for player information
type PlayerServer struct {
        store  PlayerStore |
        router *http.ServeMux
}

When I hit return, the cursor goes 8 spaces indented in the next line.

// PlayerServer is a HTTP interface for player information
type PlayerServer struct {
        store  PlayerStore 
                |
        router *http.ServeMux
}

What setting should I be looking at to see what causes this?

3
  • What does :set filetype? say? Is the file correctly recognized as Go source code? What about :set indentexpr?, does it match the Go plug-in you're using? (Just making sure everything is as expected to be in your environment.) Feel free to answer these with edits to your question.
    – filbranden
    Aug 24, 2019 at 16:57
  • 2
    Your comment made me look at those settings, I went through vim-go doc and realized I hadn't set filetype plugin indent on. That solved the issue. Thanks a bunch! If you add that as an answer I'd be happy to mark it solved.
    – woodstok
    Aug 24, 2019 at 17:04
  • I imagine there might be a duplicate for this question, but I did a quick search and couldn't find an obvious one... If anybody finds one that's appropriate, please mark it as duplicate.
    – filbranden
    Aug 24, 2019 at 17:16

1 Answer 1

3

As diagnosed through comments, you were probably using some generic indentation (such as Vim's cindent, which is likely to expect semi-colons to end statements.)

In order to enable language-specific plugins for indentation, enable filetype detection and filetype indentation plugins, with:

filetype plugin indent on
1
  • 2
    Also, dont set cindent in your vimrc :P
    – D. Ben Knoble
    Aug 24, 2019 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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