home *** CD-ROM | disk | FTP | other *** search
/ Dream 49 / Amiga_Dream_49.iso / beos / emacs / emacs-19.34-bin / emacs-19 / info / viper-2 < prev    next >
Encoding:
GNU Info File  |  1997-09-17  |  37.7 KB  |  871 lines

  1. This is Info file ../info/viper, produced by Makeinfo-1.63 from the
  2. input file viper.texi.
  3.  
  4. Distribution
  5. ************
  6.  
  7. Copyright (C) 1995, 1996 Free Software Foundation, Inc.
  8.  
  9.    Permission is granted to make and distribute verbatim copies of this
  10. manual provided the copyright notice and this permission notice are
  11. preserved on all copies.
  12.  
  13.    Permission is granted to copy and distribute modified versions of
  14. this manual under the conditions for verbatim copying, provided that
  15. the entire resulting derived work is distributed under the terms of a
  16. permission notice identical to this one.
  17.  
  18.    Permission is granted to copy and distribute translations of this
  19. manual into another language, under the same conditions as for modified
  20. versions.
  21.  
  22. 
  23. File: viper,  Node: New Commands,  Next: Useful Packages,  Prev: Movement and Markers,  Up: Improvements over Vi
  24.  
  25. New Commands
  26. ============
  27.  
  28.    These commands have no Vi analogs.
  29.  
  30. `C-x, C-c'
  31.      `C-x' will exit from Vi state and return to Emacs state
  32.      *temporarily*. If you hit one of these keys, Emacs will believe
  33.      that you hit that key in Emacs state. For example, if you hit `C-x'
  34.      followed by `2', then the current window will be split into 2 and
  35.      you will be in Vi state again. Except for novice users, `C-c' is
  36.      also set to temporarily escape to Emacs and execute a command from
  37.      the current major mode.  `ESC' will do the same, if you configure
  38.      ESC as Meta by setting `vip-no-multiple-ESC' to nil in `.vip'.
  39.      *Note Customization::. `C-z' in Insert state will make Emacs think
  40.      `Meta' has been hit.
  41.  
  42. `\'
  43.      Escape to Emacs to execute a single Emacs command. For instance, `\
  44.      ESC' will act like a Meta key.
  45.  
  46. `Q'
  47.      `Q' is for query replace.  By default, each string to be replaced
  48.      is treated as a regular expression. You can use `(setq
  49.      vip-re-query-replace nil)' in your `.emacs' file to turn this off.
  50.      (For normal searches, `:se nomagic' will work. Note that `:se
  51.      nomagic' turns Regexps off completely, unlike Vi).
  52.  
  53. `v'
  54. `V'
  55. `C-v'
  56.      These keys are used to visit files.  `v' will switch to a buffer
  57.      visiting file whose name can be entered in the Minibuffer. `V' is
  58.      similar, but will use a window different from the current window.
  59.      `C-v' is like `V', except that a new frame (X window) will be used
  60.      instead of a new Emacs window.
  61.  
  62. `#'
  63.      If followed by a certain character CH, it becomes an operator whose
  64.      argument is the region determined by the motion command that
  65.      follows (indicated as <move>).  Currently, CH can be one of `c',
  66.      `C', `g', `q', and `s'. For instance, `#qr' will prompt you for a
  67.      string and then prepend this string to each line in the buffer.
  68.  
  69. `# c'
  70.      Change upper case characters in the region to lower case
  71.      (`downcase-region').  Emacs command `M-l' does the same for words.
  72.  
  73. `# C'
  74.      Change lower case characters in the region to upper case. For
  75.      instance, `# C 3 w' will capitalize 3 words from the current point
  76.      (`upcase-region').  Emacs command `M-u' does the same for words.
  77.  
  78. `# g'
  79.      Execute last keyboard macro for each line in the region
  80.      (`vip-global-execute').
  81.  
  82. `# q'
  83.      Insert specified string at the beginning of each line in the region
  84.      (`vip-quote-region').
  85.  
  86. `# s'
  87.      Check spelling of words in the region (`spell-region').  The
  88.      function used for spelling is determined from the variable
  89.      `vip-spell-function'.
  90.  
  91. `*'
  92.      Call last keyboard macro.
  93.  
  94. `m .'
  95.      Set mark at point and push old mark off the ring
  96.  
  97. `m<'
  98. `m>'
  99.      Set mark at beginning and end of buffer, respectively.
  100.  
  101. `m,'
  102.      Jump to mark and pop mark off the ring. *Note Mark: (emacs)Mark,
  103.      for more info.
  104.  
  105. `] register'
  106.      View contents of register
  107.  
  108. `[ textmarker'
  109.      View filename and position of textmarker
  110.  
  111. `@#'
  112. `@register'
  113. `@!'
  114.      Begin/end keyboard macro. @register has a different meaning when
  115.      used after a `@#'. *Note Macros and Registers::, for details
  116.  
  117. `[]'
  118.      Go to end of heading.
  119.  
  120. `g <*movement command*>'
  121.      Search buffer for text delimited by movement command. The canonical
  122.      example is `gw' to search for the word under the cursor.  *Note
  123.      Improved Search::, for details.
  124.  
  125. `_'
  126.      Meta key when in Vi state.*Note Vi State::, for an explanation.
  127.  
  128. `C-g and C-]'
  129.      Quit and Abort Recursive edit. These may be necessary on occasion.
  130.      *Note Vi State::, for a reason.
  131.  
  132. `C-c g'
  133.      Hitting `C-c' followed by `g' will display the information on the
  134.      current buffer. This is the same as hitting  `C-g' in Vi, but, as
  135.      explained above, `C-g' is needed for other purposes in Emacs.
  136.  
  137. `C-c /'
  138.      Without a prefix argument, this command toggles
  139.      case-sensitive/case-insensitive search modes and plain
  140.      vanilla/regular expression search. With the prefix argument 1,
  141.      i.e., `1 C-c /', this toggles case-sensitivity; with the prefix
  142.      argument 2, toggles plain vanilla search and search using regular
  143.      expressions. *Note Viper Specials::, for alternative ways to invoke
  144.      this function.
  145.  
  146. `M-p and M-n'
  147.      In the Minibuffer, these commands navigate through the minibuffer
  148.      histories, such as the history of search strings, Ex commands, etc.
  149.  
  150. `C-c M-p and C-c M-n'
  151.      In Insert or Replace state, these commands let  the user peruse
  152.      the history of insertion strings used in previous insert or replace
  153.      commands. Try to hit `C-c M-p' or `C-c M-n' repeatedly and see what
  154.      happens. *Note Viper Specials::, for more.
  155.  
  156.      In Vi state, these commands let the user peruse the history of
  157.      Vi-style destructive commands, such as `dw', `J', `a', etc.  By
  158.      repeatedly typing `C-c M-p' or `C-c M-n' you will cycle Viper
  159.      through the recent history of Vi commands, displaying the commands
  160.      one by one. Once an appropriate command is found, it can be
  161.      executed by typing ``.''.
  162.  
  163.      Since typing `C-c M-p' is tedious, it is more convenient to bind an
  164.      appropriate function to a function key on the keyboard and use
  165.      that key.  *Note Viper Specials::, for details.
  166.  
  167. `Ex commands'
  168.      The commands `:args', `:next', `:pre' behave differently. `:pwd'
  169.      exists to get current directory.  The commands `:b' and `:B'
  170.      switch buffers around. *Note File and Buffer Handling::, for
  171.      details.  There are also the new commands `:RelatedFile' and
  172.      `PreviousRelatedFile' (which abbreviate to `R' and `P',
  173.      respectively. *Note Viper Specials::, for details.
  174.  
  175.    Apart from the new commands, many old commands have been enhanced.
  176. Most notably, Vi style macros are much more powerful in Viper than in
  177. Vi. *Note Vi Macros::, for details.
  178.  
  179. 
  180. File: viper,  Node: Useful Packages,  Prev: New Commands,  Up: Improvements over Vi
  181.  
  182. Useful Packages
  183. ===============
  184.  
  185.    Some Emacs packages are mentioned here as an aid to the new Viper
  186. user, to indicate what Viper is capable of.  A vast number comes with
  187. the standard Emacs distribution, and many more exist on the net and on
  188. the archives.
  189.  
  190.    This manual also mentions some Emacs features a new user should know
  191. about. The details of these are found in the GNU Emacs Manual.
  192.  
  193.    The features first. For details, look up the Emacs Manual.
  194.  
  195. `Make'
  196.      Makes and Compiles can be done from the editor. Error messages
  197.      will be parsed and you can move to the error lines.
  198.  
  199. `Shell'
  200.      You can talk to Shells from inside the editor. Your entire shell
  201.      session can be treated as a file.
  202.  
  203. `Mail'
  204.      Mail can be read from and sent within the editor. Several
  205.      sophisticated packages exist.
  206.  
  207. `Language Sensitive Editing'
  208.      Editing modes are written for most computer  languages in
  209.      existence. By controlling indentation, they catch punctuation
  210.      errors.
  211.  
  212.    The packages, below, represents a drop in the sea of special-purpose
  213. packages that come with standard distribution of Emacs 19.
  214.  
  215. `Transparent FTP'
  216.      `ange-ftp.el' can ftp from the editor to files on other machines
  217.      transparent to the user.
  218.  
  219. `RCS Interfaces'
  220.      `vc.el' for doing RCS commands from inside the editor
  221.  
  222. `Directory Editor'
  223.      `dired.el' for editing contents of directories and for navigating
  224.      in the file system.
  225.  
  226. `Syntactic Highlighting'
  227.      `hilit19.el' and `font-lock.el' for automatic highlighting various
  228.      parts of a buffer using different fonts and colors.
  229.  
  230. `Saving Emacs Configuration'
  231.      `desktop.el' for saving/restoring configuration on Emacs
  232.      exit/startup.
  233.  
  234. `Spell Checker'
  235.      `ispell.el' for spell checking the buffer, words, regions, etc.
  236.  
  237. `File and Buffer Comparison'
  238.      `ediff.el' for finding differences between files and for applying
  239.      patches.
  240.  
  241. Emacs Lisp archives exist on `archive.cis.ohio-state.edu' and
  242. `wuarchive.wustl.edu'
  243.  
  244. 
  245. File: viper,  Node: Customization,  Next: Commands,  Prev: Improvements over Vi,  Up: Top
  246.  
  247. Customization
  248. *************
  249.  
  250.    Customization can be done in 2 ways.
  251.  
  252.    * Elisp code in a `.vip' file in your home directory. Viper loads
  253.      `.vip' just before it does the binding for mode hooks. This is the
  254.      recommended method.
  255.  
  256.    * Elisp code in your `.emacs' file before and after the `(require
  257.      'viper)' line. This method is not recommended, unless you are know
  258.      what you are doing.
  259.  
  260. Emacs customization is done in Emacs Lisp. For the common cases,
  261. examples are provided that you can use directly.
  262.  
  263. * Menu:
  264.  
  265. * Rudimentary Changes::          Simple constant definitions.
  266. * Keybindings::                  Enabling Emacs Keys, Rebinding keys, etc.
  267. * Packages that Change Keymaps:: How to deal with such beasts.
  268. * Viper Specials::               Special Viper commands.
  269. * Vi Macros::                    How to do Vi style macros.
  270.  
  271. 
  272. File: viper,  Node: Rudimentary Changes,  Next: Keybindings,  Prev: Customization,  Up: Customization
  273.  
  274. Rudimentary Changes
  275. ===================
  276.  
  277.    An easy way to customize Viper is to change the values of constants
  278. used in Viper.  Here is the list of the constants used in Viper and
  279. their default values. The corresponding :se command is also indicated.
  280. (The symbols `t' and `nil' represent "true" and "false" in Lisp).
  281.  
  282.    Viper supports both the abbreviated Vi variable names and their full
  283. names. Variable completion is done on full names only. `TAB' and `SPC'
  284. complete variable names. Typing `=' will complete the name and then
  285. will prompt for a value, if applicable. For instance, `:se auSPC' will
  286. complete the command to `:set autoindent'; `:se taSPC' will complete
  287. the command and prompt further like this: `:set tabstop = '.  However,
  288. typing `:se tsSPC' will produce a "No match" message because `ts' is an
  289. abbreviation for `tabstop' and Viper supports completion on full names
  290. only. However, you can still hit `RET' or `=', which will complete the
  291. command like this: `:set ts = ' and Viper will be waiting for you to
  292. type a value for the tabstop variable.  To get the full list of Vi
  293. variables, type `:se SPC TAB'.
  294.  
  295. `vip-auto-indent nil'
  296. `:se ai (:se autoindent)'
  297. `:se gai (:se global-autoindent)'
  298.      If `t', enable auto indentation.  by `RET', `o' or `O' command.
  299.  
  300.      `vip-auto-indent' is a local variable. To change the value
  301.      globally, use `setq-default'. It may be useful for certain major
  302.      modes to have their own values of `vip-auto-indent'. This can be
  303.      achieved by using `setq' to change the local value of this
  304.      variable in the hooks to the appropriate major modes.
  305.  
  306.      `:se ai' changes the value of `vip-auto-indent' in the current
  307.      buffer only; `:se gai' does the same globally.
  308.  
  309. `vip-electric-mode t'
  310.      If `t', auto-indentation becomes electric, which means that `RET',
  311.      `O', and `o' indent cursor according to the current major mode. In
  312.      the future, this variable may control additional electric features.
  313.  
  314.      This is a local variable: `setq' changes the value of this variable
  315.      in the current buffer only. Use `setq-default' to change the value
  316.      in all buffers.
  317.  
  318. `vip-case-fold-search nil'
  319. `:se ic (:se ignorecase)'
  320.      If `t', search ignores cases.  This can also be toggled by quickly
  321.      hitting `/' twice.
  322.  
  323. `vip-re-search nil'
  324. `:se magic'
  325.      If `t' then search is reg-exp search, if `nil' then vanilla search.
  326.      This behavior can also be toggled by quickly hitting `/' trice.
  327.  
  328. `buffer-read-only'
  329. `:se ro (:se readonly)'
  330.      Set current buffer to read only. To change globally put
  331.      `(setq-default buffer-read-only t)' in your `.emacs' file.
  332.  
  333. `blink-matching-paren t'
  334. `:se sm (:se showmatch)'
  335.      Show matching parens by blinking cursor.
  336.  
  337. `tab-width t (default setting via `setq-default')'
  338. `:se ts=value (:se tabstop=value)'
  339. `:se gts=value (:se global-tabstop=value)'
  340.      `tab-width' is a local variable that controls the width of the tab
  341.      stops.  To change the value globally, use `setq-default'; for
  342.      local settings, use `setq'.
  343.  
  344.      The command `:se ts' sets the tab width in the current buffer
  345.      only; it has no effect on other buffers.
  346.  
  347.      The command `:se gts' sets tab width globally, for all buffers
  348.      where the tab is not yet set locally, including the new buffers.
  349.  
  350.      Note that typing `TAB' normally doesn't insert the tab, since this
  351.      key is usually bound to a text-formatting function,
  352.      `indent-for-tab-command' (which facilitates programming and
  353.      document writing). Instead, the tab is inserted via the command
  354.      `vip-insert-tab', which is bound to `S-tab' (shift + tab).
  355.  
  356.      On some non-windowing terminals, Shift doesn't modify the `TAB'
  357.      key, so `S-tab' behaves as if it were `TAB'. In such a case, you
  358.      will have to bind `vip-insert-tab' to some other convenient key.
  359.  
  360. `vip-shift-width 8'
  361. `:se sw=value  (:se shiftwidth=value)'
  362.      The number of columns shifted by `>' and `<' commands.
  363.  
  364. `vip-search-wrap-around t'
  365. `:se ws (:se wrapscan)'
  366.      If `t', search wraps around the end/beginning of buffer.
  367.  
  368. `vip-tags-file-name "TAGS"'
  369.      The name of the file used as the tag table.
  370.  
  371. `vip-re-query-replace nil'
  372.      If `t', use reg-exp replace in query replace.
  373.  
  374. `vip-want-ctl-h-help nil'
  375.      If `t', `C-h' is bound to `help-command'; if `nil', it is bound to
  376.      `delete-backward-char'.
  377.  
  378. `vip-vi-style-in-minibuffer t'
  379.      If `t', Viper provides a high degree of compatibility with Vi
  380.      insert mode when you type text in the Minibuffer; if `nil', typing
  381.      in the Minibuffer feels like plain Emacs.
  382.  
  383. `vip-no-multiple-ESC t'
  384.      If you set this to `nil', you can use `ESC' as Meta in Vi state.
  385.      Normally, this is not necessary, since graphical displays have
  386.      separate Meta keys (usually on each side of the space bar). On a
  387.      dumb terminal, Viper sets this variable to `twice', which is
  388.      almost like `nil', except that double `ESC' beeps. This, too, lets
  389.      ESC to be used as a Meta.
  390.  
  391. `vip-keysequence-delay 140'
  392.      Escape sequences separated by this much delay are interpreted as
  393.      command, ignoring the special meaning of ESC in VI. The default is
  394.      suitable for most terminals. However, if your terminal is
  395.      extremely slow, you might want to increase this slightly. You will
  396.      know if your terminal is slow if the ESC key sequences emitted by
  397.      the arrow keys are interpreted as separately typed characters (and
  398.      thus the arrow keys won't work).  Making this value too large will
  399.      slow you down, so exercise restraint.
  400.  
  401. `vip-ex-style-motion t'
  402.      Set this to `nil', if you want `l,h' to cross lines, etc. *Note
  403.      Movement and Markers::, for more info.
  404.  
  405. `vip-ex-style-editing-in-insert t'
  406.      Set this to to `nil', if you want `ESC' to not move back and `C-h'
  407.      to not stop at the beginning of a line in Insert state.
  408.  
  409. `vip-always t'
  410.      Leave it to Viper to decide when a buffer must be brought up in Vi
  411.      state, Insert state, or Emacs state. This heuristics works well in
  412.      virtually all cases.  This option must be set before Viper is
  413.      loaded or in the `.vip' file.
  414.  
  415. `vip-custom-file-name "~/.vip"'
  416.      Change this if you want. Must be set in `.emacs' (not `.vip'!)
  417.      before Viper is loaded. Note that you have to set it as a string
  418.      inside double quotes.
  419.  
  420. `vip-spell-function 'ispell-region'
  421.      Function used by the command `#c<move>' to spell.
  422.  
  423. `ex-nontrivial-find-file-function'
  424.      The value of this variable is the function used to find all files
  425.      that match a wildcard. This is usually done when the user types
  426.      `:e' and specifies a wildcard in the file name (or if the file
  427.      name contains unusual symbols (e.g., a space). Viper provides two
  428.      functions for this: one for Unix-like systems
  429.      (`vip-ex-nontrivial-find-file-unix') and one for DOS, W95, and NT
  430.      (`vip-ex-nontrivial-find-file-ms'). If the default function
  431.      doesn't quite do what you expect or if you prefer to use "fancy"
  432.      shells, you may have to write your own version of this function
  433.      and make it into the value of `ex-nontrivial-find-file-function'.
  434.      Use `vip-ex-nontrivial-find-file-unix' and
  435.      `vip-ex-nontrivial-find-file-ms' as examples.
  436.  
  437. `ex-cycle-other-window t'
  438.      If `t', `:n' and `:b' will cycle through files in another window,
  439.      if one exists.
  440.  
  441. `ex-cycle-through-non-files nil'
  442.      `:n' does not normally cycle through buffers. Set this to get
  443.      buffers also.
  444.  
  445. `vip-automatic-iso-accents nil'
  446.      If `t', ISO accents will be turned on in insert/replace Viper
  447.      states and turned off in Vi state. This is useful for editing text
  448.      in European languages. This variable is buffer-local. If used, it
  449.      should be set in the hooks to the appropriate major modes (usually
  450.      setting it in `text-mode-hook' is enough).
  451.  
  452. `vip-want-emacs-keys-in-insert'
  453.      This is set to `nil' for user levels 1 and 2 and to `t' for user
  454.      levels 3 and 4. Users who specify level 5 are allowed to set this
  455.      variable as they please (the default for this level is `t'). If
  456.      set to `nil', complete Vi compatibility is provided in Insert
  457.      state. This is really not recommended, as this precludes you from
  458.      using language-specific features provided by the major modes.
  459.  
  460. `vip-want-emacs-keys-in-vi'
  461.      This is set to `nil' for user level 1 and to `t' for user levels
  462.      2-4.  At level 5, users are allowed to set this variable as they
  463.      please (the default for this level is `t').  If set to `nil',
  464.      complete Vi compatibility is provided in Vi command state. Setting
  465.      this to `nil' is really a bad idea, unless you are a novice, as
  466.      this precludes the use of language-specific features provided by
  467.      the major modes.
  468.  
  469. `vip-keep-point-on-repeat t'
  470.      If `t', point is not moved when the user repeats the previous
  471.      command by typing `.'  This is very useful for doing repeated
  472.      changes with the `.' key.
  473.  
  474. `vip-repeat-from-history-key 'f12'
  475.      Prefix key used to invoke the macros `f12 1' and `f12 2' that
  476.      repeat the second-last and the third-last destructive command.
  477.      Both these macros are bound (as Viper macros) to
  478.      `vip-repeat-from-history', which checks the second key by which it
  479.      is invoked to see which of the previous commands to invoke. Viper
  480.      binds `f12 1' and `f12 2' only, but the user can bind more in
  481.      `~/.vip'. *Note Vi Macros::, for how to do this.
  482.  
  483. `vip-keep-point-on-undo nil'
  484.      If `t', Viper tries to not move point when undoing commands.
  485.      Instead, it will briefly move the cursor to the place where change
  486.      has taken place. However, if the undone piece of text is not seen
  487.      in window, then point will be moved to the place where the change
  488.      took place.  Set it to `t' and see if you like it better.
  489.  
  490. `vip-delete-backwards-in-replace nil'
  491.      If `t', DEL key will delete characters while moving the cursor
  492.      backwards.  If `nil', the cursor will move backwards without
  493.      deleting anything.
  494.  
  495. `vip-replace-overlay-face 'vip-replace-overlay-face'
  496.      On a graphical display, Viper highlights replacement regions
  497.      instead of putting a `$' at the end. This variable controls the so
  498.      called "face" used to highlight the region.
  499.  
  500.      By default, `vip-replace-overlay-face' underlines the replacement
  501.      on monochrome displays and highlights it with color on  color
  502.      displays.  If you know something about Emacs faces and don't like
  503.      how Viper highlights replacement regions, you can change this
  504.      variable to specify a new face name. (Emacs faces are described in
  505.      the Emacs Lisp reference.) On a color display, the following
  506.      customization method is usually most effective:
  507.           (set-face-foreground vip-replace-overlay-face "DarkSlateBlue")
  508.           (set-face-background vip-replace-overlay-face "yellow")
  509.      For a complete list of colors available to you, evaluate the
  510.      expression `(x-defined-colors)'. (Type it in the buffer `*scratch*'
  511.      and then hit the `C-j' key.
  512.  
  513. `vip-replace-overlay-cursor-color  "Red"'
  514.      Cursor color when it is inside the replacement region.  This has
  515.      effect only on color displays and only when Emacs runs as an X
  516.      application.
  517.  
  518. `vip-replace-region-end-delimiter "$"'
  519.      A string used to mark the end of replacement regions.  It is used
  520.      only with TTYs or if `vip-use-replace-region-delimiters' is
  521.      non-nil.
  522.  
  523. `vip-replace-region-start-delimiter  ""'
  524.      A string used to mark the beginning of replacement regions.  It is
  525.      used only with TTYs or if `vip-use-replace-region-delimiters' is
  526.      non-nil.
  527.  
  528. `vip-use-replace-region-delimiters'
  529.      If non-nil, Viper will always use
  530.      `vip-replace-region-end-delimiter' and
  531.      `vip-replace-region-start-delimiter' to delimit replacement
  532.      regions, even on color displays (where this is unnecessary). By
  533.      default, this variable is non-nil only on TTYs or monochrome
  534.      displays.
  535.  
  536. `vip-toggle-key "\C-z"'
  537.      Specifies the key used to switch from Emacs to Vi and back.  Must
  538.      be set in `.vip' or prior to loading Viper. This variable can't be
  539.      changed interactively after Viper is loaded.
  540.  
  541. `vip-ESC-key "\e"'
  542.      Specifies the key used to escape from Insert/Replace states to Vi.
  543.      Must be set in `.vip' or prior to loading Viper. This variable
  544.      cannot be changed interactively after Viper is loaded.
  545.  
  546. `vip-buffer-search-char nil'
  547.      Key used for buffer search. *Note Viper Specials::, for details.
  548.  
  549. `vip-surrounding-word-function 'vip-surrounding-word'
  550.      The value of this variable is a function name that is used to
  551.      determine what constitutes a word clicked upon by the mouse. This
  552.      is used by mouse search and insert.
  553.  
  554. `vip-search-face 'vip-search-face'
  555.      Variable that controls how search patterns are highlighted when
  556.      they are found.
  557.  
  558. `vip-vi-state-hook nil'
  559.      List of parameterless functions to be run just after entering the
  560.      Vi command state.
  561.  
  562. `vip-insert-state-hook nil'
  563.      Same for Insert state. This hook is also run after entering
  564.      Replace state.
  565.  
  566. `vip-replace-state-hook  nil'
  567.      List of (parameterless) functions called just after entering
  568.      Replace state (and after all `vip-insert-state-hook').
  569.  
  570. `vip-emacs-state-hook nil'
  571.      List of (parameterless) functions called just after switching from
  572.      Vi state to Emacs state.
  573.  
  574. `vip-load-hook nil'
  575.      List of (parameterless) functions called just after loading Viper.
  576.      This is the last chance to do customization before Viper is up and
  577.      running.
  578.  
  579. You can reset some of these constants in Viper with the Ex command
  580. `:set' (when so indicated in the table).  Or you can include a line
  581. like this in your `.vip' file:
  582.      (setq vip-case-fold-search t)
  583.  
  584. 
  585. File: viper,  Node: Keybindings,  Next: Packages that Change Keymaps,  Prev: Rudimentary Changes,  Up: Customization
  586.  
  587. Keybindings
  588. ===========
  589.  
  590.    Viper lets you define hot keys, i.e., you can associate keyboard keys
  591. such as F1, Help, PgDn, etc., with Emacs Lisp functions (that may
  592. already exist or that you will write). Each key has a "preferred form"
  593. in Emacs. For instance, the Up key's preferred form is [up], the Help
  594. key's preferred form is [help], and the Undo key has the preferred form
  595. [f14].  You can find out the preferred form of a key by typing `M-x
  596. describe-key-briefly' and then typing the key you want to know about.
  597.  
  598.    Under X Windows, every keyboard key emits its preferred form, so you
  599. can just type
  600.  
  601.      (global-set-key [f11] 'calendar)                        ; L1, Stop
  602.      (global-set-key [f14] 'undo)                            ; L4, Undo
  603.  
  604. to bind L1 so it will invoke the Emacs Calendar and to bind L4 so it
  605. will undo changes.  However, on a dumb terminal or in an Xterm window,
  606. even the standard arrow keys may not emit the right signals for Emacs
  607. to understand. To let Emacs know about those keys, you will have to
  608. find out which key sequences they emit by typing `C-q' and then the key
  609. (you should switch to Emacs state first). Then you can bind those
  610. sequences to their preferred forms using `function-key-map' as follows:
  611.  
  612.      (cond ((string= (getenv "TERM") "xterm")
  613.             (define-key function-key-map "\e[192z" [f11])    ; L1
  614.             (define-key function-key-map "\e[195z" [f14])    ; L4, Undo
  615.  
  616.    The above illustrates how to do this for Xterm. On VT100, you would
  617. have to replace "xterm" with "vt100" and also change the key sequences
  618. (the same key may emit different sequences on different types of
  619. terminals).
  620.  
  621.    The above keys are global, so they are overwritten by the local maps
  622. defined by the major modes and by Viper itself. Therefore, if you wish
  623. to change a binding set by a major mode or by Viper, read this.
  624.  
  625.    Viper users who wish to specify their own key bindings should be
  626. concerned only with the following three keymaps:
  627. `vip-vi-global-user-map' for Vi state commands,
  628. `vip-insert-global-user-map' for Insert state commands, and
  629. `vip-emacs-global-user-map' for Emacs state commands (note: customized
  630. bindings for Emacs state made to `vip-emacs-global-user-map' are *not*
  631. inherited by Insert state).
  632.  
  633.    For more information on Viper keymaps, see the header of the file
  634. `viper.el'.  If you wish to change a Viper binding, you can use the
  635. `define-key' command, to modify `vip-vi-global-user-map',
  636. `vip-insert-global-user-map', and `vip-emacs-global-user-map', as
  637. explained below. Each of these key maps affects the corresponding Viper
  638. state.  The keymap `vip-vi-global-user-map' also affects Viper's
  639. Replace state.
  640.  
  641. If you want to bind a key, say `C-v', to the function that scrolls page
  642. down and to make `0' display information on the current buffer, putting
  643. this in `.vip' will do the trick in Vi state:
  644.      (define-key vip-vi-global-user-map "\C-v" 'scroll-down)
  645.  
  646. To set a key globally,
  647.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  648.      (define-key vip-vi-global-user-map "0" 'vip-info-on-file)
  649.  
  650. Note, however, that this binding may be overwritten by other keymaps,
  651. since the global keymap has the lowest priority.  To make sure that
  652. nothing will override a binding in Emacs state, you can write this:
  653.      (define-key vip-emacs-global-user-map "\C-c m" 'smail)
  654.  
  655. To customize the binding for `C-h' in Insert state:
  656.      (define-key vip-insert-global-user-map "\C-h" 'my-del-backwards-function)
  657.  
  658. Each Emacs command key calls some lisp function. If you have enabled the
  659. Help, (*Note Rudimentary Changes::) `C-h k' will show you the function
  660. for each specific key; `C-h b' will show all bindings, and `C-h m' will
  661. provide information on the major mode in effect. If Help is not
  662. enabled, you can still get help in Vi state by prefixing the above
  663. commands with `\', e.g., `\ C-h k' (or you can use the Help menu in the
  664. menu bar, if Emacs runs under X Windows).
  665.  
  666.    Viper users can also change bindings on a per major mode basis.  As
  667. with global bindings, this can be done separately for each of the three
  668. main Viper states.  To this end, Viper provides the function
  669. `vip-modify-major-mode'.
  670.  
  671.    To modify keys in Emacs state for `my-favorite-major-mode', the user
  672. needs to create a sparse keymap, say, `my-fancy-map', bind whatever
  673. keys necessary in that keymap, and put
  674.  
  675.      (vip-modify-major-mode 'dired-mode 'emacs-state my-fancy-map)
  676.  
  677. in `~/.vip'. To do the same in Vi and Insert states, one should use
  678. `vi-state' and `insert-state'. Changes in Insert state are also in
  679. effect in Replace state.  For instance, suppose that the user wants to
  680. use `dd' in Vi state under Dired mode to delete files, `u' to unmark
  681. files, etc. The following code in `~/.vip' will then do the job:
  682.  
  683.      (setq my-dired-modifier-map (make-sparse-keymap))
  684.      (define-key my-dired-modifier-map "dd" 'dired-flag-file-deletion)
  685.      (define-key my-dired-modifier-map "u" 'dired-unmark)
  686.      (vip-modify-major-mode 'dired-mode 'vi-state my-dired-modifier-map)
  687.  
  688.    A Vi purist may want to modify Emacs state under Dired mode so that
  689. `k', `l', etc., will move around in directory buffers, as in Vi.
  690. Although this is not recommended, as these keys are bound to useful
  691. Dired functions, the trick can be accomplished via the following code:
  692.  
  693.      (setq my-dired-vi-purist-map (make-sparse-keymap))
  694.      (define-key my-dired-vi-purist-map "k" 'vip-previous-line)
  695.      (define-key my-dired-vi-purist-map "l" 'vip-forward-char)
  696.      (vip-modify-major-mode 'dired-mode 'emacs-state my-dired-vi-purist-map)
  697.  
  698.    Similar effect can be achieved by defining Vi keyboard macros using
  699. the Ex commands `:map' and `:map!'. The difference is that multi-key Vi
  700. macros do not override the keys they are bound to, unless these keys are
  701. typed in quick succession. So, with macros, one can use the normal keys
  702. alongside with the macros. If per-mode modifications are needed, the
  703. user can try both ways and see which one is more convenient.  *Note Vi
  704. Macros::, for details.
  705.  
  706.    Note: in major modes that come up in *Emacs state* by default, the
  707. aforesaid modifications may not take place immediately (but only after
  708. the buffer switches to some other Viper state and then back to Emacs
  709. state).  To avoid this, one should add `vip-change-state-to-emacs' to an
  710. appropriate hook of that major mode. (Check the function
  711. `vip-set-hooks' in `viper.el' for examples.)  However, if you have set
  712. `vip-always' to `t', chances are that you won't need to perform the
  713. above procedure, because Viper will take care of most useful defaults.
  714.  
  715.    Finally, Viper has a facility that lets the user define per-buffer
  716. bindings, i.e., bindings that are in effect in some specific buffers
  717. only. Unlike per-mode bindings described above, per-buffer bindings can
  718. be defined based on considerations other than the major mode.  This is
  719. done via the function `vip-add-local-keys', which lets one specify
  720. bindings that should be in effect in the current buffer only and for a
  721. specific Viper state. For instance,
  722.      (vip-add-local-keys 'vi-state '(("ZZ" . TeX-command-master)
  723.                                      ("ZQ" . vip-save-kill-buffer)))
  724.  
  725. redefines `ZZ' to invoke `TeX-command-master' in `vi-state' and `ZQ' to
  726. save-then-kill the current buffer. These bindings take effect only in
  727. the buffer where this command is executed. The typical use of this
  728. function is to execute the above expression from within a function that
  729. is included in a hook to some major mode. For instance, the above
  730. expression could be called from a function, `my-tex-init', which may be
  731. added to `tex-mode-hook' as follows:
  732.      (add-hook 'tex-mode-hook 'my-tex-init)
  733.  
  734. When TeX mode starts, the hook is executed and the above Lisp
  735. expression is evaluated. Then, the bindings for `ZZ' and `ZQ' are
  736. changed in Vi command mode for all buffers in TeX mode.
  737.  
  738.    Another useful application is to bind `ZZ' to `send-mail' in the
  739. Mail mode buffers (the specifics of this depend on which mail package
  740. you are using, `rmail', `mh-e', `vm', etc.  For instance, here is how
  741. to do this for `mh-e', the Emacs interface to MH:
  742.      (defun mh-add-vi-keys ()
  743.        "Set up ZZ for MH-e and XMH."
  744.        (vip-add-local-keys 'vi-state '(("ZZ" . mh-send-letter))))
  745.      (add-hook 'mh-letter-mode-hook 'mh-add-vi-keys)
  746.  
  747.    You can also use `vip-add-local-keys' to set per buffer bindings in
  748. Insert state and Emacs state by passing as a parameter the symbols
  749. `'insert-state' and `'emacs-state', respectively.  As with global
  750. bindings, customized local bindings done to Emacs state are not
  751. inherited by Insert state.
  752.  
  753.    On rare occasions, local keys may be added by mistake. Usually this
  754. is done indirectly, by invoking a major mode that adds local keys (e.g.,
  755. `shell-mode' redefines `RET'). In such a case, exiting the wrong major
  756. mode won't rid you from unwanted local keys, since these keys are local
  757. to Viper state and the current buffer, not to the major mode.  In such
  758. situations, the remedy is to type `M-x vip-zap-local-keys'.
  759.  
  760.    So much about Viper-specific bindings.  *Note Customization:
  761. (emacs)Customization, and the Emacs quick reference card for the
  762. general info on key bindings in Emacs.
  763.  
  764. 
  765. File: viper,  Node: Packages that Change Keymaps,  Next: Viper Specials,  Prev: Keybindings,  Up: Customization
  766.  
  767. Packages that Change Keymaps
  768. ----------------------------
  769.  
  770.    Viper is designed to coexist with all major and minor modes of
  771. Emacs. This means that bindings set by those modes are generally
  772. available with Viper (unless you explicitly prohibit them by setting
  773. `vip-want-emacs-keys-in-vi' and `vip-want-emacs-keys-in-insert' to
  774. `nil').  If `vip-always' is set to `t', Viper will try to bring each
  775. buffer in the a Viper state that is most appropriate for that buffer.
  776. Usually, this would be the Vi state, but sometimes it could be the
  777. Insert state or the Emacs state.
  778.  
  779.    Some major mode bindings will necessarily be overwritten by Viper.
  780. Indeed, in Vi state, most of the 1-character keys are used for Vi-style
  781. editing.  This usually causes no problems because most packages
  782. designed for editing files typically do not bind such keys. Instead,
  783. they use key sequences that start with `C-x' and `C-c'. This is why it
  784. was so important for us to free up `C-x' and `C-c'.  It is common for
  785. language-specific major modes to bind `TAB' and `LFD' (the line feed)
  786. keys to various formatting functions. This is extremely useful, but may
  787. require some getting used to for a Vi user. If you decide that this
  788. feature is not for you, you can re-bind these keys as explained earlier
  789. (*Note Customization::).
  790.  
  791.    Binding for `TAB' is one of the most unusual aspects of Viper for
  792. many novice users.  In Emacs, `TAB' is used to format text and
  793. programs, and is extremely useful. For instance, hitting `TAB' causes
  794. the current line to be re-indented in accordance with the context.  In
  795. programming, this is very important, since improper automatic
  796. indentation would immediately alert the programmer to a possible error.
  797. For instance, if a `)' or a `"' is missing somewhere above the current
  798. line, `TAB' is likely to mis-indent the line.
  799.  
  800.    For this reason, Viper doesn't change the standard Emacs binding of
  801. `TAB', thereby sacrificing Vi compatibility (except for users at level
  802. 1). Instead, in Viper, the key `S-tab' (shift+ tab) is chosen to
  803. emulate Vi's `TAB'.
  804.  
  805.    We should note that on some non-windowing terminals, Shift doesn't
  806. modify the `TAB' key, so `S-tab' behaves as if it were `TAB'. In such a
  807. case, you will have to bind `vip-insert-tab' to some other convenient
  808. key.
  809.  
  810.    Some packages, notably Dired, Gnus, Info, etc., attach special
  811. meaning to common keys like `SPC', `x', `d', `v', and others. This
  812. means that Vi command state is inappropriate for working with these
  813. packages. Fortunately, these modes operate on read-only buffers and are
  814. designed not for editing files, but for special-purpose browsing,
  815. reading news, mail, etc., and Vi commands are meaningless in these
  816. situations. For this reason, Viper doesn't force Vi state on such major
  817. modes.  Rather, it brings them in Emacs state. You can switch to Vi
  818. state by typing `C-z' if, for instance, you want to do Vi-style search
  819. in a buffer (although, usually, incremental search, which is bound to
  820. `C-s', is sufficient in these situations). But you should then switch
  821. back to Emacs state if you plan to continue using these major modes
  822. productively. You can also switch to Vi temporarily, to execute one
  823. 1-character command. This is done by typing `M-C-z' (or `ESC C-z').
  824. This facility cannot execute several complex Vi commands, such as `dw',
  825. `de', etc.
  826.  
  827.    It is also possible to harness some major modes, even though they
  828. may bind common keys to specialized commands. Harnessing can make sense
  829. for modes that bind only a small number of common keys.  For instance,
  830. if `vip-always' is set to `t' in your `~/.vip' file, Viper will harness
  831. the Shell mode by changing the bindings for `C-m' and `C-d' using
  832. `vip-add-local-keys' described in section on customization (*Note
  833. Customization::). In general, there is no single recipe for harnessing
  834. modes. It can be as simple as adding the function `viper-mode' to a
  835. hook associated with the mode, or it can be more complex, as in the
  836. case of Shell mode and Emerge. Take a look at `vip-set-hooks' function
  837. for some examples.
  838.  
  839.    Conversely, it may be the case that most of the major modes harnessed
  840. by `vip-set-hooks' function fit your working style, except one or two
  841. cases. In this case, you may still be able to set `vip-always' to `t'
  842. and then remove a hook that forces Vi command state. For instance, to
  843. unharness `lisp-interaction-mode', you can put the following line in
  844. your `.emacs' (not `.vip'!) file after `(require 'viper)':
  845.      (remove-hook 'lisp-interaction-mode-hook 'viper-mode)
  846.  
  847.    In some rare cases, some minor modes may override certain essential
  848. bindings in Vi command state.  This is not really catastrophic because
  849. this may happen only in the beginning, when the minor mode kicks in.
  850. Typing `M-x viper-mode' will correct the situation.  Viper knows about
  851. several such minor modes and takes care of them, so that the above trick
  852. is usually not necessary.  If you find that some minor mode, e.g.,
  853. `nasty-mode.el' interferes with Viper, putting the following in `.vip'
  854. should fix the problem:
  855.      (vip-harness-minor-mode "nasty-mode")
  856.  
  857. The argument to `vip-harness-minor-mode' is the name of the file for the
  858. offending minor mode with the suffixes `.el' and `.elc' removed.
  859.  
  860.    It may be tricky, however, to find out which minor mode is at fault.
  861. The only guidance here is to look into the file that defines the minor
  862. mode you are suspecting, say `nasty-mode.el', and see if it has a
  863. variable called `nasty-mode-map'. Then check if there is a statement of
  864. the form
  865.      (define-key nasty-mode-map key function)
  866.  
  867. that binds the misbehaving keys. If so, use the above line to harness
  868. `nasty-mode'. If your suspicion is wrong, no harm is done if you
  869. harness a minor mode that doesn't need to be harnessed.
  870.  
  871.