Firefox CTRL-+ for changing the guifont size map

28 views
Skip to first unread message

David Fishburn

unread,
Oct 1, 2007, 4:48:17 PM10/1/07
to vim...@googlegroups.com
My most used feature of FireFox is the ability to quickly and easily
change the fontsize of the text I am reading.

So you can hit CTRL+ and CTRL- repeatedly to get the text the size you want.

I was trying to do the same with Vim 7.1 (on WinXP) using a substitute command.

:echo &guifont
Bitstream_Vera_Sans_Mono:h11:b:cANSI

So I tried some variations of this substitue command:
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\(.*\)', '\1\2\3', '')
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\(.*\)', '\1\=submatch(2)\3', '')
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\(.*\)', '\1'.submatch(2).'\3', '')

With the end goal of doing this and hoping I could do arithmetic in
the submatch without it ending up as string concatentation:
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\(.*\)', '\1'.
(submatch(2)+1) .'\3', '')

Anyway, I can't get any of these to work and I was wondering if
someone might have some suggestions. The submatches always end up as
"submatch" literals added instead of the contents of the match.

So final result would be something like this:
:nnoremap + :let &guifont=substitute(&guifont,
'\(.*:h\)\(\d\+\)\(.*\)', '\1'. (submatch(2)+1) .'\3', '')
:nnoremap - :let &guifont=substitute(&guifont,
'\(.*:h\)\(\d\+\)\(.*\)', '\1'. (submatch(2)-1) .'\3', '')

TIA,
Dave

David Fishburn

unread,
Oct 1, 2007, 6:44:53 PM10/1/07
to vim...@googlegroups.com

Little more progress on this, looks like I am running into a Vim bug.

This works:
echo substitute(&guifont, '\%(.*:h\)\(\d\+\)\%(.*\)', '\=submatch(0)', '')
Meaning I get this back:
Bitstream_Vera_Sans_Mono:h11:b:cANSI

This does NOT work:
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\%(.*\)', '\1\=submatch(1)', '')
The result is:
Bitstream_Vera_Sans_Mono:h=submatch(1)

Or:
This does NOT work:
echo substitute(&guifont, '\(.*:h\)\(\d\+\)\%(.*\)',
'\1'.'\=submatch(1)', '')
The result is:
Bitstream_Vera_Sans_Mono:h=submatch(1)

:version
:version
VIM - Vi IMproved 7.1 (2007 May 12, compiled Aug 8 2007 16:27:15)
MS-Windows 32 bit GUI version with OLE support
Included patches: 1-56
Compiled by fishburn@FISHBURN-M20
Big version with GUI. Features included (+) or not (-):
+arabic +autocmd +balloon_eval +browse ++builtin_terms +byte_offset
+cindent +clientserver +clipboard +cmdline_compl
+cmdline_hist +cmdline_info +comments +cryptv +cscope +cursorshape
+dialog_con_gui +diff +digraphs -dnd -ebcdic +emacs_tags
+eval +ex_extra +extra_search +farsi +file_in_path +find_in_path
+folding -footer +gettext/dyn -hangul_input +iconv/dyn
+insert_expand +jumplist +keymap +langmap +libcall +linebreak
+lispindent +listcmds +localmap +menu +mksession
+modify_fname +mouse +mouseshape +multi_byte +multi_lang -mzscheme
+netbeans_intg +ole -osfiletype +path_extra +perl/dyn
-postscript +printer -profile +python/dyn +quickfix +reltime
+rightleft -ruby +scrollbind +signs +smartindent -sniff
+statusline -sun_workshop +syntax +tag_binary +tag_old_static
-tag_any_white -tcl -tgetent -termresponse +textobjects
+title +toolbar +user_commands +vertsplit +virtualedit +visual
+visualextra +viminfo +vreplace +wildignore +wildmenu
+windows +writebackup -xfontset -xim -xterm_save +xpm_w32

A.Politz

unread,
Oct 1, 2007, 7:01:01 PM10/1/07
to vim...@googlegroups.com
David Fishburn wrote:

