2017-05-18 09:58
浏览 54


The situation

I am writing go language applications on Windows 10. I use vim to edit my source files. I use git for version control.

The go language comes with some unusually rigid prescriptions for source file formatting. I have decided my life will be easier if I go along with this.

The problem

the go fmt command is useful for sorting imports, lining up columns and other things. I'm inclined to use it prior to checkin and at other times.

The go fmt command changes line endings to lf. This causes both git and vim to issue warnings.

My solution?

Moved into an "Answer" after 3 months because no other answers appeared and it's probably better for other people with a similar problem to see in a search result that this question has 1 Answer rather than 0 Answers

My question.

Is my line-ending solution optimal or have I missed something that may bite me later?

图片转代码服务由CSDN问答提供 功能建议


我正在Windows 10上编写Go语言应用程序。 使用vim编辑我的源文件。 我使用git进行版本控制。

go语言附带了一些对源文件格式特别严格的规定。 我已经决定,如果我坚持这一点,我的生活将会更轻松。


go fmt 命令 对于排序导入,排列列和其他内容很有用。 我倾向于在签入之前和其他时间使用它。

go fmt 命令将行尾更改为 lf 。 这会导致 git vim 发出警告。

我的 解决方案?

三个月后移入“答案”,因为没有其他答案出现,对于其他有类似问题的人,在搜索结果中看到该问题可能会更好 我的问题有1个答案而不是0个答案

我的行尾解决方案是最佳解决方案还是错过了一些可能 以后再咬我吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douketangyouzh5219 2017-08-21 13:25

    My solution.

    To eliminate the warnings I configured vim and git to work the way golang likes.


    The following command stops git from trying to do what is normally the right thing: standard line-endings in repo, platform line-endings on each developers working directory, convert as needed.

    git config core.autocrlf false

    Now git won't change lf to crlf on checkout or bleat about line-endings.


    In _vimrc

    au FileType go setl ts=3 sw=3 nowrap nu syntax=go ruler fileformat=unix

    The fileformat=unix seems to keep vim complaint-free regarding line-endings that are not native to the platform.


    3 months after posting the above question I haven't come across any drawbacks or problems - at least not the way I use go, vim and git.

    解决 无用
    打赏 举报

相关推荐 更多相似问题