How can you automatically remove trailing whitespace in vim

后端 未结 13 2122
星月不相逢
星月不相逢 2020-12-02 03:39

I am getting \'trailing whitespace\' errors trying to commit some files in git.

I want to remove these trailing whitespace characters automatically right before I sa

13条回答
  •  不思量自难忘°
    2020-12-02 03:59

    This is how I'm doing it. I can't remember where I stole it from tbh.

    autocmd BufWritePre * :call StripWhite()
    fun! StripWhite()
        %s/[ \t]\+$//ge
        %s!^\( \+\)\t!\=StrRepeat("\t", 1 + strlen(submatch(1)) / 8)!ge
    endfun
    

提交回复
热议问题