how do I add a font in gVim on windows system - vim

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

Related

Custom Fonts in VIM

I'm somewhat new to vim and wanted to add some custom fonts.
This is the one I wanted to add: https://github.com/belluzj/fantasque-sans.
How would I tell vim to use this font since it's not part of the default font set.
Do I add this to the .vimrc?
I'm on Mac Catalina by the way.
If you're using vim in the command line: Vim uses the font of your terminal emulator so if you set up your terminal emulator (iTerm2, Terminal.app etc) to use that font it should pick it up automatically.
If you want that font to be used exclusively in vim and you're using gvim you can change the guifont option which is documented on the Vim FAQ:
"You can change the 'guifont' option to change the font used by GUI Vim. To
display the current value of this option, you can use
:set guifont?
You can add the displayed font name to the .vimrc file to use the font
across Vim sessions. For example, add the following line to the .vimrc file
to use Andale Mono font.
set guifont=Andale_Mono:h10:cANSI
For Win32, GTK and Photon version of Vim, you can use the following command
to bringup a dialog which will help you in changing the guifont:
:set guifont=*
You can also use the -font Vim command line option to specify the font used
for normal text."

How to change the color of Vim's (straight) underline?

I've tried everything changing the color of this:
call s:h("Underlined", {"fg": s:norm, "gui": "underline", "cterm": "underline"})
As well as all the colors of the link texts.
Does anybody know how to change it?
Here's a picture:
For anyone finding that in 2021, you can use guisp=red in neovim at least.
For example I use
:hi CocErrorHighlight gui=undercurl guisp=red
to have red curly lines.
I am using NeoVim in the Xfce-Terminal.
For a long time, you couldn't; the underline color always equaled the text color. AFAICT, in terminals this wasn't supported, and for consistency, Vim also didn't offer this in GVIM.
With Vim 8.2.0863, the ctermul attribute allows setting a separate color for underline / undercurl now. Apparently, this still isn't supported in GVIM, though (which I find odd, because Vim usually values consistency in features over fancy stuff (as explained by :help design-not)).
In GVIM, you could switch to the (GUI-only) undercurl attribute (mostly used for spell checking), which supports a separate "special color", set via guisp={color-name}; see :help highlight-guisp.
You can colorize underline only with ctermul(independent with ctermfg).
See this commit enabling that.

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 i can write arabic html file by vim

I can not write a html file in Arabic by vim.
Tried to do the following:
:set arabic
:set rl
or
:set rightleft
or
:set arabicshape
The problem I want to write Arabic without any change on my tags. I want her to go from left to right.
How i can do thos?
Vim can be invoked in Arabic mode activated by the following command:
vim -A test1
this will start with the cursor located in the right and ready for Arabic text:
السلام عليكم
-- INSERT Arabic --
source: http://blog.naoar.com/2012/04/vim-and-arabic.html
As vim is not BiDi enabled this should not be possible.
But I've been fiddling around a bit and it seems that vim + Konsole (KDE's terminal emulator) seems to do the job if you enable bidirectional support for Konsole. In vim (NO arabic options enabled) you should be able to write LTR and RTL, but letters will always be in isolated form (no shaping). I've found that setting the 'arabicshape' option then unsetting it seems to fix that. Short vowels are not displayed correctly, even though they seem to be written just fine to the file.
I have not tried with other terminal emulators, I'm not aware of their BiDi capabilities. Gnome-terminal maybe ?
because I can't comment on G.J I post it as an answer
using vim in konsole and putting set arabicshape! in my .vimrc
solved the problem for me
as Arabic moves rtl, not ltr, your requirements are contradictory, which is no doubt why it doesn't work.

How to view UTF-8 Characters in Vim or gVim

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.

Resources