dstbtam8732 2017-05-18 09:58
浏览 54
已采纳

在MS-Windows上使用vim和git在语言源文件中的行尾

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 2017-08-21 13:25
    关注

    My solution.

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

    git

    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.

    vim

    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.


    Footnote

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP