Monday, December 12, 2011

vimで開いているファイルの改行コードを簡単に変更したい

$ vi ~/.vimrc
で以下を追加する

function FuncBreakLine(type)
if a:type == "d"
echo "Set to dos"
set fileformat=dos
elseif a:type == "m"
echo "Set to mac"
set fileformat=mac
elseif a:type == "u"
echo "Set to unix"
set fileformat=unix
else
echo "usage# :Br [dmu]"
endif
endfunction

command -nargs=1 BreakLine :call FuncBreakLine("")

:BreakLine d
CRLF → ms-dos, win

:BreakLine m
CR → mac

:BreakLine u
LF → unix, mac os x

※他に類似する名称のコマンドが定義されていなければ、
:Br d
:Br m
:Br u
だけタイプすれば実行可能です。

No comments:

Post a Comment