.. rst3: filename: html/vimBindings.html ################### Using Vim with Leo ################### This chapter discusses these topics: - How to enable and use Leo's new vim-emulation mode. - How to import and export vim's .otl files. - How to install and use stand-alone vim-like bindings. .. contents:: Contents :depth: 3 :local: Using Leo's native vim mode +++++++++++++++++++++++++++ In general, vim-mode in Leo works much as in the real vim. There are three modes, insert, normal and visual. Supported commands ****************** - Cursor motions: ^,$,0,b,e,f,F,gg,gG,j,h,k,l,t,T,w. - The gb,ge,gh commands are synonyms for 0,$,^. - The h,j,k,l commands work on outlines when entered in the outline pane. - 0 in outline pane: goto-first-visible-node - e in outline pane: goto-last-visible-node. - Deleting text: d{motion},{motion}d,v{motion}d,diw,x. - Insert commands: a,A,i,o,O and switch to insert mode if entered in the outline pane. - Yank & paste commands: y,p. These act on outlines if entered in the outline pane. - Search commands: /,?,n,*,#. These commands are node-only searches. - The dot command '.' works for motions, but not yet for inserts or searches. - v: start/end visual mode. Notes: - Except as noted above, all vim-mode commands must be entered in the body pane. - in headlines switches to the outline pane. - in the outline pane switches to the body pane. Differences from the real vim ***************************** - The gb,ge,gh commands are synonyms for 0,$,^. - The h,j,k,l commands work on outlines when entered in the outline pane. - The a,A,i,o,O commands switch to insert mode if entered in the outline pane. - The y,p commands act on outlines if entered in the outline pane. - Ending visual mode with 'v' retains the selection range. - Ctrl-H puts the headline in insert mode. - Mouse clicks never change vim's state. Abbreviations ************* - The ``jj`` abbreviation switches to normal mode, preserving the changed status of the .leo file. - Return in visual/normal mode enters insert mode. .. - ``,,`` in normal mode now moves to insert mode. .. ``,,`` in insert mode does nothing, unless there is an abbreviation template available. Colon commands ************** The ':' command enters Leo's minibuffer, with ':' pre-inserted. You may backspace over the ':'. Here are the commands:: :! Execute a shell command. :e! Revert all changes to a .leo file, prompting if there have been changes. :gt cycle-focus :q Quit, prompting for saves. :qa Quit only if there are no unsaved changes. :r Prompt for a file name. Insert it at the cursor. :tabnew Prompt for a file name, and open a new tab. :w Save the .leo file. :wa Save all changed .leo files. :wq Save all open files and exit. :xa ave all open files and exit. The following colon commands are unique to Leo:: :print-vim-dot :toggle-vim-mode :toggle-vim-trainer-mode Settings ******** **@bool vim-mode = False**: Enables Leo's vim mode when True. **@bool vim-crosses-lines = True**: When True the f,F,h,l,t,T,x commands may cross line boundaries. Using vimoutline (.otl) files in Leo ++++++++++++++++++++++++++++++++++++ Leo can automatically import and export vimoutline (.otl) files. Nodes like:: @auto-otl or equivalently:: @auto-vimoutline import the .otl as a Leo outline. These nodes work like other @auto nodes: when Leo loads an outline, Leo reads the .otl file into the @auto-otl tree. When Leo writes an outline, Leo writes any @auto-otl tree back to the .otl file. After creating an @auto-otl node by hand, be sure to use Leo's refresh-from-disk command to populate the node. Do this *before* saving the .leo file. If you try to save an empty @auto-otl node Leo will warn you that you are about to overwrite the file. The refresh-from-disk command creates an @auto-otl node whose **children** represent the contents of the external .otl file. Leo does *not* write the @auto-otl node itself. This allows you to put Leo directives in the node. Using stand-alone vim bindings ++++++++++++++++++++++++++++++ Installing vim bindings *********************** Place a copy of the "@keys Vim bindings" node and its sub-nodes, located in the leoSettings.leo file, under the "@settings" node in the myLeoSettings.leo file The same procedure is performed to update to a new version. Note: Place any local customized key bindings in a separate "@keys My Vi" node in the myLeoSettings.leo file to prevent them from being overwritten when updating to a new version. General commands **************** The following commands are always available. State change commands:: i Change state to insert from command state Esc Change state to command from insert state Ctrl-[ Same as ESC Save/Exit/Quite commands:: :e Revert :w Save '.leo' file :wq Save '.leo' file and quit Leo :q Quit Leo (Leo will prompt if file not saved) ZZ Save leo file and exit Undo/Redo commands:: u Undo previous command Ctrl-r Redo previous command Search options:: Ctrl-/ Prompt for option to change Options: a Search all nodes (also key) h Toggle headline search b Toggle body search m Toggle marking of nodes (specify sub-option) f Toggle marking of nodes with found text c Toggle marking of nodes with changed text (only supported with 'Alt-/', 'Alt-p') r Toggle regex matches ('/' key turns off regex. 'n' key uses regex if turned on) Note: Whether a search is limited to node's body or the node's sub-outline is determined by which pane has focus when search text specified. (See "Find text commands:" sub-sections in Outline/Body Pane sections) Miscellaneous commands:: Tab Toggle focus between Outline and Body pane = Simulate double-click on current node's icon box Alt-G Go to specified line number (relative to external file) Ctrl-: Enter Leo's command line Body pane commands ****************** Move cursor commands:: h Go back 1 character LtArrow Mapped to "h" for convenience j Go down 1 line DnArrow Mapped to "j" for convenience k Go up 1 line UpArrow Mapped to "k" for convenience l Go forward 1 character RtArrow Mapped to "l" for convenience w Go to beginning of next word W Mapped to "w" until "stop after blank characters" supported b Go to beginning of current/previous word B Mapped to "b" until "stop at blank character" supported e Go to end of current/next word E Mapped to "e" until "stop at blank character" supported Note: Move by word commands stop at non-alpha characters | Goto beginning of current line ^ Go to 1st non-blank character on current line $ Goto end of current line % Go to matching bracket ( Go to beginning of current sentence ) Go to beginning of next sentence { Go to beginning of current paragraph } Go to beginning of next paragraph gg Go to the first line (Cursor at column 1) G Go to the last line (Cursor at column 1) Mark commands:: m