1 *hgcommand.txt* Mercurial vim integration v0.2
4 HGCOMMAND REFERENCE MANUAL~
7 Author: Mathieu Clabaut <mathieu.clabaut@gmail.com>
8 Credits: Bob Hiestand <bob.hiestand@gmail.com>
9 Mercurial: http://www.selenic.com/mercurial
10 Mercurial (noted Hg) is a fast, lightweight Source Control Management
11 system designed for efficient handling of very large distributed projects.
13 ==============================================================================
14 1. Contents *hgcommand-contents*
16 Installation : |hgcommand-install|
17 HGCommand Intro : |hgcommand|
18 HGCommand Manual : |hgcommand-manual|
19 Customization : |hgcommand-customize|
20 Bugs : |hgcommand-bugs|
22 ==============================================================================
23 2. HGCommand Installation *hgcommand-install*
25 In order to install the plugin, place the hgcommand.vim file into a plugin'
26 directory in your runtime path (please see |add-global-plugin| and
29 HGCommand may be customized by setting variables, creating maps, and
30 specifying event handlers. Please see |hgcommand-customize| for more
34 The help file is automagically generated when the |hgcommand| script is
35 loaded for the first time.
37 ==============================================================================
39 3. HGCommand Intro *hgcommand*
42 The HGCommand plugin provides global ex commands for manipulating
43 HG-controlled source files. In general, each command operates on the
44 current buffer and accomplishes a separate hg function, such as update,
45 commit, log, and others (please see |hgcommand-commands| for a list of all
46 available commands). The results of each operation are displayed in a
47 scratch buffer. Several buffer variables are defined for those scratch
48 buffers (please see |hgcommand-buffer-variables|).
50 The notion of "current file" means either the current buffer, or, in the
51 case of a directory buffer, the file on the current line within the buffer.
53 For convenience, any HGCommand invoked on a HGCommand scratch buffer acts
54 as though it was invoked on the original file and splits the screen so that
55 the output appears in a new window.
57 Many of the commands accept revisions as arguments. By default, most
58 operate on the most recent revision on the current branch if no revision is
59 specified (though see |HGCommandInteractive| to prompt instead).
61 Each HGCommand is mapped to a key sequence starting with the <Leader>
62 keystroke. The default mappings may be overridden by supplying different
63 mappings before the plugin is loaded, such as in the vimrc, in the standard
64 fashion for plugin mappings. For examples, please see
65 |hgcommand-mappings-override|.
67 The HGCommand plugin may be configured in several ways. For more details,
68 please see |hgcommand-customize|.
70 ==============================================================================
71 4. HGCommand Manual *hgcommand-manual*
73 4.1 HGCommand commands *hgcommand-commands*
75 HGCommand defines the following commands:
91 This command performs "hg add" on the current file. Please note, this does
92 not commit the newly-added file.
94 :HGAnnotate *:HGAnnotate*
96 This command performs "hg annotate" on the current file. If an argument is
97 given, the argument is used as a revision number to display. If not given
98 an argument, it uses the most recent version of the file on the current
99 branch. Additionally, if the current buffer is a HGAnnotate buffer
100 already, the version number on the current line is used.
102 If the |HGCommandAnnotateParent| variable is set to a non-zero value, the
103 version previous to the one on the current line is used instead. This
104 allows one to navigate back to examine the previous version of a line.
106 The filetype of the HGCommand scratch buffer is set to 'HGAnnotate', to
107 take advantage of the bundled syntax file.
110 :HGCommit[!] *:HGCommit*
112 If called with arguments, this performs "hg commit" using the arguments as
115 If '!' is used with no arguments, an empty log message is committed.
117 If called with no arguments, this is a two-step command. The first step
118 opens a buffer to accept a log message. When that buffer is written, it is
119 automatically closed and the file is committed using the information from
120 that log message. The commit can be abandoned if the log message buffer is
121 deleted or wiped before being written.
123 Alternatively, the mapping that is used to invoke :HGCommit (by default
124 <Leader>hgc) can be used in the log message buffer to immediately commit.
125 This is useful if the |HGCommandCommitOnWrite| variable is set to 0 to
126 disable the normal commit-on-write behavior.
130 With no arguments, this performs "hg diff" on the current file against the
131 current repository version.
133 With one argument, "hg diff" is performed on the current file against the
136 With two arguments, hg diff is performed between the specified revisions of
139 This command uses the 'HGCommandDiffOpt' variable to specify diff options.
140 If that variable does not exist, then 'wbBc' is assumed. If you wish to
141 have no options, then set it to the empty string.
144 :HGGotoOriginal *:HGGotoOriginal*
146 This command returns the current window to the source buffer, if the
147 current buffer is a HG command output buffer.
151 Like ":HGGotoOriginal" but also executes :bufwipeout on all HG command
152 output buffers for the source buffer.
156 Performs "hg log" on the current file.
158 If an argument is given, it is passed as an argument to the "-r" option of
161 :HGRevert *:HGRevert*
163 Replaces the current file with the most recent version from the repository
164 in order to wipe out any undesired changes.
166 :HGReview *:HGReview*
168 Retrieves a particular version of the current file. If no argument is
169 given, the most recent version of the file on the current branch is
170 retrieved. Otherwise, the specified version is retrieved.
172 :HGStatus *:HGStatus*
174 Performs "hg status" on the current file.
176 :HGUpdate *:HGUpdate*
178 Performs "hg update" on the current file. This intentionally does not
179 automatically reload the current buffer, though vim should prompt the user
180 to do so if the underlying file is altered by this command.
182 :HGVimDiff *:HGVimDiff*
184 With no arguments, this prompts the user for a revision and then uses
185 vimdiff to display the differences between the current file and the
186 specified revision. If no revision is specified, the most recent version
187 of the file on the current branch is used.
189 With one argument, that argument is used as the revision as above. With
190 two arguments, the differences between the two revisions is displayed using
193 With either zero or one argument, the original buffer is used to perform
194 the vimdiff. When the other buffer is closed, the original buffer will be
195 returned to normal mode.
197 Once vimdiff mode is started using the above methods, additional vimdiff
198 buffers may be added by passing a single version argument to the command.
199 There may be up to 4 vimdiff buffers total.
201 Using the 2-argument form of the command resets the vimdiff to only those 2
202 versions. Additionally, invoking the command on a different file will
203 close the previous vimdiff buffers.
206 4.2 Mappings *hgcommand-mappings*
208 By default, a mapping is defined for each command. These mappings execute
209 the default (no-argument) form of each command.
212 <Leader>hgn HGAnnotate
215 <Leader>hgg HGGotoOriginal
216 <Leader>hgG HGGotoOriginal!
221 <Leader>hgv HGVimDiff
223 *hgcommand-mappings-override*
225 The default mappings can be overriden by user-provided instead by mapping
226 to <Plug>CommandName. This is especially useful when these mappings
227 collide with other existing mappings (vim will warn of this during plugin
228 initialization, but will not clobber the existing mappings).
230 For instance, to override the default mapping for :HGAdd to set it to
231 '\add', add the following to the vimrc: >
233 nmap \add <Plug>HGAdd
235 4.3 Automatic buffer variables *hgcommand-buffer-variables*
237 Several buffer variables are defined in each HGCommand result buffer.
238 These may be useful for additional customization in callbacks defined in
239 the event handlers (please see |hgcommand-events|).
241 The following variables are automatically defined:
243 b:hgOrigBuffNR *b:hgOrigBuffNR*
245 This variable is set to the buffer number of the source file.
249 This variable is set to the name of the hg command that created the result
251 ==============================================================================
253 5. Configuration and customization *hgcommand-customize*
256 The HGCommand plugin can be configured in two ways: by setting
257 configuration variables (see |hgcommand-options|) or by defining HGCommand
258 event handlers (see |hgcommand-events|). Additionally, the HGCommand
259 plugin provides several option for naming the HG result buffers (see
260 |hgcommand-naming|) and supported a customized status line (see
261 |hgcommand-statusline| and |hgcommand-buffer-management|).
263 5.1 HGCommand configuration variables *hgcommand-options*
265 Several variables affect the plugin's behavior. These variables are
266 checked at time of execution, and may be defined at the window, buffer, or
267 global level and are checked in that order of precedence.
270 The following variables are available:
272 |HGCommandAnnotateParent|
273 |HGCommandCommitOnWrite|
275 |HGCommandDeleteOnHide|
279 |HGCommandEnableBufferSetup|
280 |HGCommandInteractive|
281 |HGCommandNameMarker|
282 |HGCommandNameResultBuffers|
285 HGCommandAnnotateParent *HGCommandAnnotateParent*
287 This variable, if set to a non-zero value, causes the zero-argument form of
288 HGAnnotate when invoked on a HGAnnotate buffer to go to the version
289 previous to that displayed on the current line. If not set, it defaults to
292 HGCommandCommitOnWrite *HGCommandCommitOnWrite*
294 This variable, if set to a non-zero value, causes the pending hg commit to
295 take place immediately as soon as the log message buffer is written. If
296 set to zero, only the HGCommit mapping will cause the pending commit to
297 occur. If not set, it defaults to 1.
299 HGCommandHGExec *HGCommandHGExec*
301 This variable controls the executable used for all HG commands. If not
302 set, it defaults to "hg".
304 HGCommandDeleteOnHide *HGCommandDeleteOnHide*
306 This variable, if set to a non-zero value, causes the temporary HG result
307 buffers to automatically delete themselves when hidden.
309 HGCommandDiffOpt *HGCommandDiffOpt*
311 This variable, if set, determines the options passed to the diff command of
312 HG. If not set, it defaults to 'w'.
314 HGCommandDiffSplit *HGCommandDiffSplit*
316 This variable overrides the |HGCommandSplit| variable, but only for buffers
317 created with |:HGVimDiff|.
319 HGCommandEdit *HGCommandEdit*
321 This variable controls whether the original buffer is replaced ('edit') or
322 split ('split'). If not set, it defaults to 'edit'.
324 HGCommandEnableBufferSetup *HGCommandEnableBufferSetup*
326 This variable, if set to a non-zero value, activates HG buffer management
327 mode see (|hgcommand-buffer-management|). This mode means that three
328 buffer variables, 'HGRepository', 'HGRevision' and 'HGBranch', are set if
329 the file is HG-controlled. This is useful for displaying version
330 information in the status bar.
332 HGCommandInteractive *HGCommandInteractive*
334 This variable, if set to a non-zero value, causes appropriate commands (for
335 the moment, only |:HGReview|) to query the user for a revision to use
336 instead of the current revision if none is specified.
338 HGCommandNameMarker *HGCommandNameMarker*
340 This variable, if set, configures the special attention-getting characters
341 that appear on either side of the hg buffer type in the buffer name. This
342 has no effect unless |HGCommandNameResultBuffers| is set to a true value.
343 If not set, it defaults to '_'.
345 HGCommandNameResultBuffers *HGCommandNameResultBuffers*
347 This variable, if set to a true value, causes the hg result buffers to be
348 named in the old way ('<source file name> _<hg command>_'). If not set or
349 set to a false value, the result buffer is nameless.
351 HGCommandSplit *HGCommandSplit*
353 This variable controls the orientation of the various window splits that
354 may occur (such as with HGVimDiff, when using a HG command on a HG command
355 buffer, or when the |HGCommandEdit| variable is set to 'split'. If set to
356 'horizontal', the resulting windows will be on stacked on top of one
357 another. If set to 'vertical', the resulting windows will be side-by-side.
358 If not set, it defaults to 'horizontal' for all but HGVimDiff windows.
360 5.2 HGCommand events *hgcommand-events*
362 For additional customization, HGCommand can trigger user-defined events.
363 Event handlers are provided by defining User event autocommands (see
364 |autocommand|, |User|) in the HGCommand group with patterns matching the
367 For instance, the following could be added to the vimrc to provide a 'q'
368 mapping to quit a HGCommand scratch buffer: >
371 au HGCommand User HGBufferCreated silent! nmap <unique> <buffer> q:
376 The following hooks are available:
378 HGBufferCreated This event is fired just after a hg command result
379 buffer is created and filled with the result of a hg
380 command. It is executed within the context of the HG
381 command buffer. The HGCommand buffer variables may be
382 useful for handlers of this event (please see
383 |hgcommand-buffer-variables|).
385 HGBufferSetup This event is fired just after HG buffer setup occurs,
388 HGPluginInit This event is fired when the HGCommand plugin first
391 HGPluginFinish This event is fired just after the HGCommand plugin
394 HGVimDiffFinish This event is fired just after the HGVimDiff command
395 executes to allow customization of, for instance,
396 window placement and focus.
398 5.3 HGCommand buffer naming *hgcommand-naming*
400 By default, the buffers containing the result of HG commands are nameless
401 scratch buffers. It is intended that buffer variables of those buffers be
402 used to customize the statusline option so that the user may fully control
403 the display of result buffers.
405 If the old-style naming is desired, please enable the
406 |HGCommandNameResultBuffers| variable. Then, each result buffer will
407 receive a unique name that includes the source file name, the HG command,
408 and any extra data (such as revision numbers) that were part of the
411 5.4 HGCommand status line support *hgcommand-statusline*
413 It is intended that the user will customize the |'statusline'| option to
414 include HG result buffer attributes. A sample function that may be used in
415 the |'statusline'| option is provided by the plugin, HGGetStatusLine(). In
416 order to use that function in the status line, do something like the
419 set statusline=%<%f\ %{HGGetStatusLine()}\ %h%m%r%=%l,%c%V\ %P
421 of which %{HGGetStatusLine()} is the relevant portion.
423 The sample HGGetStatusLine() function handles both HG result buffers and
424 HG-managed files if HGCommand buffer management is enabled (please see
425 |hgcommand-buffer-management|).
427 5.5 HGCommand buffer management *hgcommand-buffer-management*
429 The HGCommand plugin can operate in buffer management mode, which means
430 that it attempts to set two buffer variables ('HGRevision' and 'HGBranch')
431 upon entry into a buffer. This is rather slow because it means that 'hg
432 status' will be invoked at each entry into a buffer (during the |BufEnter|
435 This mode is enabled by default. In order to disable it, set the
436 |HGCommandEnableBufferSetup| variable to a false (zero) value. Enabling
437 this mode simply provides the buffer variables mentioned above. The user
438 must explicitly include those in the |'statusline'| option if they are to
439 appear in the status line (but see |hgcommand-statusline| for a simple way
442 ==============================================================================
443 9. Tips *hgcommand-tips*
445 9.1 Split window annotation, by Michael Anderson >
447 :nmap <Leader>hgN :vs<CR><C-w>h<Leader>hgn:vertical res 40<CR>
448 \ggdddd:set scb<CR>:set nowrap<CR><C-w>lgg:set scb<CR>
452 This splits the buffer vertically, puts an annotation on the left (minus
453 the header) with the width set to 40. An editable/normal copy is placed on
454 the right. The two versions are scroll locked so they move as one. and
455 wrapping is turned off so that the lines line up correctly. The advantages
458 1) You get a versioning on the right.
459 2) You can still edit your own code.
460 3) Your own code still has syntax highlighting.
462 ==============================================================================
464 8. Known bugs *hgcommand-bugs*
466 Please let me know if you run across any.
468 HGVimDiff, when using the original (real) source buffer as one of the diff
469 buffers, uses some hacks to try to restore the state of the original buffer
470 when the scratch buffer containing the other version is destroyed. There
471 may still be bugs in here, depending on many configuration details.
473 ==============================================================================
475 9. TODO *hgcommand-todo*
477 Integrate symlink tracking once HG will support them.
478 ==============================================================================
480 vim:tw=78:ts=8:ft=help:norl: