Wikia

Vim Tips Wiki

Changes: Change guifont to see more of your file

Edit

Back to page

(Adjust previous/next navigation)
(Remove html character entities)
 
Line 14: Line 14:
 
}}
 
}}
 
Sometimes, its nice to be able to quickly jump to a smaller font to see more of the file you're editing at once, and jump back again to make the text more readable. I use these mapping:
 
Sometimes, its nice to be able to quickly jump to a smaller font to see more of the file you're editing at once, and jump back again to make the text more readable. I use these mapping:
 
 
<pre>
 
<pre>
:map &lt;f9&gt; :set guifont=Lucida_Console:h9:cANSI&lt;Cr&gt;
+
:map <F9> :set guifont=Lucida_Console:h9:cANSI<CR>
:map &lt;f11&gt; :set guifont=Lucida_Console:h11:cANSI&lt;Cr&gt;
+
:map <F11> :set guifont=Lucida_Console:h11:cANSI<CR>
:map &lt;S-f9&gt; :set guifont=Courier_New:h9:cANSI&lt;Cr&gt;
+
:map &lt;S-f9> :set guifont=Courier_New:h9:cANSI<CR>
:map &lt;S-f11&gt; :set guifont=Courier_New:h11:cANSI&lt;Cr&gt;
+
:map &lt;S-f11> :set guifont=Courier_New:h11:cANSI<CR>
 
</pre>
 
</pre>
   
9 and 11 are my mnemonics for the font size. &lt;f10&gt; wouldn't work for me because it activates the menu. Of course, this only works in gvim.
+
9 and 11 are my mnemonics for the font size. F10 wouldn't work for me because it activates the menu. Of course, this only works in gvim.
   
 
==Comments==
 
==Comments==
 
For decreasing/increasing the current font size by one point you can also use these mappings:
 
For decreasing/increasing the current font size by one point you can also use these mappings:
 
 
<pre>
 
<pre>
nmap &lt;F12&gt; :let &amp;guifont = substitute(&amp;guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) - 1)', '')&lt;cr&gt;
+
nmap <F12> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) - 1)', '')<CR>
nmap &lt;S-F12&gt; :let &amp;guifont = substitute(&amp;guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) + 1)', '')&lt;cr&gt;
+
nmap &lt;S-F12> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) + 1)', '')<CR>
 
</pre>
 
</pre>
   
Line 36: Line 34:
 
----
 
----
 
In addition you can set the blank space between the lines:
 
In addition you can set the blank space between the lines:
+
<pre>
"number of pixel lines to use between lines
+
"number of pixel lines to use between lines
set lsp=0
+
set lsp=0
  +
</pre>
   
 
----
 
----
Line 45: Line 43:
 
You mileage may vary regarding the point size, depending on the your screen resolution and whether you are using small fonts or large ones. The same issues apply to 75 dpi vs 100 dpi fonts on X11.
 
You mileage may vary regarding the point size, depending on the your screen resolution and whether you are using small fonts or large ones. The same issues apply to 75 dpi vs 100 dpi fonts on X11.
   
On Windows, you can 'set wak=no' to prevent &lt;F10&gt; from bringing up the menu.
+
On Windows, you can 'set wak=no' to prevent <F10> from bringing up the menu.
   
 
----
 
----
Line 52: Line 50:
 
<pre>
 
<pre>
 
function! ScaleFontUp()
 
function! ScaleFontUp()
let gf_size_whole = matchstr(&amp;guifont, '\(\:h\)\@&lt;=\d\+')
+
let gf_size_whole = matchstr(&guifont, '\(\:h\)\@<=\d\+')
let gf_size_frac = matchstr(&amp;guifont, '\(\:h\d\+\.\)\@&lt;=\d\=')
+
let gf_size_frac = matchstr(&guifont, '\(\:h\d\+\.\)\@<=\d\=')
 
let font_size = gf_size_whole * 10 + gf_size_frac
 
let font_size = gf_size_whole * 10 + gf_size_frac
 
let font_size = font_size + 5
 
let font_size = font_size + 5
Line 59: Line 57:
 
let gf_size_frac = font_size - gf_size_whole * 10
 
let gf_size_frac = font_size - gf_size_whole * 10
 
let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
 
let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
let &amp;guifont = substitute(&amp;guifont, '\:h.\{-}\:', new_font_size, '')
+
let &guifont = substitute(&guifont, '\:h.\{-}\:', new_font_size, '')
 
endfunction
 
endfunction
   
 
function! ScaleFontDown()
 
function! ScaleFontDown()
let gf_size_whole = matchstr(&amp;guifont, '\(\:h\)\@&lt;=\d\+')
+
let gf_size_whole = matchstr(&guifont, '\(\:h\)\@<=\d\+')
let gf_size_frac = matchstr(&amp;guifont, '\(\:h\d\+\.\)\@&lt;=\d\=')
+
let gf_size_frac = matchstr(&guifont, '\(\:h\d\+\.\)\@<=\d\=')
 
let font_size = gf_size_whole * 10 + gf_size_frac
 
let font_size = gf_size_whole * 10 + gf_size_frac
 
let font_size = font_size - 5
 
let font_size = font_size - 5
Line 70: Line 68:
 
let gf_size_frac = font_size - gf_size_whole * 10
 
let gf_size_frac = font_size - gf_size_whole * 10
 
let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
 
let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
let &amp;guifont = substitute(&amp;guifont, '\:h.\{-}\:', new_font_size, '')
+
let &guifont = substitute(&guifont, '\:h.\{-}\:', new_font_size, '')
 
endfunction
 
endfunction
   
