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 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