LoginSignup
2
3

More than 5 years have passed since last update.

Vim でファイルの改行コードが unix 以外だったら保存する際に unix に半強制的にする

Last updated at Posted at 2012-03-15
function! s:set_fileformat()
        if &fileformat != "unix" && input("setlocal fileformat=unix?[y/n]") == "y"
                try
                        setlocal fileformat=unix
                catch
                endtry
        endif
endfunction
autocmd BufWritePre * :call <SID>set_fileformat()

改行コードが unix 以外になっていると,:w の際に setlocal fileformat=unix?[y/n] と聞かれて y を入力すると unix に変えてくれます.

unix 以外だと毎回聞かれるので,「こんな改行コードが混在してるかもしれない部屋に居られるか!俺は自分の LF に戻る!」って人だけお使い下さい.

ref.
Vim の改行コードを unix に変更してみた - C++でゲームプログラミング
http://ideone.com/I8joy
https://twitter.com/manga_osyo/status/180258672520331266

Special Thanks @manga_osyo

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3