Permalink
Browse files

Last pass over GUI chapter before release.

  • Loading branch information...
1 parent f014b21 commit 84d7fdbbadd2fdfac3e369861f10eede604f1d79 @runpaint committed May 1, 2009
View
2 TODO
@@ -41,3 +41,5 @@ STATUS LINE
* Screenshot
PRINTING
* Write?
+MAX. SCREEN SPACE
+ * Screenshots
@@ -33,7 +33,7 @@ <h3 id="deleting-text">Deleting Text</h3>
<p>Vim doesn't just <i>delete</i> text; it saves it to a <i>register</i>
first. If you delete a small amount of text (less than a line), it's stored in
a register named <tt>"-</tt>. Otherwise, it's stored in <tt>"0</tt>, whose
-existing contents are moved to <tt>"1</tt>, whose existing&ldots;right up to
+existing contents are moved to <tt>"1</tt>, whose existing&hellip;right up to
<tt>"9</tt>. This allows you easy access to previously deleted text inasmuch
as you can recall, say, the 3<sup>rd</sup> most recently deleted line with
<kbd>"2p</kbd>. Even more usefully, you can use <tt>:registers</tt> to view
View
@@ -0,0 +1 @@
+<h2>GUI (GVim)</h2>
@@ -0,0 +1,65 @@
+<h3 id="changing-the-font">Changing the Font</h3>
+
+<h4>Problem</h4>
+
+<p>You want to display the text in a different font.</p>
+
+<p>For example, the current font isn't particularly readable, or is too large.</p>
+
+<h4>Solution</h4>
+
+<p>Standard Vim uses the font from the terminal it is run under. Gvim,
+however, gives you full control over the font face and size.</p>
+
+<p>The command <tt>:set guifont <var>font-name</var></tt> changes the current
+font to <var>font-name</var>. The font name can be followed by a size. There
+are, unfortunately, some platform-specific differences at this
+point&hellip;</p>
+
+<blockquote class="callout">
+
+ <h5>Specifying <tt>guifont</tt> in an Operating-System-Specific Manner</h5>
+
+ <h6>Linux</h6>
+
+ <ul>
+ <li>The font name and size are space separated.</li>
+ <li>Spaces and commas need to be backslash escaped.</li>
+ </ul>
+
+ <p>For example: <tt>:set guifont=Andale\ Mono\ 11</tt>.</p>
+
+ <h6>Mac</h6>
+
+ <ul>
+ <li>The font name and size are colon separated.</li>
+ <li>The size is prefixed with a <tt>h</tt>.</li>
+ <li>Spaces and commas need to be backslash escaped.</li>
+ </ul>
+
+ <p>For example: <tt>:set guifont=Monaco:h11</tt>.
+
+ <h6>Windows</h6>
+
+ <ul>
+ <li>The font name and size are colon separated.</li>
+ <li>Spaces in font names can be replaced with underscores (<tt>_</tt>).</li>
+ </ul>
+
+ <p>For example: <tt>:set guifont=Andale_Mono:11</tt>.</p>
+
+</blockquote>
+
+<h4>Discussion</h4>
+
+<p>To change the font you need to know its name. On most operating systems you
+can request a GUI font chooser with the command <tt>:set guifont=*</tt>. Linux
+users can also use the <tt>xlsfonts</tt> utility to see a list of available
+fonts.</p>
+
+<p>If the font you've specified can not be found, Vim complains. To avoid this
+you can specify multiple fonts in order of preference with a comma separated
+list. The first valid font is loaded. For example: <tt>:set
+ guifont=Screen15,\ 7x13</tt>. This approach is particularly useful if you
+use your Vim configuration on multiple computers, or if you simply want it to
+be portable. </p>
@@ -1,17 +1,16 @@
-<h3>Maximising Screen Space</h3>
+<h3 id="#maximising-screen-space">Maximising Screen Space</h3>
<h4>Problem</h4>
-<p><span class="todo">Should title be: Maximising Screen Real Estate?</span></p>
-
-<p>The toolbar, menubar, and other GUI artifacts take up too much of your screen;
-you want to hide them.</p>
+<p>The toolbar, menubar, and other GUI artifacts take up too much of your
+screen; you want to hide them.</p>
<h4>Solution</h4>
<p>Modify the <i>guioptions</i> variable. Gvim decides which elements of the
GUI to display based on the value of <i>guioptions</i>. This is a series of
-letters, each of which refer to some specfic element. Some examples follow:</p>
+letters, each of which refer to some specfic element. Some examples
+follow:</p>
<ul>
<li><i>m</i> - Display a menu bar.</li>
@@ -25,36 +24,28 @@
<li><i>b</i> - Display the horizontal scrollbar.</li>
</ul>
-<p>So, to hide the menu bar, toolbar, and scrollbars you could
-use <tt>:set guioptions-=mTrlb</tt>. To display a hidden element use
-<i>+=</i> instead, e.g. <tt>:set guioptions+=T</tt>.</p>
-
-<p><span class="todo">Screenshots: before/after</span></p>
+<p>So, to hide the menu bar, toolbar, and scrollbars you could use <tt>:set
+ guioptions-=mTrlb</tt>. To display a hidden element use <i>+=</i> instead,
+e.g. <tt>:set guioptions+=T</tt>.</p>
<h4>Discussion</h4>
-<p>If you decide that you want to restore one or more of these elements you can
-simply execute <tt>:set guioptions+=m</tt>, for example. This can be
+<p>If you decide that you want to restore one or more of these elements you
+can simply execute <tt>:set guioptions+=m</tt>, for example. This can be
cumbersome, however, as it requires you to remember the significance of each
letter.</p>
-<p>The following stanza in your <i>gvimrc</i>\footnote{The configuration file
-for Gvim. Its use is explained in recipe~\ref{sec:configuring}} assigns
-<tt>&lt;F11&gt;</tt> to toggle the display of extraneous GUI elements:</p>
-
-<p><span class="todo">Should these variables be in a different scope?</span></p>
+<p>The following stanza in your <a href="#configuring-vim"><tt>gvimrc</tt></a>
+assigns <tt>&lt;F11&gt;</tt> to toggle the display of extraneous GUI
+elements:</p>
-<p><span class="todo">Display apostrophes correctlty</span></p>
-
-<pre><code>function ToggleGUICruft()
+<pre><code>
+function ToggleGUICruft()
let opts = ['T','m','r','L']
- let sign= &amp;amp;guioptions =~# 'T' ? '-' : '+'
+ let sign = &amp;guioptions =~# 'T' ? '-' : '+'
for opt in opts
exec('set guioptions'.sign.'='.opt)
endfor
endfunction
map &lt;F11&gt; &lt;Esc&gt;:call ToggleGUICruft()&lt;cr&gt;
</code></pre>
-
-<p><span class="todo">Suggest Gnome keyboard shortcuts for
-fullscreen</span></p>
@@ -1,31 +1,33 @@
-<h3>Creating Menus and Toolbar Buttons</h3>
+<h3 id="creating-menus-toolbar-buttons">Creating Menus and Toolbar Buttons</h3>
<h4>Problem</h4>
<p>You want to add your own commands to Gvim's menus, or toolbar, for quick
access.</p>
-<p>For example, you've written a function that automatically writes bestselling
-novels for you, but you're not willing to use it if you have to type its name
-every time; you want to invoke it by selecting a menu option. </p>
+<p>For example, you've written a function that automatically writes
+bestselling novels for you, but you're not willing to use it if you have to
+type its name every time; you want to invoke it by selecting a menu option.
+</p>
<h4>Solution</h4>
-<p>Use <tt>:set amenu <var>menu</var> <var>command</var></tt> to map a menu item to a command.
-This is the GUI equivalent of <tt>:map</tt><span clas="fn">Recipe~\ref{sec:key-map}
-explains the use of <tt>:map</tt> in key mappings.</span>.</p>
+<p>Use <tt>:set amenu <var>menu</var> <var>command</var></tt> to map a menu
+item to a command. This is the GUI equivalent of <a
+ href="#creating-keyboard-shortcuts-with-key-mappings"><tt>:map</tt></a>.</p>
-<p>For example, <tt>:amenu Help.Op&amp;ions :help options&lt;cr&gt;</tt> adds a
-new item called <i>Options</i> to the <i>Help</i> menu, which invokes
+<p>For example, <tt>:amenu Help.Op&amp;ions :help options&lt;cr&gt;</tt> adds
+a new item called <i>Options</i> to the <i>Help</i> menu, which invokes
<tt>:help options</tt>. The ampersand (<i>&amp;</i>) signifies that the
character it prefixes can be used as a keyboard shortcut, so in this case
<kbd><kbd>&lt;Alt&gt;</kbd>+<kbd>h</kbd>+<kbd>t</kbd></kbd> selects this
command.</p>
<h4>Discussion</h4>
-<p>You're not restricted to adding items to existing menus; you can create a new
-top-level menu simply by specifying a name not currently in use. For example:</p>
+<p>You're not restricted to adding items to existing menus; you can create a
+new top-level menu simply by specifying a name not currently in use. For
+example:</p>
<pre><code>
:amenu &lt;silent&gt;&amp;Vim.vim\.org :!xdg-open http://www.vim.org/&lt;cr&gt;
@@ -35,22 +37,23 @@
<kbd>V</kbd>. It will contain one entry named <i>vim.org</i> (we escape the
<i>.</i> because otherwise it would create a <i>vim</i> entry which in turn
contain an <i>org</i> item). When invoked it will open the Vim website on
-systems adhering to the Free Desktop<span class="todo">link</span>
-specification. The <tt>&lt;silent&gt;</tt> prefix prevents the command from
-being echoed on the command-line. </p>
-
-<p>If you want to add a dashed separator line between menu items use a menu item
-named <i>-SEP-</i> and an empty command, e.g. <tt>:amenu Help.-SEP- :</tt>.</p>
-
-<p>To control where a top-level menu appears relative to its neighbours you need
-to prefix <tt>amenu</tt> with a numeric priority: the lower the number the
-further right the menu's position. For example, <tt>:5amenu First.first :echo
-'first'&lt;cr&gt;</tt> creates a top-level menu named <i>First</i> that
-appears before all of the others.</p>
-
-<p>The same approach can be used to position menu items. For example, <tt>:amenu
-9999.1 Help.first :echo 'first'&lt;cr&gt;</tt> adds a <i>first</i> item to the
-<i>Help</i> menu, which appears before the other items.</p>
+systems adhering to the <i>Free Desktop Specification</i>. The
+<tt>&lt;silent&gt;</tt> prefix prevents the command from being echoed on the
+command-line. </p>
+
+<p>If you want to add a dashed separator line between menu items use a menu
+item named <i>-SEP-</i> and an empty command, e.g. <tt>:amenu Help.-SEP-
+ :</tt>.</p>
+
+<p>To control where a top-level menu appears relative to its neighbours you
+need to prefix <tt>amenu</tt> with a numeric priority: the lower the number
+the further right the menu's position. For example, <tt>:5amenu First.first
+ :echo 'first'&lt;cr&gt;</tt> creates a top-level menu named <i>First</i>
+that appears before all of the others.</p>
+
+<p>The same approach can be used to position menu items. For example,
+<tt>:amenu 9999.1 Help.first :echo 'first'&lt;cr&gt;</tt> adds a <i>first</i>
+item to the <i>Help</i> menu, which appears before the other items.</p>
<p>You can also use <tt>:amenu</tt> to add a new toolbar icon: </p>
@@ -0,0 +1,114 @@
+<h3 id="using-vim-as-file-manager">Using Vim as a File Manager</h3>
+
+<h4>Problem</h4>
+
+<p>You want to use Vim to manage your file system in a similar way to
+<i>Nautilus</i>, <i>Midnight Commander</i>, or <i>Windows Explorer</i>.</p>
+
+<p>For example, you want to rename files matching a certain pattern. Or you
+want to compress the contents of a directory.</p>
+
+<h4>Solution</h4>
+
+<p><a href="#browsing-directories">Browsing Directories</a> explains the
+basics of working with directories in Vim, so read it first.</p>
+
+<blockquote class="callout">
+
+ <h5>Marking Files</h5>
+
+ <p>To operate on files you must first <i>mark</i> them (this does not have
+ any relation to the <a href="#navigating-marks"><i>marks</i>
+ feature</a>).</p>
+
+ <ul>
+ <li><b>Mark</b> the file under the cursor: <kbd>mf</kbd> (mnemonic:
+ <i>m</i>ark <i>f</i>ile).</li>
+ <li><b>Unmark</b> the marked file under the cursor: <kbd>mf</kbd>.</li>
+ <li>Mark files <b>matching a Vim regular expression</b>: <kbd>mr</kbd>
+ (mnemonic: <i>m</i>ark with <i>r</i>egular expression). You're then
+ prompted for a <a href="#creating-regular-expressions">pattern</a>.</li>
+ <li><b>Unmark all</b> files: <kbd>mu</kbd> (mnemonic: <i>m</i>arks
+ <i>u</i>ndo).</li>
+ <li><b>Visually</b> mark files:
+ <kbd><kbd>&lt;Shift&gt;</kbd>-<kbd>v</kbd></kbd>, then <kbd>j</kbd> and
+ <kbd>k</kbd> to change the selection area.</li>
+ </ul>
+
+</blockquote>
+
+<p>You can operate on a single file or a group of them. In the latter case,
+you need to select files by marking them, as explained in the sidebar. You can
+now perform various operations on these files such as:</p>
+
+<ul>
+ <li><b>Deletion</b>: hit <kbd>D</kbd>. You're prompted for each file you've
+ selected. Answering <kbd>a</kbd> deletes them all without asking you any
+ more.</li>
+ <li><b>Renaming</b>: hit <kbd>R</kbd>. For each file you're prompted for its
+ new name.</li>
+ <li><b>Copying/Moving</b>: Hit <kbd>mt</kbd> (mnemonic: <i>m</i>ark
+ <i>t</i>arget) in the target directory. Change to the directory containing
+ the source files, select them, then hit <kbd>mc</kbd> (mnemonic: <i>m</i>arked
+ <i>c</i>opy) to copy or <kbd>mm</kbd> (mnemonic: <i>m</i>arked
+ <i>m</i>ove) to move.</li>
+ <li><b>Diff</b>: To <a href="#viewing-differences-between-files">diff</a> up
+ to three marked files, use <kbd>md</kbd> (mnemonic: <i>m</i>arked
+ <i>d</i>iff).</li>
+ <li><b>Printing</b>: hit <kbd>mp</kbd> to print marked files (mnemonic:
+ <i>m</i>ark <i>p</i>rint).</li>
+ <li><b>Execute shell command</b>: hit <kbd>mx</kbd> (mnemonic:
+ <i>m</i>arked e<i>x</i>ecute). (See the discussion for examples).</li>
+ <li><b>Compress/Decompress</b>: hit <kbd>mz</kbd> (mnemonic: <i>m</i>arked
+ g<i>z</i>ip). (Other compression utilities can be used instead of
+ <tt>gzip</tt>, but the Vim command remains the same).</li>
+ <li><b>Open</b> in horizontal split: hit <kbd>o</kbd> (mnemonic:
+ <i>o</i>pen).</li>
+</ul>
+
+
+<h4>Discussion</h4>
+
+<p>Vim can be used as a pretty well-featured file manager. In fact, given that
+it can be scripted, key mapped, and configured in concert with Vim, as well as
+seamlessly operate on remote directories, it is arguably better.</p>
+
+<p>Perhaps the most interesting command is <kbd>mx</kbd>. This allows you to
+pass the list of marked files to an external command. You're prompted for a
+command line, in which you can use the <tt>%</tt> wildcard. Vim then loops
+through the selected files and calls the command for each one, substituting
+<tt>%</tt> for the filename. </p>
+
+<p>For example, using a POSIX-compatiable system, select three files
+(<tt>foo.txt</tt>, <tt>bar.txt</tt>, and <tt>glark</tt>) with <kbd>mf</kbd>.
+Hit <kbd>mx</kbd> and enter <tt>cat %&gt;&gt;foo-bar-glark</tt>. Vim will now
+execute:</p>
+
+<pre><code>
+cat foo.txt &gt;&gt;foo-bar-glark
+cat bar.txt &gt;&gt;foo-bar-glark
+cat glark &gt;&gt;foo-bar-glark
+</code></pre>
+
+<p><tt>foo-bar-glark</tt> will now contain the contents of each file in turn.</p>
+
+<p>The <kbd>mz</kbd> command also bears further discussion. It toggles the
+state of the selected files between compressed and decompressed. </p>
+
+<p>If a file is uncompressed, Vim attempts to compress it. By default it uses
+<tt>gzip</tt>, but you can change this by modifying the
+<tt>g:netrw_compress</tt> variable. For example, to use Bzip2: <tt>:let
+ g:netrw_compress=bzip2</tt>.</p>
+
+<p>For decompression Vim uses an extension-to-program mapping:</p>
+
+<ul>
+ <li><tt>.tar</tt> - <tt>tar -xf</tt></li>
+ <li><tt>.gz</tt> - <tt>gunzip</tt></li>
+ <li><tt>.bz2</tt> - <tt>bunzip2</tt></li>
+ <li><tt>.zip</tt> - <tt>unzip</tt></li>
+</ul>
+
+<p>For example, if a filename ends with <tt>.zip</tt> Vim decompresses it by
+calling <tt>unzip <var>zip-file</var></tt>. To add support for another format
+use <tt>:let g:netrw_decompress[<var>ext</var>] = <var>prog</var></tt>.</p>
Oops, something went wrong.

0 comments on commit 84d7fdb

Please sign in to comment.