# Vi Key Bindings

Vi emulation mimics the modal behavior of the Vi editor. The Vi scheme (and custom schemes created with Vi emulation) require this emulation in order to assign keystrokes to appropriate actions in the various modes.

Keybinding schemes and Vi emulation are configured in Edit|Preferences|Editor|Keybindings.

## Vi Emulation

Komodo emulates the following Vi modes:

- Normal: navigation and editing.

  When you open a file in Komodo with the Vi scheme enabled, you start off in command mode. Keystrokes in this mode control movement, deletion, cutting, pasting and other standard editing commands that are generally mapped to Ctrl and Alt key combinations in other schemes.

- Input: entering text.

  Hitting an "input" command key in Normal mode (i.e. 'i' to insert, 'a' to append, or 'o' to open a new line and insert) puts the editor into Input mode. Keystrokes in this mode enter text. Use the 'Esc' key to exit into Normal mode.

- Visual: visual selection of text with navigation keystrokes.

  Similar to Vim's visual modes. Entering 'v' enables selection by character, 'V' enables linewise selection, and 'Ctrl'+'v' enables blockwise selection. Navigation keystrokes within these modes expand and contract the selection area. Use the 'Esc' key to exit into Normal mode.

- Command-line: running vi/ex commands.

  In Normal mode, entering ':' opens a text box in the status bar at the bottom of the Komodo window for entering Vi commands. The following Vi and Vim commands have been implemented in the default Vi scheme:

  - edit
  - exit
  - help
  - next
  - previous
  - quit
  - set
  - splitview
  - undo
  - write
  - wq
  - xit
  - number <line number>
  - <range>s/<search string>/<substitution>/[g|i|I]

### Custom Vi Commands

To add your own Vi commands, create a Toolbox folder named Vi Commands, then add Macros or Run Commands to the folder. The macro or command is executed when you type its name in the Vi command-line text box.

Command-line arguments can be passed to Macros using the `koIViCommandDetail` XPCOM service. The IDL for this service is:

    attribute long startLine;         // Start line (current line when unset)
    attribute long endLine;           // End line (current line when unset)
    attribute boolean forced;         // Command name ended with a "!"
    attribute wstring commandName;    // Command name being run
    attribute wstring leftover;       // Everything after the command
    attribute wstring rawCommandString; // Raw command string as typed in
    void getArguments(out unsigned long count,
                      [array, size_is(count), retval] out wstring args);
    void setArguments(in unsigned long count,
                      [array, size_is(count)] in wstring args);
    void clear();

JavaScript sample macro:

    var viCommandDetails = Components.classes['@activestate.com/koViCommandDetail;1'].
                                    getService(Components.interfaces.koIViCommandDetail);
    var count = new Object();
    var args = viCommandDetails.getArguments(count);
    var msg = "startLine:" + viCommandDetails.startLine + "\n" +
              "endLine:" + viCommandDetails.endLine + "\n" +
              "commandName:" + viCommandDetails.commandName + "\n" +
              "arguments:" + args + "\n" +
              "rawCommandString:" + viCommandDetails.rawCommandString;
    alert(msg);

Python sample macro:

    from xpcom import components
    viCommandDetails = components.classes['@activestate.com/koViCommandDetail;1'].getService(components.interfaces.koIViCommandDetail)
    msg = [ "startLine: %d" % viCommandDetails.startLine ]
    msg.append("endLine: %d" % viCommandDetails.endLine)
    msg.append("commandName: %s" % viCommandDetails.commandName)
    msg.append("arguments: %r" % viCommandDetails.getArguments())
    msg.append("rawCommandString: %s" % viCommandDetails.rawCommandString)
    print "\n".join(msg)

## Vi Scheme

The default Vi scheme is based on the Default scheme (which varies slightly between platforms) and includes all Default keybindings which do not conflict with those used in Vi emulation. To view the list of key bindings for your current scheme, select Help|List Key Bindings. The following are key bindings which are unique to the Vi scheme.

### Vi-specific key bindings

