How to view UTF-8 Characters in Vim or gVim - vim

I work on webpages involving non-English scripts from time to time, most of them are encoded using UTF-8.
Vim and gVim do not display those UTF-8 characters correctly.
I'm using Vim 7.3.46 on Windows 7, 64-bit, with set guifont=Monaco:h10 in _vimrc.
Is there a way to fix this?
Update: I've googled around and found set guifontwide acts as second fallback for regional languages.
I added the following lines to _vimrc and most of my problems got solved.
set enc=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf8,prc
set guifont=Monaco:h11
set guifontwide=NSimsun:h12
The above NSimsun font works for Chinese, The problem is, I don't know how they got the font name to work with Vim, Courier New is mentioned as Courier_New also NSimsun is nowhere in the font directory. The font I want to use is Latha But, I don't know how to use it in the _vimrc file. set guifontwide=latha:h12 or set guifontwide=Latha:h12 doesn't work.
If I successfully set the guifontwide to latha, then my problem will be solved. How to do it?

Did you try
:set encoding=utf-8
:set fileencoding=utf-8
?

Try to reload the document using:
:e! ++enc=utf8
If that works you should maybe change the fileencodings settings in your .vimrc.

If Japanese people come here, please add the following lines to your ~/.vimrc
set encoding=utf-8
set fileencodings=iso-2022-jp,euc-jp,sjis,utf-8
set fileformats=unix,dos,mac

