• VI Mode

    Introduction

    Vim Logo
    Kate’s VI mode is a project to bring Vim-like, modal editing to the Kate text editor and by extension to other KDE programs who share the same editor component. The project started as a Google Summer of Code project in 2008 – where all the basic functionality was written. I have continued to maintain and further develop this code and the number of missing features from Vim are slowly decreasing. Most Vim users will already be productive in Kate’s VI mode. A list of what’s missing is found at the bottom of the page.

    This page is meant to be an updated overview of this work.

    To enable the VI input mode, go to
    Settings → Configure Kate… → Editing → VI Input Mode.
    It can also be toggled with the “VI Input Mode” setting in the “Edit” menu. (The default shortcut key is Meta+Ctrl+V – where Meta usually is the Windows key).

    Goals

    The goal of the VI mode is not to be a complete replacement for Vim and support all Vim’s features. Its aim is to make the “Vim way” of text editing – and the Vim habits learned – available for programs using the Kate text editor as their internal editor. These programs include

    1. The Kate Text editor
    2. KWrite – KDE’s simple text editor
    3. KDevelop – An advanced IDE for many programming languages
    4. Kile – A LaTeX editor

    The VI mode aims integrate nicely with the programs and deviate from Vim’s behaviour where it makes sense. For example, :w will open a save dialogue in Kate’s VI mode.

    Incompatibilities with Vim

    There are only a few features of Kate’s VI mode which are incompatible with Vim (not counting things missing). They are listed below together with the respective reasons.

    1. Kate: U and ctrl+r is redo
      Vim: ctrl+r is normal redo, U is used to undo all latest changes on one line
      The reason for having U act as redo in Kate’s VI mode is that the shortcut ctrl+r by default is taken by Kate’s replace function (search and replace). By default, the VI mode won’t override Kate’s shortcuts (this can be configured in Settings → Configure Kate… → Editing → Vi Input Mode), therefore a redo-action needs to be available as a “regular” key press, too. Besides, the behaviour of the U command in Vim doesn’t map well to Kate’s internal undo system, so it would be non-trivial to support anyway.
    2. Kate: :print shows the ‘print’ dialogue
      Vim: :print prints the lines of the given range like its grandfather ed
      Commands like :print are available not only in the VI mode but for users using “regular” Kate, too – I have therefore chosen to let the :print command open the print dialogue – following the principle of least surprise instead of mimicking Vim’s behaviour.
    3. Kate: ‘Y’ yanks to end of line.
      Vim: ‘Y’ yanks whole line, just like ‘yy’.
      VI’s behaviour for the ‘Y’ command is in practice a bug; For both change and delete commands, ‘cc’/'dd’ will do its action on the current line and ‘C’/'D’ will work from the cursor column to the end of the line. However, both ‘yy’ and ‘Y’ yanks the current line.In Kate’s VI Mode ‘Y’ will yank to the end of the line. This is described as “more logical” in the Vim documentation.
    4. Kate: ‘O’ and ‘o’ opens [count] new lines and puts you in insert mode
      Vim: ‘O’ and ‘o’ opens a new line and inserts text [count] times when leaving insert mode
      This is mostly done as a consequence of witnessing many people being confused by this behaviour on a vim irc channel (#vim on freenode).

    Supported Commands

    Supported normal/visual mode commands

    a Enter Insert Mode and append
    A Enter Insert Mode and append to EOL
    i Enter Insert Mode
    I Insert before first non-blank char in line
    v Enter Visual Mode
    V Enter Visual Line Mode
    <c-v> Enter Visual Block Mode
    gv Re-select Visual
    o Open new line under
    O Open new line over
    J Join lines
    c Change
    C Change to EOL
    cc Change line
    s Substitute char
    S Substitute line
    dd Delete line
    d Delete
    D Delete to EOL
    x Delete char
    X Delete char backward
    gu Make lowercase
    guu Make lowercase line
    gU Make uppercase
    gUU Make uppercase line
    y Yank
    yy Yank line
    Y Yank to EOL
    p Paste
    P Paste before
    r. Replace character
    R Enter replace mode
    : Switch to command line
    / Search
    u Undo
    <c-r> Redo
    U Redo
    m. Set mark
    >> Indent line
    << Unindent line
    > Indent lines
    < Unindent lines
    <c-f> Scroll page down
    <pagedown> Scroll page down
    <c-b> Scroll page up
    <pageup> Scroll page up
    <c-u> Scroll half page up
    <c-d> Scroll half page down
    zz Centre view on cursor
    ga Print character code
    . Repeat last change
    == Align line
    = Align lines
    ~ Change case
    <c-a> Add to number
    <c-x> Subtract from number
    <c-o> Go to prev jump
    <c-i> Go to next jump
    <c-w>h Switch to left view
    <c-w><c-h> Switch to left view
    <c-w><left> Switch to left view
    <c-w>j Switch to down view
    <c-w><c-j> Switch to down view
    <c-w><down> Switch to down view
    <c-w>k Switch to up view
    <c-w><c-k> Switch to up view
    <c-w><up> Switch to up view
    <c-w>l Switch to right view
    <c-w><c-l> Switch to right view
    <c-w><right> Switch to right view
    <c-w>w Switch to next view
    <c-w><c-w> Switch to next view
    <c-w>s Split horizontally
    <c-w>S Split horizontally
    <c-w><c-s> Split horizontally
    <c-w>v Split vertically
    <c-w><c-v> Split vertically
    gt Switch to next tab
    gT Switch to prev tab
    gqq Format line
    gq Format lines

    Supported motions

    h Left
    <left> Left
    <backspace> Left
    j Down
    <down> Down
    <enter> Down to first non blank
    k Up
    <up> Up
    - Up to first non blank
    l Right
    <right> Right
    <space> Right
    $ To EOL
    <end> To EOL
    0 To 0 column
    <home> To 0 column
    ^ To first character of line
    f. Find char
    F. Find char backward
    t. To char
    T. To char backward
    ; Repeat last t. or f. command
    , Repeat last t. or f. command
    n Find next
    N Find prev
    gg To first line
    G To last line
    w Word forward
    W WORD forward
    b Word backward
    B WORD backward
    e To end of word
    E To end of WORD
    ge To end of prev word
    gE To end of prev WORD
    | To screen column
    % To matching item
    `[a-zA-Z><] To mark
    ‘[a-zA-Z><] To mark line
    [[ To previous brace block start
    ]] To next brace block start
    [] To previous brace block end
    ][ To next brace block end
    * To next occurrence of word under cursor
    # To prev occurrence of word under cursor
    H To first line of window
    M To middle line of window
    L To last line of window
    gj To next visual line
    gk To prev visual line

    Supported text objects

    iw Inner word
    aw A word
    i" Inner double quote
    a" A double quote
    i' Inner single quote
    a' A single quote
    i` Inner back quote
    a` A back quote
    ib Inner paren
    i) Inner paren
    i( Inner paren
    ab A paren
    a) A paren
    a( A paren
    iB Inner curly bracket
    o} Inner curly bracket
    i{ Inner curly bracket
    aB A curly bracket
    a} A curly bracket
    a{ A curly bracket
    i< Inner inequality sign
    i> Inner inequality sign
    a< A inequality sign
    a> A inequality sign
    i[ Inner bracket
    I] Inner bracket
    a[ A bracket
    a] A bracket
    i, Inner comma
    a, A comma

    Supported insert mode commands

    <c-d> Unindent
    <c-t> Indent
    <c-e> Insert from below
    <c-y> Insert from above
    <c-w> Delete word
    <c-r>. Insert content of register
    <c-o> Switch to normal mode for one command
    <c-a> Increase number under cursor
    <c-x> Decrease number under cursor

    Comma text object ranges. If the cursor is over, say, “arg2”, pressing c i , (“change inner comma”) would delete “double arg2” and place the cursor between the two commas in insert mode. A very convenient way to change a function's parameters.

    The Comma Text Object

    This is something that I have been missing in Vim. The comma text object makes it easy to modify parameter lists in C-like languages and other comma separated lists. It is basically the area between two commas or between a comma and a bracket. In the line shown in the illustration to the right, the three ranges this text object can span are highlighted in red.

    Missing Features

      As stated earlier, the goal of Kate’s VI Mode is not to support 100% of Vim’s features, however, there are some features which are sorely missed
    • Visual block mode – especially the ability to prepend/append text to the visual block selection.
    • Having ex commands available in other programs than the Kate application.
    • The search code needs improvement and the * and # commands should just be regular searches.

    If you miss other features or want to help on the ones mentioned above, feel free to contact me or send patches! :-)

    Change Log

    • 2010-05-16:
      Initial version. Collected the information from blog entries and README files to make a single source of current information.
    • 2010-05-17:
      Ctrl+A and Ctrl+X added (increment/decrement number under cursor).
    • 2010-08-30:
      Moved page to kate-editor.org.
    • 2010-09-10:
      Fixed the text on the comma text object and made some formatting fixes

    23 Responses to VI Mode

    1. François
      September 1, 2010 at 21:32

      Hi,

      I would like to read your source code. Where can I find it? I didn’t find anything in kate svn…

      Thank you.
      Regards.

      • September 1, 2010 at 23:39

        The source code for the vi mode is in kdelibs/kate/vimode. :-)

    2. Yaroslav
      November 6, 2010 at 18:39

      d% works really wrong…

      • November 7, 2010 at 13:42

        please report bugs at bugs.kde.org where it’s possible to follow them up. :-)

    3. uu
      July 16, 2011 at 03:43

      “make mouse dragging start visual mode” ——when could this complete?
      Vi mode selection is not consistent with kate’s cursor selection,this cause many trouble.

      • Svyatoslav Kuzmich
        July 25, 2011 at 16:45

        It’s already implemented. You can find it in the git version of Kate and help to test it.

        • uu
          July 26, 2011 at 19:09

          Thanks very much.
          I’ll test it right now.

    4. October 3, 2011 at 20:44

      The _one_ vi feature that kate that I would like to see added is the abbreviations. I.e. :ab i I or :ab tht that. I am working on a text-to-speech application for people who are mute or speech-impaired and who cannot type very fast. I have discovered that by having a standard list of roughly 130 abbrevs, typing ordinary English text can be speeded up by about 31%.

      I have been a programmer for many years and am willing to add this feature–or at least help with it.

      Please let me know.

      gary kline

    5. October 27, 2011 at 09:03

      很不错的功能。支持

    6. alphi
      January 27, 2012 at 00:49

      What about remaping keys (using :remap .. for example when using a keyboard like colemak or bepo ?)

      What is the best way to redo it (in vim I have my :remap commands in my vimrc)

      • January 27, 2012 at 11:46

        @alphi: There is experimental support for :nn[oremap] (normal mode remappings) for the Vi Mode. These are saved in ~/.kde/share/config/katerc. It should be possible to write a short script to convert from Vim’s format to the format used in the katerc file for normal mode mappings.

    7. alphi
      January 27, 2012 at 14:39

      Thx, it’s working, in fact I was using fake vim from qtcreator, but it seems to be different to kate (I didn’t manage to do the same key mapping as in kate).

      But thx.

      • January 27, 2012 at 14:42

        @alphi: Ah. Ok. Ironically Qt Creator’s “fake vim” does not support many (or any at all?) vim functionality, but just Vi functions, while Kate’s “Vi mode” support a lot of Vim functionality like text objects (I could never live without them!). :-)

    8. Marcus
      June 25, 2012 at 04:05

      I am experimenting with Kate’s Vi Mode, but I was stuck after my first :split! I could not close the split windows! In Vim, that would be a simple :q, but Kate closes __files__ (buffers?) with :q, not split windows…

      So what’s the command for closing split windows? I have tried :q, :close, C-w c, and right-clicking everywhere…

    9. Artem
      September 27, 2012 at 21:12

      This page is in need of an update after Vegard Øye’s great improvements to the VI mode.

    10. vik
      October 27, 2012 at 20:38

      ywp doesn’t insert the yanked word correctly (cursor should be at the end) :(

    11. RobertK
      November 20, 2012 at 21:08

      How cool is that feature? Love it!

      Rob

    12. December 3, 2012 at 08:15

      Can I implement some mappings like “imap jj”

      This would be great, because I can’t get used to press Esc everytime I want ot exit Insert Mode

      • December 3, 2012 at 14:48

        Not yet, no. Patches are welcome, though! :)

        You can use Ctrl-[ (or even Ctrl-C) or instead of Esc.

        • January 3, 2013 at 03:37

          Is there any place to go to contribute in development or something? I’m interested in helping improve the VI mode.

        • January 3, 2013 at 03:39

          Duh! Nevermind, I’ve just found the primary tab saying Join Us.

    13. Dayton_b
      January 11, 2013 at 20:45

      Sorry, I don’t really have the programming experience (yet) to contribute, but can we get *zt* for make current line the top line and *zb* for make the current line the bottom line? It doesn’t seem like this is the right place to make feature requests, but I don’t know where to properly make the request.