Can Vim reference a font stored locally in .vim or vimfiles? - vim

I have my Vim configuration under source control, and instead of moving to a new platform and having to install the specific Powerline font I use on every machine, I'd like to be able to simply store my font in something like ~/.vim/fonts/my-powerline-font.ttf, so I can use a command in my vimrc to reference it locally.
Is this possible?

Like any other application, Vim uses the operating system's APIs to use one of the installed fonts. If a font is not properly installed, Vim cannot use it.
So, you need to install any font first. You could automate that by invoking external commands in your ~/.vimrc, though. For example, on Linux, "installing" can be as easy as copying the font into ~/.fonts:
if ! file_readable($HOME . '/.fonts/my-powerline-font.ttf')
call system('cp ~/.vim/fonts/my-powerline-font.ttf ~/.fonts/')
fi

Related

How to change vim colorscheme to point to different directory

I'm wondering whether I can change 'colorscheme' to point to different directory.(rather than default) since I want to set my all my color schemes in vimrc file with my own directory.
In My MacOS, the default directory are in /usr/local/share/vim/vim80/colors
You are supposed to put colorschemes in ~/.vim/colors/.
Create that directory if it doesn't exist and stay away from /usr/local/share/vim/.
As #romainl pointed out, keep your hands off the system-wide directories. Just because Vim's default stuff gets installed under /usr/local/share/vim, this doesn't mean that your personal extensions and customizations should be in there as well. You'll provoke problems when upgrading or reinstalling Vim.
If the suggested default location (~/.vim/colors/) doesn't suit you, you can add additional directories to 'runtimepath' (early enough; i.e. in your ~/.vimrc). For colorschemes, the direct directory has to be colors, though. To work around that, you'd have to use filesystem links to create an alias.

Can you set different fonts for different file types in gvim?

For example source code pro for .py files and ubuntu font for .txt files
No, at least not where two different fonts are displayed simultaneously (e.g. when you have both a Python and text file open in two window splits). You can dynamically switch the entire global 'guifont' option triggered by :autocmds, though.
The reason for that is that Vim / GVIM adhere to a classic terminal model, where the entire screen consists of fixed-width display cells. Different fonts, due to their different size properties, would either look very ugly or disrupt that fixed cell model.
As others have pointed out, you can't have multiple fonts in the same instance of gvim (the same desktop window) at the same time. But if you're opening a new gvim for each different type of file, then you can do it with autocommands, specifically something like:
autocmd FileType python setlocal guifont=<font>
Replace <font> with whatever font you want (you can check set guifont? to get the formatting right).
YMMV if you use a lot of buffers, tabs, etc. But personally, I can't think of a time (other than :help) when I have two different filetypes open simultaneously.
Check out the following recent discussion in vim-use groups. There it is claimed that it is possible to change font based on syntax:
vim-use-thread

Windows 7 & gVim makeprg/shellpipe setup to show build output

I'm trying to setup vim on windows to work like it does in Linux. Basically, when I type ":make" in linux, I get the output of makeprg sort of streaming through vim itself.
On windows I get a cmd prompt that comes up, but behind vim. I have to switch focus to view the results until they are finished and then they can be viewed in the quickfix window.
I attempted to download a copy of "tee" and set shellpipe to |tee, but that didn't really change anything. Below are the sort of relevant settings in my vimrc, I use ninja, but the same happens if I switch to nmake or something similar.
set makeprg=ninja\ -C\ build-ninja
set shellpipe=2>&1\ \|tee
set efm+=%Dninja:\ Entering\ directory\ `%f',%Xninja:\ leaving\ directory
I think this is related to what you want, but provides only for a partial solution, because it will not wait until the program has finished running:
set makeprg=start\ /min\ ninja\ -C\ build-ninja
Getting it to work will not be trivial (see comments), it seems like an important oversight of the Windows version of Vim, because start cannot be executed from makeprg (see comments), only the internal (and more limited !start).
The full documentation of the start program (which it seems you would need to somehow invoke) you can find in this question

Vim plugin Align fails to work. Can it be installed without vimball?

I've happily installed the vim Align plugin on my home computer, but on the Red Hat servers at work, the installation doesn't work. The servers at work have a very old copy (2006) of vimball, which from Googling I know doesn't support more recent vimballs, including Align. I can't get the systems group (IT department) to upgrade vimball, so I thought perhaps I could simply copy the various files into ~/.vim/plugin by hand. I copied the 3 files from my home system AlignMapsPlugin.vim AlignPlugin.vim cecutil.vim, but when I attempt to use Align from within vim I get the following error message
E117: Unknown function: Align#Align
I know that it's seeing the plugin, because when I remove the plugin the error message is different (it says "Not an editor command Align").
Is there a workaround for this? I love "Align" and would sure like to use it at work as well as at home.
{rtp}/plugin is not the only location where plugin files can be placed. The name of the function suggests that there is at least one file in {rtp}/autoload named Align.vim (autoloaded functions must have names looking like path#to#file#with#function#without#leading#autoload#function_name(), this example is for function located in {rtp}/autoload/path/to/file/with/function/without/leading/autoload.vim). But I strongly suggest that if #LucHermitte’s solution is not acceptable, you should use something that supports holding plugins in separate directories. If you used VAM all you needed to do (assuming that you have already installed align using VAM) is to look for files in ~/.vim/vim-addons/Align%294 and copy all of them.
Update: Forgot to say, you may try to install newer vimball plugin into your ~/.vim. In order to do this you need copy a file placed in /usr/share/vim/vim73/autoload/vimball.vim to ~/.vim/autoload (there is another related file, /usr/share/vim/vim73/plugin/vimballPlugin.vim, but it is not likely to be changed). No need to make IT department to upgrade anything, unless the newest version uses the newest vim features.
Install a recent (/the latest) vim in your $HOME. I've been doing this for ages now. It's the easiest way to get the job done (i.e. to have a proper environment).

How do I have Emacs load a font from a file?

In the interest of making my emacs setup more portable, I'd like to be able to set the current font by specifying a file rather than a font name, i.e. "Load ~/config/myfont.ttf and use size 12". Is there a way to do that in my .emacs? All the instructions I've found assume the font is already installed on the system. I'm using the XFT support on Linux, so a linux specific hack would be OK but I'd prefer something that would work on all targets.
Update: To be clear, I'm using a font that isn't standard on Windows / OS X / Linux. I'm not just looking to set a different font based on platform, but to specify a specific font file that I have (TTFs work on Windows and Linux, if not on Mac I'll get another version of the file but I still want to specify the font via file rather than name).
Unfortunately, you can't.
Emacs on different platforms uses different windowing toolkits, all of which take care of font handling for it. I don't believe you can specify a font filename in Emacs on any platform - it just doesn't work that way.
As for how to find the font:
On Linux, you could use XFT's support for a user-specific font config file which is usually ~/.fonts.conf (but check /etc/fonts/font.conf to be sure) to add whatever directory you place your fonts into.
On a Mac, you can add the font into ~/Library/Fonts. TTFs work fine on Macs, BTW.
On Windows, I think you'd just have to add it to the system fonts directory.
From there, you then go and tell Emacs (through customize or not) to use your font. You'll find the naming schemes to be different on each platform (not sure what Windows looks like), but customize should help take care of this for you - just keep a separate customize file per machine if need be.
...so basically your portable Emacs setup has to encompass more than just an Emacs config file (which, given that you're carrying a font file around, it already does).

Resources