On Microsoft Windows, gvim wouldn't allow you to select non-monospaced fonts. Unfortunately Latha is a non-monospaced font.
There is a hack way to make it happen: Using FontForge (you can download Windows binary from http://www.geocities.jp/meir000/fontforge/) to edit the Latha.ttf and mark it as a monospaced font. Doing like this:
Load fontforge, select latha.ttf.
Menu: Element -> Font Info
Select "OS/2" from left-hand list on Font Info dialog
Select "Panose" tab
Set Proportion = Monospaced
Save new TTF version of this font, try it out!
Good luck!

this work for me and do not need change any config file
vim --cmd "set encoding=utf8" --cmd "set fileencoding=utf8" fileToOpen

In Linux, Open the VIM configuration file
$ sudo -H gedit /etc/vim/vimrc
Added following lines:
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
Save and exit, and terminal command:
$ source /etc/vim/vimrc
At this time VIM will correctly display Chinese.

Is this problem solved meanwhile?
I had the problem that gvim didn't display all unicode characters (but only a subset, including the umlauts and accented characters), while :set guifont? was empty; see my question. After reading here, setting the guifont to a sensible value fixed it for me. However, I don't need characters beyond 2 bytes.

I couldn't get any other fonts I installed to show up in my Windows GVim editor, so I just switched to Lucida Console which has at least somewhat better UTF-8 support. Add this to the end of your _vimrc:
" For making everything utf-8
set enc=utf-8
set guifont=Lucida_Console:h9:cANSI
set guifontwide=Lucida_Console:h12
Now I see at least some UTF-8 characters.

On Windows gvim just select "Lucida Console" font.

Related

Trouble Getting Colorschemes in Vim with Iterm2

I can't get the vimbrant colorscheme (or any) to work in Vim with Iterm2. This is my .vimrc file:
syntax on
syntax enable
colorscheme vimbrant
set background=dark
I have Iterm set up to use xterm-256 like it says in the FAQ as well. Whenever I echo in Vim it says 256.
The terminal also doesn't use the color settings I have in Iterm2 but I don't care about that as much.
EDIT: The file is in ~/.vim/colors/vimbrant.vim. Also, I forgot to mention that my cursor seems to have the right colors for variables and structs and whatnot, but the text itself is all white still. The background seems to be the correct color. And the only thing in my .gvimrc file is colorscheme vimbrant.
Really dumb mistake, I had minimum contrast maxed out without realizing.
I've been having the same issue and this is what seems to have solved it:
In your .bash_profile set CLICOLOR before setting TERM:
# Set CLICOLOR if you want Ansi Colors in iTerm2
export CLICOLOR=1
# Set colors to match iTerm2 Terminal Colors
export TERM=xterm-256color
save bash file and source:
source ~/.bash_profile
Then, in your iTerm2 Preferences > Terminal > Report Terminal Type, set to either xterm-256color or xterm
Close iTerm2, restart it and type ls. That did the trick for me.
Good luck.
I have my iterm2 colors highly customized, and build a specific theme for vim/janus. My iterm2 colors are fine, but after the 20161204 nightly build, colors would be all messed up in vim.
I noticed the colors that were off in vim were my iterm2 profile "bright" colors. I tried set background=dark in my .vimrc, but that didn't fix it. However using set background=light, my colors are exactly how I used to have them again!
I clearly did something backwards when configuring vim, but I've fine tuned it the way I like it. I hope this helps for anyone else having an issue with vim colors after December 4th 2016.
syntax enable is useless after syntax on.
set background=dark is also generally useless outside of a colorscheme.
Does your colorscheme work when you do :colorscheme vimbrant? Where did you install it?
After trying all other suggestions made here and elsewhere, the final thing that worked for me was:
set termguicolors

Fail to set font in Macvim

I am configuring macvim on Mac OS X Mavericks. I type "set guifont=Menlo\ 14" in both ~/.vimrc and ~/.gvimrc but the editor remains displaying in courier.
I insert ":set guifont?" and it reveals "guifont=Menlo\ 14". I overviewed the content of .vimrc and .gvimrc but found no other line overriding the guifont setting.
I have checked several posts in stack overflow but cannot yet find the solution. Wish to get some help, thanks for anticipation.
The ideal way of going about doing this is by invoking the following command from vim :
set guifont=*
That will open a font selection dialog box and you can select whatever you would like there. Once done, you should then check what the option was set to by using the command you mentioned yourself :
set guifont?
Now you should put the output of that in your .gvimrc (not .vimrc) and additionally you'll need to escape the spaces like you're doing already. There might be subtle mistakes in what you're setting yourself, the font size for instance can sometimes be set in different ways.
On my version of MacVim (7.4.258) and running EL Kapitan, putting
set guifont=*
in .vimrc caused MacVim to spit out the following error (when run from the command line, starting it from the Dock caused it to just not run at all):
E665: Cannot start GUI, no valid font found
So it seems the correct way is to start MacVim, use the Edit > Font > Show Font menu, pick a font, then use
set guifont?
to find the line to add to your .vimrc
Also remember to use forward slashes to escape any spaces in the font name.
To change font, use Edit -> Font -> Show Fonts and selected a font.
Unfortunately this setting gets wiped out with each update of MacVim.
To have your font setting persisted in MacVim add this to your ~/.gvimrc
set guifont=Hack\ Nerd\ Font:h12

How to set font to be DejaVu Sans Mono in vim for xp?

i have installed vim for xp ,there is a file _vimrcin C:\Vim ,i have set font in _vimrc :
set guifont=Bitstream_Vera_Sans_Mono:h11:cANSI
when i open vim ,the setup can not work ,when i open gvim ,the setup can work .
what is the matter?
the configuration i write in _vimrc can work perfectly in gvim when i open it ,why it can not work in vim?
In my gvim and cmd ,i can see Bitstream_Vera_Sans_Mono font in screen ,and my active console code page is set to be 437, vim can't use Bitstream_Vera_Sans_Mono font ,why?
In $MYVIMRC, add the line:
set guifont=DejaVu\ Sans\ Mono:h11
...where :h11, specifies a height of 11 points.
N.B: A _ can be used in the place of a space, so you don't need to use
backslashes to escape the spaces.
Reference
:help 'guifont'
Notes, following update to question
'guifont' only works on Vim's GUI (i.e. gvim) and not on a console (or terminal) vim instance. Vim has no control over the font of the terminal in which it is running.
If you wish to change the Windows XP(!) console font, see How to change the Windows XP console font? on SuperUser.

Why doesn't the font setting work in gvim?

In Fedora15, I was originally using vim, with all my settings defined in my ~/.vimrc file. I recently installed vim-X11, and have now transitioned to gvim. I defined a ~/.gvimrc file, with the following line to set the font:
set guifont=Bitstream_Vera_Sans_Mono:h11:cANSI
However, it doesn't work. There are two strange things:
The other settings such as line number, color scheme works right, but font setting doesn't work. Instead, I need to set them in the tool bar every time to change the font: "Edit->Select Font".
Every time I select "Edit -> Startup Settings", it opens the ~/.vimrc file instead of the ~/.gvimrc file.
Your guifont is valid only on Windows. In GTK GVim, you want:
set guifont=Bitstream\ Vera\ Sans\ Mono\ 11
Also, you can use set guifont=* to bring up a system dialog to choose a font, and then look at the contents of the setting with set guifont?.
GVim loads .vimrc and then .gvimrc, so you can separate settings that apply only to GUI version.
I find use set guifont=* then set guifont? will not work, butset guifont=Bitstream\ Vera\ Sans\ Mono\ 11 nice

how do I add a font in gVim on windows system

I wanted to add a UTF-8 font in Gvim but I could not find out how to do this.
I tried to follow the step on this manual but it still did not work.
http://www.inter-locale.com/whitepaper/learn/learn_to_type.html (vim section halfway the page)
Can anyone tell me how to add a font in Vim so I can have Japanese characters displayed ?
As others note, you must use a fixed-width font. Vim is a text editor, not a WYSIWYG editor.
If you have a fixed-width font with the characters you need then:
:set guifont=*
Select the font you want to use, the size, etc. Once you're happy with it, do:
:set guifont?
And it will output the current setting of the value. Put the set guifont=foo in your .gvimrc (or in .vimrc with a if has("gui_running") block).
set guifont=<C-R>=&guifont<CR>
That will put the current value into the file.
For Windows, I found using the guifontwide setting provided the expected functionality (i.e. mixed character display: Japanese, Chinese and English in the same file). This is not intuitive or obvious (at least not to me!) from the Vim help files, but having something like this in your startup settings will work:
set guifont=Consolas:h10
set guifontwide=MingLiU:h10 "For windows to display mixed character sets
set encoding=utf-8
Quote from the vim documentation:
For MS-Windows, some fonts have a limited number of Unicode characters. Try
using the "Courier New" font. You can use the Edit/Select Font... menu to
select and try out the fonts available. Only fixed-width fonts can be used
though. Example:
:set guifont=courier_new:h12
So, I guess, unless you find a fixed width font containing the characters you want to display, then you are out of luck.
This is what I use...
set gfn=MingLiU:h16:cDEFAULT
set fenc=utf-8
set encoding=utf-8
Put this in your _vimrc file, exit and reopen. Works like a charm for me.
+T
You have to use a fixed-width font for Gvim under Windows.
There are several relevant pages at the Vim Tips Wiki:
Working with Unicode
Setting the guifont
The perfect programming font

Resources