Is there a command you can enter into a Vim _gvimrc file to set default encoding and line endings?
Is there a command you can enter into a _gvimrc
file to set default encoding and line endings?
I'm working on a Windows machine but i would like to create and edit files using UTF-8 encoding (no BOM) and standard Unix 开发者_Python百科line endings (\n).
Can i set Vim up to create files with these specs?
Sure, put this to your gvimrc:
set encoding=utf-8
set fileformat=unix
You can use the :h[elp]
command to get additional info, e.g. :h encoding
After a while of reading and experimenting:
Set these in _gvimrc
set encoding=utf-8 "Set default buffer encoding to UTF-8.
set fileencodings=utf-8,latin1 "Set the order of file encodings when reading and creating files.
set fileformats=unix,dos,mac "Set the order of line endings when reading and creating files.
These should be used in the command line.
set fileencoding=utf-8 "Change an opened file's encoding.
set fileformat=unix "Change an opened file's line endings.
NOTE:
I realize that you specifically asked for a setting for your vimrc
file but I thought I would offer this bit of advice anyway because I suspect that you may benefit from it (you may be using both *nix and Windows like me).
I do work on both *nix and Windows and I have found it a lot easier to use the modeline
feature (see: :help modeline
) in lieu of setting the file format in my RC file. This allows me to have something like: vim:ff=unix
at the bottom of each file (This way, I do not have to worry about changing the line endings for a *nix makefile I happen to edit in/on Windows.
HTH
Take a look at this question, that should cover all of your vim encoding bases.
Quote from linked answer, with your line ending preferences added in:
set fileformats=unix,dos,mac
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8 " better default than latin1
setglobal fileencoding=utf-8 " change default file encoding when writing new files
endif
精彩评论