nmap &lt;C-S-F11&gt; :call ScaleFontDown()&lt;CR&gt;
+
nmap <C-S-F11> :call ScaleFontDown()<CR>
nmap &lt;C-S-F12&gt; :call ScaleFontUp()&lt;CR&gt;
+
nmap <C-S-F12> :call ScaleFontUp()<CR>
 
</pre>
 
</pre>
   
Line 81: Line 79:
 
----
 
----
 
And if you don't ever use the guis.
 
And if you don't ever use the guis.
+
<pre>
set guioptions-=T "get rid of toolbar
+
set guioptions-=T "get rid of toolbar
set guioptions-=m "get rid of menu
+
set guioptions-=m "get rid of menu
  +
</pre>
   
 
----
 
----
Line 101: Line 99:
   
 
----
 
----
Hey the functions for scaling the font up and down are really great, but I had to change the "substitute"-line cause I have no colon after the ":hFONTSIZE".
+
The functions for scaling the font up and down are really great, but I had to change the "substitute"-line cause I have no colon after the ":hFONTSIZE".
   
 
The following line works with and without a colon after the fontsize.
 
The following line works with and without a colon after the fontsize.
+
<pre>
let &amp;guifont = substitute(&amp;guifont, '\:h[0-9\.]\+', new_font_size, '')
+
let &guifont = substitute(&guifont, '\:h[0-9\.]\+', new_font_size, '')
  +
</pre>
   
 
----
 
----

Latest revision as of 08:40, September 29, 2008

Duplicate tip

This tip is very similar to the following:

These tips need to be merged – see the merge guidelines.

Tip 414 Printable Monobook Previous Next

created January 30, 2003 · complexity basic · author benrich · version 5.7


Sometimes, its nice to be able to quickly jump to a smaller font to see more of the file you're editing at once, and jump back again to make the text more readable. I use these mapping:

:map <F9> :set guifont=Lucida_Console:h9:cANSI<CR>
:map <F11> :set guifont=Lucida_Console:h11:cANSI<CR>
:map <S-f9> :set guifont=Courier_New:h9:cANSI<CR>
:map <S-f11> :set guifont=Courier_New:h11:cANSI<CR>

9 and 11 are my mnemonics for the font size. F10 wouldn't work for me because it activates the menu. Of course, this only works in gvim.

CommentsEdit

For decreasing/increasing the current font size by one point you can also use these mappings:

nmap <F12> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) - 1)', '')<CR>
nmap <S-F12> :let &guifont = substitute(&guifont, ':h\(\d\+\)', '\=":h" . (submatch(1) + 1)', '')<CR>

Because notation of fonts is highly system dependent, this might only work on Windows.


In addition you can set the blank space between the lines:

"number of pixel lines to use between lines
set lsp=0

This tip probably works only for Windows but the basic idea can be applied to UNIX and other platforms.

You mileage may vary regarding the point size, depending on the your screen resolution and whether you are using small fonts or large ones. The same issues apply to 75 dpi vs 100 dpi fonts on X11.

On Windows, you can 'set wak=no' to prevent <F10> from bringing up the menu.


Try this script, which allows you to enlarge or shrink your font sizes by half-point increments. It works on Win32. The script is easily modified to deal with whole-point increments, of course.

function! ScaleFontUp()
  let gf_size_whole = matchstr(&guifont, '\(\:h\)\@<=\d\+')
  let gf_size_frac = matchstr(&guifont, '\(\:h\d\+\.\)\@<=\d\=')
  let font_size = gf_size_whole * 10 + gf_size_frac
  let font_size = font_size + 5
  let gf_size_whole = font_size / 10
  let gf_size_frac = font_size - gf_size_whole * 10
  let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
  let &guifont = substitute(&guifont, '\:h.\{-}\:', new_font_size, '')
endfunction

function! ScaleFontDown()
  let gf_size_whole = matchstr(&guifont, '\(\:h\)\@<=\d\+')
  let gf_size_frac = matchstr(&guifont, '\(\:h\d\+\.\)\@<=\d\=')
  let font_size = gf_size_whole * 10 + gf_size_frac
  let font_size = font_size - 5
  let gf_size_whole = font_size / 10
  let gf_size_frac = font_size - gf_size_whole * 10
  let new_font_size = ':h'.gf_size_whole.'.'.gf_size_frac.':'
  let &guifont = substitute(&guifont, '\:h.\{-}\:', new_font_size, '')
endfunction

nmap <C-S-F11> :call ScaleFontDown()<CR>
nmap <C-S-F12> :call ScaleFontUp()<CR>

Ctrl-Shift-F11 and -F12 reduces and enlarges the font sizes, respectively.


And if you don't ever use the guis.

set guioptions-=T "get rid of toolbar
set guioptions-=m "get rid of menu

Check guifont++.vim plugin script#593

When you drop it into your plugin directory, keys +, -, and = will be remapped: + makes the font larger by 1, - makes the font smaller by 1, = restores whatever the original font size was. And these key mappings can be redefined to something else (if you use your +, -, or = keys) in your vimrc file (see the plugin description for info on that).


Ever want that great looking unix font for gvim on win32?

I have, and I just found where you can get them: http://www.tomasek.cz/semtel/download/fonts.zip

This guy has hacked some of the most common unix fonts (.bdf format) into win32 .fon style fonts. Just drop the desired font into your c:\winnt\fonts directory and you're good to go!

My personal favorite is 7x14, which combined with vim's ":set lsp=0" makes my gvim screen on win32 look just like my vim terminal on unix. Horray!


The functions for scaling the font up and down are really great, but I had to change the "substitute"-line cause I have no colon after the ":hFONTSIZE".

The following line works with and without a colon after the fontsize.

let &guifont = substitute(&guifont, '\:h[0-9\.]\+', new_font_size, '')

Around Wikia's network

Random Wiki