Vi: Cancel |
Ctrl+[
Vi: Close the Current Buffer Without Saving | Z, Q
Vi: Cut One Character |
x
Vi: Cut One Character to Left |
X
Vi: Cut Whole Line and Enter Insert Mode |
S
Vi: Cut to End of Line and Enter Insert Mode |
C
Vi: Delete the Current Character and Enter Insert Mode |
s
Vi: Deletes from cursor to end of line. |
D
Vi: Enter Insert Mode |
i
Vi: Enter Insert Mode after the Cursor Position |
a
Vi: Enter Insert Mode at Start of the Line |
I
Vi: Enter Insert mode at the End of the Current Line |
A
Vi: Enter command mode |
:
Vi: Enter visual block mode |
Ctrl+V
Vi: Enter visual character mode |
v
Vi: Enter visual line mode |
V
Vi: Go to Next Line |
j
Vi: Go to Previous Line |
Ctrl+P
k
Vi: Goto Line |
G
Vi: Join current and next lines |
J
Vi: Move Left One Character |
h
Vi: Move One Word Left |
b
Vi: Move Right One Character |
Space
l
Vi: Move To End of Word To Right |
e
Vi: Move To Start of Word To Right |
w
Vi: Move one page down |
Ctrl+F
Vi: Move one page up |
Ctrl+B
Vi: Move one word left, past any punctuation |
B
Vi: Move one word right, past any punctuation |
W
Vi: Move to Beginning of Line (first visible char/first column) |
^
Vi: Move to Beginning of the Current Line |
0
Vi: Move to Beginning of the Previous Line |
-

### Code Browser

Locate current scope... |
Ctrl+K, Ctrl+L

### Debugger

Clear All Breakpoints |
Ctrl+F9
Disable/Enable Breakpoint |
F9
New Session |
Ctrl+Shift+F5
Run Script |
F7
Ctrl+F7
Run to Cursor |
Shift+F10
Ctrl+Shift+F10
Show Current Statement |
Alt+*
Start |
F5
Ctrl+F5
Start/Find/Hide Default Interactive Shell |
F12
Step In |
F11
Ctrl+F11
Step Out |
Shift+F11
Ctrl+Shift+F11
Step Over |
F10
Ctrl+F10
Stop |
Shift+F5

### Editor

Back |
Shift+Backspace
Backspace |
Backspace
Beginning of Line (first visible char/first column) |
Home
Cancel AutoComplete |
Escape
Close Current Buffer |
Ctrl+W
Ctrl+F4
Copy |
Ctrl+C
Ctrl+Insert
Cut |
Ctrl+X
Shift+Delete
Ctrl+Shift+X
Delete |
Delete
Delete Word Left |
Ctrl+Backspace
Delete Word Right |
Ctrl+Delete
End of Line |
End
Go to End of Document |
Ctrl+End
Go to End of word |
Ctrl+E
Go to Line... |
Ctrl+G
Go to Next Bookmark |
F2
Go to Next Line |
Down
Go to Previous Bookmark |
Shift+F2
Go to Previous Line |
Up
Go to Top of Document |
Ctrl+Home
Insert Abbreviation Snippet by Name |
Ctrl+T
Insert Newline |
Return
Insert Newline (align with current line) |
Ctrl+Shift+Return
Insert Newline (continue comments) |
Shift+Return
Insert Newline (no favors) |
Ctrl+Return
Insert Next Key as Literal Character |
Ctrl+M
Join current and next lines |
Ctrl+K, Ctrl+J
Move Back Part of Word |
Alt+Right
Move Forward Part of Word |
Alt+Left
Move Left One Character |
Left
Move One Character Right |
Right
Move One Word Left |
Ctrl+Left
Move One Word Right |
Ctrl+Right
Page Down |
Page_Down
Page Up |
Page_Up
Paste |
Ctrl+V
Shift+Insert
Paste and Select |
Ctrl+Shift+V
Redo |
Ctrl+Y
Reflow paragraph(s) |
Ctrl+Q
Remove All Bookmarks |
Ctrl+Shift+F2
Repeat next keystroke N times |
Ctrl+K, Ctrl+U
Scroll One Line Down |
Ctrl+Down
Scroll One Line Up |
Ctrl+Up
Select All |
Ctrl+A
Select Next Character |
Shift+Right
Select Next Word |
Ctrl+Shift+Right
Select Page Down |
Shift+Page_Down
Select Page Up |
Shift+Page_Up
Select Previous Character |
Shift+Left
Select Previous Word |
Ctrl+Shift+Left
Select Rectangular Next Character |
Alt+Shift+Right
Select Rectangular Page Down |
Alt+Shift+Page_Down
Select Rectangular Page Up |
Alt+Shift+Page_Up
Select Rectangular Previous Character |
Alt+Shift+Left
Select Rectangular to Beginning of Line (first char/first column) |
Alt+Shift+Home
Select Rectangular to End of Line |
Alt+Shift+End
Select Rectangular to Next Line |
Alt+Shift+Down
Select Rectangular to Previous Line |
Alt+Shift+Up
Select to Beginning of Line (first char/first column) |
Shift+Home
Select to Beginning of word |
Ctrl+Shift+W
Select to End of Document |
Ctrl+Shift+End
Select to End of Line |
Shift+End
Select to Next Line |
Shift+Down
Select to Previous Line |
Shift+Up
Select to Top of Document |
Ctrl+Shift+Home
Toggle Bookmark |
Ctrl+F2
Toggle Overtype/Insert Mode |
Insert
Trigger preceding AutoComplete list or CallTip |
Ctrl+J
Undo |
Ctrl+Z