You are not logged in.

#1 2016-11-26 15:12:22

Malkawi
Member
Registered: 2016-11-26
Posts: 15

[SOLVED]Using different fonts in terminal and vim

Hello guys, I installed arch 2 days ago and it's been a blast so far! I am currently in the process of ricing my system and I have an idea that i would like to make possible. I am currently using rxvt-unicode as my terminal, zsh as my shell, I also installed a nice theme, a matching color scheme, and a custom font. However, I would like to use a different font in vim because it gets really annoying when you're dealing with huge amounts of code. Thanks in advanced.

Last edited by Malkawi (2016-11-27 12:40:55)

Offline

#2 2016-11-26 15:41:42

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED]Using different fonts in terminal and vim

man urxvt wrote:

CHANGING FONTS
...
       You can, however, switch fonts at runtime using escape sequences, e.g.:

          printf '\e]710;%s\007' "9x15bold,xft:Kochi Gothic"

Just add that to an alias or shell function to invoke vim.

Note that this will not work under terminal multiplexers (tmux/screen).


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#3 2016-11-26 16:25:52

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

Trilby wrote:
man urxvt wrote:

CHANGING FONTS
...
       You can, however, switch fonts at runtime using escape sequences, e.g.:

          printf '\e]710;%s\007' "9x15bold,xft:Kochi Gothic"

Just add that to an alias or shell function to invoke vim.

Note that this will not work under terminal multiplexers (tmux/screen).

Thanks a lot smile

Last edited by Malkawi (2016-11-26 18:20:31)

Offline

#4 2016-11-26 18:20:42

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

This might not be the right way to do it, however I'm still new to bash. I tried adding " alias vim='open "vim"'&&'printf '\e]710;%s\007' "9x15bold,xft:Kochi Gothic" ' " to my .zsh file but I get "~/.zshrc:91: command not found: printf e]710
~/.zshrc:fg:91: job not found: s007 "9x15bold,xft:Kochi Gothic" "


How can I fix this?

Offline

#5 2016-11-26 18:33:18

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED]Using different fonts in terminal and vim

You need to escape the inner `'` quotes.


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#6 2016-11-26 20:00:01

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

jasonwryan wrote:

You need to escape the inner `'` quotes.

Escape?How?

Offline

#7 2016-11-26 20:01:13

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED]Using different fonts in terminal and vim


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#8 2016-11-26 21:43:52

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED]Using different fonts in terminal and vim

Am I reading that wrong - as there is a lot more wrong with that than escaping quotes.  That is unless aliases are completely different in zsh and bash.

First, I don't know what "open" is, and alias is usually just the commands you want it replaced with.  And you need to put the printf command before vim, or you will not have the new font in vim.  Then you probably want another printf command after vim to reset the font after vim exits.  Lastly, 9x15bold,xft:Kochi Gothic is just the example in the man page - is that really the font you want to use?

Extra-lastly, you probably want this to be a function not an alias as you want to pass parameters to vim:

function vim() {
   printf '\e]710;%s\007' "FONT-FOR-VIM"
   /usr/bin/vim "$@"
   printf '\e]710;%s\007' "YOUR-DEFAULT-FONT"
}

This would work for bash.  I don't have any experience with zsh to know if the function would need to be written differently - but I don't think there are any bashisms, so it should all be POSIX sh anyways.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#9 2016-11-27 04:47:11

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

Trilby wrote:

Am I reading that wrong - as there is a lot more wrong with that than escaping quotes.  That is unless aliases are completely different in zsh and bash.

First, I don't know what "open" is, and alias is usually just the commands you want it replaced with.  And you need to put the printf command before vim, or you will not have the new font in vim.  Then you probably want another printf command after vim to reset the font after vim exits.  Lastly, 9x15bold,xft:Kochi Gothic is just the example in the man page - is that really the font you want to use?

Extra-lastly, you probably want this to be a function not an alias as you want to pass parameters to vim:

function vim() {
   printf '\e]710;%s\007' "FONT-FOR-VIM"
   /usr/bin/vim "$@"
   printf '\e]710;%s\007' "YOUR-DEFAULT-FONT"
}

This would work for bash.  I don't have any experience with zsh to know if the function would need to be written differently - but I don't think there are any bashisms, so it should all be POSIX sh anyways.

Thanks for the reply mate, your command was able to change font of my terminal. However, vim doesn't start, it shows this error message instead. "vim:2: maximum nested function level reached"

Offline

#10 2016-11-27 12:04:30

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED]Using different fonts in terminal and vim

It works fine here in bash.  I did edit it a couple times, did you use the version you just quoted?  That error sounds like the result of not having /usr/bin/ before vim in the function.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#11 2016-11-27 12:28:11

seth
Member
Registered: 2012-09-03
Posts: 49,981

Re: [SOLVED]Using different fonts in terminal and vim

... or running the function from vim's init. where did you put the function?

Offline

#12 2016-11-27 12:32:11

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED]Using different fonts in terminal and vim

I did think about putting the printf line in vimrc under an autocmd.  My first attempts at that failed, and I suspected it might be a poor approach.  The printf command needs to execute *before* vim starts up the ncurses alt screen.  I don't know the order of events in vim startup, but I'm gathering that the screen may be initialized before the autocmds are executed.  So - echoing the above - this must be a shell function, not a vim function.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#13 2016-11-27 12:38:57

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

Trilby wrote:

It works fine here in bash.  I did edit it a couple times, did you use the version you just quoted?  That error sounds like the result of not having /usr/bin/ before vim in the function.

Ah my bad, I just noticed that. Thanks a lot for your help, but I have a small question: Do you have any resources on where I can start learning bash/general linux scripting in general? I really like customizing apps to my liking, and by the looks of it it seems like I'll be writing a lot of scripts/editing config files.

seth wrote:

... or running the function from vim's init. where did you put the function?

I added the lines to my ~/.zshrc file.

Offline

#14 2016-11-27 13:44:17

2ManyDogs
Forum Moderator
Registered: 2012-01-15
Posts: 4,645

Re: [SOLVED]Using different fonts in terminal and vim

Malkawi wrote:

Do you have any resources on where I can start learning bash/general linux scripting in general?

https://wiki.archlinux.org/index.php/Bash#Tutorials


How to post. A sincere effort to use modest and proper language and grammar is a sign of respect toward the community.

Offline

#15 2016-11-27 13:44:51

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: [SOLVED]Using different fonts in terminal and vim

As suggested above, I can't offer guidance on zsh, but for bash or shell in general, see the wiki.

I'd suggest Greg's Wiki in particular.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#16 2016-11-27 13:48:24

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

Trilby wrote:

As suggested above, I can't offer guidance on zsh, but for bash or shell in general, see the wiki.

I'd suggest Greg's Wiki in particular.

Well, Zsh is highly compatible with bash, I am basically using it as a better bash rn, thanks a lot for the links.

Hopefully one day I will be one of the people who answer questions in here instead of asking them.

Offline

#17 2016-11-27 23:52:21

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: [SOLVED]Using different fonts in terminal and vim

I like Greg's wiki, it was really straightforward which was helpful when I was learning shell scripting
(I still basically always am learning)

Offline

#18 2016-11-28 22:16:58

Malkawi
Member
Registered: 2016-11-26
Posts: 15

Re: [SOLVED]Using different fonts in terminal and vim

HiImTye wrote:

I like Greg's wiki, it was really straightforward which was helpful when I was learning shell scripting
(I still basically always am learning)

Yeah the tutorials are really nice and well-structured.

Offline

Board footer

Powered by FluxBB