Fail to set font in Macvim - vim

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

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."

Different color in Vim while using screen

I'm currently using color scheme from http://vimcolors.com/535/jay/dark in iTerm on Mac OSX. However, I found the color became different when I use Vim in screen, what setting should I look into here?
Without screen:
With screen:
> echo $TERM
xterm-256color
> cat ~/.screenrc
...
term xterm-256color
I hope it isn't too late.
Normally, on your ~/.vimrc there might be a line
colorscheme yourColorScheme
where yourColorScheme is one of the .vim color configuration file your can find in /usr/share/vim/vim80/colors/, without the .vim extension
Example, I want to use /usr/share/vim/vim80/colors/blue.vim configuration file, I do
colorscheme blue
If this line isn't written in .vimrc, then vim will select a default color configuration file and that selection might be different while using screen.
I had the same problem and solve it by adding this line à the end of the file.
The only distasteful thing is that you will probably have to try all the configuration listed in /usr/share/vim/vim80/colors/ to find the one you liked (I advise you to open a terminal with your ~/.vimrc opened in to test the differents colorshemes, a second terminal where you vim a file that shows you the good syntax color you like, and a third and a third where you launch screen and vim the same file to see the new syntax color and compare)

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

vim in tmux background color changes when paging

I am using vim in 256 color mode on Solaris (connected via Putty on Windows). Everything looks great and works fine outside of tmux, but within tmux the background color changes periodically when paging/scrolling through a file.
Here is how it's supposed to look:
Here is how it appears after paging around a bit:
Thanks!
As explained here, disable Background Color Erase (BCE) by clearing the t_ut terminal option (run :set t_ut= in Vim and then press Control+L to refresh the terminal's display) so that color schemes work properly when Vim is used inside tmux and GNU screen.
Per the above link, BCE can be set in .vimrc by adding the following
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
Adding an alternative solution, as I ran into this problem myself and only just solved it. I had the correct TERM value, the terminfo file was there, etc., but the background would still only be drawn behind cells that contained printable characters, or cells to the left of them.
If you switch between GUI vim and CLI vim often, you may have put something like this in your .vimrc file at some point:
if !has("gui_running")
set term=xterm
endif
(Or really any overriding at all of the TERM variable within .vimrc)
Change the terminal override to screen-256color.
...
set term=screen-256color
...
This looks like an issue with your term setting, or terminfo.
Make sure that your term in tmux is TERM=screen-256color and that your solaris box has the correct terminfo.
This bug is fixed in vim 7.4 patch 7.4.1942
Relevant issue: 804

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