summaryrefslogtreecommitdiffstats
path: root/en_US/docs-vim.xml
blob: 9175aefb8a062a6aef008e4c3142af2abe97646b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<!-- $Id: docs-vim.xml,v 1.1 2006/11/23 02:24:17 pfrields Exp $ -->
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [

<!-- *************** Bring in Fedora entities *************** -->
<!ENTITY % FEDORA-ENTITIES-EN SYSTEM "fdp-entities.ent">
%FEDORA-ENTITIES-EN;

]>


  <chapter id="ch-vim">
   <title>VIM and DocBook</title>
    
    <indexterm>
      <primary>VIM</primary>
    </indexterm>
    
    <para>
      VIM has many features to help you write XML content such as DocBook,
      including syntax highlighting and customizable key bindings.
      Additionally, one can easily use external programs from VIM for features
      such as spell-checking. 
      This chapter assumes you already know generally how to use VIM; if you
      want to learn how, try the <command>vimtutor</command> or by typing
      <userinput>:help tutor</userinput> from inside VIM.
    </para>
    
    <sect1 id="s1-vimrc-file">
      <title>Setting Up Your <filename>.vimrc</filename> File</title>

      <indexterm>
	<primary>VIM</primary>
	<secondary>configuration file</secondary>
      </indexterm>

      <para>
        Below is a short sample <filename>.vimrc</filename> file that turns on
	some VIM features useful for editing SGML or XML content such as 
	DocBook:
<screen>
<computeroutput>" Turn off vi compatibility settings like limited undo
set nocompatible
" Syntax highlighting based on file extension
syntax on
" Automatically insert newlines after 80 characters
set textwidth=80
" Automatically indent
set autoindent
" Match SGML tags with %
source $VIMRUNTIME/macros/matchit.vim</computeroutput>
</screen>
      </para>
      <note>
      <para>
      Some of these features require the <filename>vim-enhanced</filename>
      package to be installed.  If you are using or the
      <filename>vim-minimal</filename> package, or if you are using an older
      version of VIM, you may not have the
      <filename>$VIMRUNTIME/macros/matchit.vim</filename> file. You can still
      download <ulink
      url="http://vim.org/scripts/script.php?script_id=39">matchit.zip from
      Vim.org</ulink> and load it separately.
      </para>
      </note>
    </sect1>

    <sect1 id="s1-vim-keymapping">
      <title>Keymapping with VIM</title>
      
      <para>
      VIM can speed up your DocBook creation by mapping frequently typed tags
      (or any words or phrases) onto short key combinations.  By default, the
      keymap leader is the backslash (<literal>\</literal>), but it can be
      redefined with a command like <userinput>let mapleader =
      ","</userinput>. There are two ways to use the following example;
      you can put it directly in your <filename>.vimrc</filename>, or you
      can save it in a separate file and load it with a 
      <userinput>source</userinput> command in your
      <filename>.vimrc</filename>.
<screen>
<![CDATA[let mapleader = ","

" skip ahead to after next tag without leaving insert mode
imap <leader>e <esc>/><cr>:nohlsearch<cr>a

" common tags that start a new text block
imap<leader>pa <para><cr></para><esc>O
imap<leader>s1 <sect1 id=""><cr><para><esc>jo</sect1><esc>O
imap<leader>pl <programlisting><cr></programlisting><esc>O<esc>0i
imap<leader>cp <computeroutput></computeroutput><esc>O<esc>0i

" common tags that are placed inline
" use <esc>F>a
imap<leader>en <envar></envar><esc>F>a
imap<leader>fi <filename></filename><esc>F>a
imap<leader>lt <literal></literal><esc>F>a
imap<leader>re <replaceable></replaceable><esc>F>a
imap<leader>ui <userinput></userinput><esc>F>a
imap<leader>ul <ulink url=""></ulink><esc>F>a
imap<leader>si <systemitem></systemitem><esc>F>a
imap<leader>us <systemitem class="username"></systemitem><esc>F>a
imap<leader>sy <systemitem class="systemname"></systemitem><esc>F>a
imap<leader>cm <command></command><esc>F>a                                  
" entities
imap <leader>> &gt;
imap <leader>< &lt;]]>
</screen>
      </para>
      <para>
      Unfortunately, there is not currently a complete macro set for all
      DocBook commands, so you will need to define them yourself or customize
      the definitions in the examples from <xref
      linkend="s1-vim-additional-resources"></xref>.
      </para>
    </sect1>

    <sect1 id="s1-vim-additional-resources">
      <title>Additional VIM Resources</title>

      <para>
      Additional information about VIM may be found from:
      </para>

      <itemizedlist>
	<listitem>
	  <para><ulink url=
	  "http://newbiedoc.sourceforge.net/text_editing/vim.html#JESSE-SGMLRC">
	  Example sgml-vimrc</ulink> from the <citetitle>Beginner's guide to
	  Vi Improved (VIM)</citetitle> 
	  </para>
	</listitem>
	<listitem> 
	  <para>The <ulink url="http://tnerual.eriogerg.free.fr/vim.html">VIM 
	  Quick Reference Card</ulink> 
	  </para>
	</listitem>
	<listitem>
	  <para>
	  <ulink url="http://www.pinkjuice.com/howto/vimxml/">Vim as XML
	  Editor</ulink>
	  </para>
	</listitem>
	<listitem>
	  <para>
	  The <citetitle>VIM REFERENCE MANUAL</citetitle>, which comes with
	  the <filename>vim-common</filename> package &mdash;
	  <filename>/usr/share/vim/<replaceable>&lt;version&gt;</replaceable>/doc/intro.txt</filename>
	  or type <userinput>:help intro</userinput> from within VIM
	  </para>
	</listitem>
	
      </itemizedlist>

    </sect1>
  </chapter>