>Little more progress on this, looks like I am running into a Vim bug.
>
>This works:
> echo substitute(&guifont, '\%(.*:h\)\(\d\+\)\%(.*\)', '\=submatch(0)', '')
>Meaning I get this back:
> Bitstream_Vera_Sans_Mono:h11:b:cANSI
>
>This does NOT work:
> echo substitute(&guifont, '\(.*:h\)\(\d\+\)\%(.*\)', '\1\=submatch(1)', '')
>The result is:
> Bitstream_Vera_Sans_Mono:h=submatch(1)
>
>Or:
>This does NOT work:
> echo substitute(&guifont, '\(.*:h\)\(\d\+\)\%(.*\)',
>'\1'.'\=submatch(1)', '')
>The result is:
> Bitstream_Vera_Sans_Mono:h=submatch(1)
>
>

A substitution is either an expression which starts with '\=', or it is
a string,
which can contain special sub-replace patterns like '\1'.
You can't mix it.

-ap

--
Ich hab geträumt, der Krieg wär vorbei.

Hari Krishna Dara

unread,
Oct 1, 2007, 6:53:24 PM10/1/07
to vim...@googlegroups.com

This is not a bug. For expressions to work, the replacement pattern
should start with "\=". If you want to use "\=" you have to use string
constants (with "." to append them) and submatch()s to assemble your
replacement string.

--
HTH,
Hari

David Fishburn

unread,
Oct 1, 2007, 7:13:02 PM10/1/07
to vim...@googlegroups.com
On 10/1/07, Hari Krishna Dara <hari...@gmail.com> wrote:
>
>
> On Mon, 1 Oct 2007 at 6:44pm, David Fishburn wrote:
>
> >
> > On 10/1/07, David Fishburn <dfishb...@gmail.com> wrote:

...

> > Little more progress on this, looks like I am running into a Vim bug.
> >
> > This works:
> > echo substitute(&guifont, '\%(.*:h\)\(\d\+\)\%(.*\)', '\=submatch(0)', '')
> > Meaning I get this back:
> > Bitstream_Vera_Sans_Mono:h11:b:cANSI
> >
> > This does NOT work:
> > echo substitute(&guifont, '\(.*:h\)\(\d\+\)\%(.*\)', '\1\=submatch(1)', '')
> > The result is:
> > Bitstream_Vera_Sans_Mono:h=submatch(1)
>
> This is not a bug. For expressions to work, the replacement pattern
> should start with "\=". If you want to use "\=" you have to use string
> constants (with "." to append them) and submatch()s to assemble your
> replacement string.


Ahh, thank you Hari. That makes sense.

So I have this working this way (thanks to your suggestion):
nnoremap <C-Up> :silent! let &guifont = substitute(&guifont,


'\(.*:h\)\(\d\+\)\(.*\)',

'\=submatch(1).eval(submatch(2)+1).submatch(3)', '')<CR>
nnoremap <C-Down> :silent! let &guifont = substitute(&guifont,


'\(.*:h\)\(\d\+\)\(.*\)',

'\=submatch(1).eval(submatch(2)-1).submatch(3)', '')<CR>


But then realized, it is a bit redundant and reduced it to the final
working version:
nnoremap <C-Up> :silent! let &guifont = substitute(&guifont, '\d\+',
'\=eval(submatch(0)+1)', '')<CR>
nnoremap <C-Down> :silent! let &guifont = substitute(&guifont, '\d\+',
'\=eval(submatch(0)-1)', '')<CR>

I will add this as a new Vim Tip, once I figure out how to use the new
system with login's and all.

Thanks for the help.
Dave

David Fishburn

unread,
Oct 1, 2007, 8:03:52 PM10/1/07
to vim...@googlegroups.com
> I will add this as a new Vim Tip, once I figure out how to use the new
> system with login's and all.

http://vim.wikia.com/wiki/Increase/decrease_fontsize_using_a_map_ala_FireFox

My only issue with it currently is the dreaded "Hit ENTER or type
command to continue" in some cases. The font has to get _pretty_ big
or _very_ small to trigger it, but it is there.

I tried adding let saved_more = &more \| set nomore ... \| let &more =
saved_more around it but that just made the command longer which
trigger the prompt sooner. I could put it in a function, but that
seems overkill.

Enjoy.
Dave

John Beckett

unread,
Oct 1, 2007, 11:11:18 PM10/1/07
to vim...@googlegroups.com
David Fishburn wrote:
>> I will add this as a new Vim Tip, once I figure out how to
>> use the new system with login's and all.
>
> http://vim.wikia.com/wiki/Increase/decrease_fontsize_using_a_m
> ap_ala_FireFox

