Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim: textwidth setting ignored for Go #177

Closed
FND opened this issue Oct 10, 2014 · 7 comments
Closed

Vim: textwidth setting ignored for Go #177

FND opened this issue Oct 10, 2014 · 7 comments
Assignees

Comments

@FND
Copy link

FND commented Oct 10, 2014

When using Go, it appears something is overriding EditorConfig's textwidth setting.

My .editorconfig file looks like this:

# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
max_line_width = 80
indent_style = tab
indent_size = 4

[COMMIT_EDITMSG]
trim_trailing_whitespace = false

This works as expected for other languages: e.g. opening a .js file results in filetype=javascript and textwidth=80 - yet opening a .go file results in filetype=go and textwidth=0.

I'm insufficiently familiar with Vim's internals to guess what might be interfering there, but didn't see anything suspicious in /usr/local/share/vim/vim74/ftplugin/go.vim.

:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 22 2014 08:24:27)
MacOS X (unix) version
Included patches: 1-430
Compiled by Homebrew
File: editorconfig.txt
Version: 0.3.2
@xuhdev
Copy link
Member

xuhdev commented Oct 11, 2014

I can also reproduce. It's quite strange as go.vim actually does nothing relavant.

@xuhdev
Copy link
Member

xuhdev commented Oct 11, 2014

I see what's happening. In go.vim, there is

setlocal formatoptions-=t

Which means go.vim disables auto text wrapping, textwidth won't be used, no matter what is set. Do you understand why? I don't know go and I can't tell any reason.

@FND
Copy link
Author

FND commented Oct 11, 2014

Ah, well spotted!

I can only assume that's in there because of this:

Go has no line length limit. Don't worry about overflowing a punched card. If a line feels too long, wrap it and indent with an extra tab.

https://golang.org/doc/effective_go.html#formatting

However, arguably .editorconfig takes precedence - so if it defines such a limit, that option should be (re)activated?

@xuhdev
Copy link
Member

xuhdev commented Oct 11, 2014

@FND
Well, if it doesn't make sense for the language, there is no point to activate right? Actually Vim will also ignore the settings regarding tabs for Makefile, as Makefile only see tabs validated, not spaces.

As I understand, go has no difference on line handling with C -- in theory they can both have infinite long lines. For me, the settings in Vim also doesn't make sense. A temporary solution would be delete the formatoptions line in go.vim. A long term solution would be to file a bug here.

@FND
Copy link
Author

FND commented Oct 11, 2014

if it doesn't make sense for the language, there is no point to activate right?

Well, it does make sense (and is perfectly valid too), there's just no specific recommendation at the language level (the same is true for JavaScript, Ruby etc.). That's the point of EditorConfig, isn't it: Agreeing on project-specific standards on top of what the language enforces.

So I still consider this a bug in editorconfig-vim, as from a user's perspective, the max_line_width setting is simply being ignored.

@xuhdev
Copy link
Member

xuhdev commented Oct 12, 2014

I see the problem: max_line_width should be max_line_length. Everything fixed then.

@FND
Copy link
Author

FND commented Oct 12, 2014

Wow, you're right - I have no idea how that happened; I'd been using pretty much the same .editorconfig file across different projects for quite a while now, and nobody ever noticed!

Thanks, and sorry for the trouble.

@FND FND closed this as completed Oct 12, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants