2017-05-18 09:58 阅读 45


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?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    douketangyouzh5219 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.

    点赞 评论 复制链接分享