Good work. Here are a couple of comments on the wikitext (the text you typed
in).

You have the line:
:echo &guifont

However, the leading ':' causes an indent (and '::' would give more indent).

The simplest fix is to insert a space before the ':'. A leading space causes
the line to be treated as if it were in <pre>...</pre> tags.

You used multiple spaces to align some text. That won't work unless in a
<pre> block. I would not bother trying to align (it is possible to enter
some magic to get a table, but the effort is often not worthwhile).

However, you might like to add '<br>' to lines where you want to force a
line break. In html, you might put <br />, but just <br> is fine in
wikitext. For example, you might want:

Indicates:<br>

If you edit the tip, please put a short comment in the Summary box
("Improved formatting"), and use the 'Show preview' button to check before
saving.

John

key...@googlemail.com

unread,
Oct 3, 2007, 8:09:34 AM10/3/07
to vim_use
Hi,

thanks for the nice macros to increase and decrease the font-size.
I use them, but encounter the following problem:

I use 7.1.132 on ubuntu with a gnome desktop and devilspie to
place and resize my applications as i wish. gvim is
automatically made fullscreen with no decoration
(menubar, windowtitle, etc). when i now resize the
font obviously there is a mismatch in the current
gvim-window-size. if i reduce the font size, the right
hand side, and the lower part of the vim window are
gray. if i increase the fontsize, i will not be able to read
the status or command line.

Is there an automatic way to "redraw" gvim to match the
current window size?

cheers,
Keyan


On Oct 1, 10:48 pm, "David Fishburn" <dfishburn....@gmail.com> wrote:
> My most used feature ofFireFoxis the ability to quickly and easily

Tony Mechelynck

unread,
Oct 3, 2007, 12:02:17 PM10/3/07
to vim...@googlegroups.com
key...@googlemail.com wrote:
> Hi,
>
> thanks for the nice macros to increase and decrease the font-size.
> I use them, but encounter the following problem:
>
> I use 7.1.132 on ubuntu with a gnome desktop and devilspie to
> place and resize my applications as i wish. gvim is
> automatically made fullscreen with no decoration
> (menubar, windowtitle, etc). when i now resize the
> font obviously there is a mismatch in the current
> gvim-window-size. if i reduce the font size, the right
> hand side, and the lower part of the vim window are
> gray. if i increase the fontsize, i will not be able to read
> the status or command line.
>
> Is there an automatic way to "redraw" gvim to match the
> current window size?
>
> cheers,
> Keyan

Instead of making gvim fullscreen by means of some external application Vim
knows nothing about, do it by Vim means, just after setting the 'guifont':

a) in the vimrc:

if has('gui_running')
" detect which 'guifont' format is required by the current gvim
if has('gui_gtk2')
set gfn=Courier\ New\ 9
elseif has('gui_photon')
set gfn=Courier\ New:s9
elseif has('gui_kde')
set gfn=Courier\ New/9/-1/5/50/0/0/0/1/0
elseif has('x11')
set gfn=*-courier-medium-r-normal-*-*-90-*-*-m-*-*
else
set gfn=Courier_New:h9:cDEFAULT
endif
" make sure the gvim window starts at top left
if exists(':winpos') == 2
winpos 0 0
endif
" maximize the gvim window
set lines=99999 columns=99999
endif

b) Doing it manually (e.g. for GTK2):

:set gfn=Andale\ Mono\ 8 lines=99999 columns=99999

Note: When changing the 'guifont' manually, you should already know (or find
out) which of the 5 possible mutually incompatible formats your version requires.

c) when changing the font in a user command or function:

if has('gui_running')
call FontResize()
set lines=99999 columns=99999
endif


Best regards,
Tony.
--
Cynic, n.:
A blackguard whose faulty vision sees things as they are, not
as they ought to be. Hence the custom among the Scythians of plucking
out a cynic's eyes to improve his vision.
-- Ambrose Bierce, "The Devil's Dictionary"

Zbikow

unread,
Oct 5, 2007, 2:50:26 AM10/5/07
to vim_use
This might not work as it did not for me. After invoking font
selection window by "set guifont=*" i saw that that by default i'm
using a font (fixedsys) which is not scalable (the size list contains
only one size). After changing the fonts to scalable everything works.

HTH others if they have the same problem

regards
Zbikow

Reply all
Reply to author
Forward
0 new messages