VI Mode
Introduction

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.
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
- The Kate Text editor
- KWrite – KDE’s simple text editor
- KDevelop – An advanced IDE for many programming languages
- 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.
- 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. - 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. - 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. - 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 | commandEnterInsertModeAppend |
| A | commandEnterInsertModeAppendEOL |
| i | commandEnterInsertMode |
| v | commandEnterVisualMode |
| V | commandEnterVisualLineMode |
| o | commandOpenNewLineUnder |
| O | commandOpenNewLineOver |
| J | commandJoinLines |
| c | commandChange |
| C | commandChangeToEOL |
| cc | commandChangeLine |
| s | commandSubstituteChar |
| S | commandSubstituteLine |
| dd | commandDeleteLine |
| d | commandDelete |
| D | commandDeleteToEOL |
| x | commandDeleteChar |
| X | commandDeleteCharBackward |
| gu | commandMakeLowercase |
| guu | commandMakeLowercaseLine |
| gU | commandMakeUppercase |
| gUU | commandMakeUppercaseLine |
| y | commandYank |
| yy | commandYankLine |
| Y | commandYankToEOL |
| p | commandPaste |
| P | commandPasteBefore |
| r | commandReplaceCharacter |
| : | commandSwitchToCmdLine |
| / | commandSearch |
| u | commandUndo) |
| <c-r> | commandRedo |
| U | commandRedo |
| m. | commandSetMark |
| n | commandFindNext |
| N | commandFindPrev |
| >> | commandIndentLine |
| << | commandUnindentLine |
| > | commandIndentLines |
| < | commandUnindentLines |
| <c-f> | commandScrollPageDown |
| <c-b> | commandScrollPageUp |
| ga | commandPrintCharacterCode |
| . | commandRepeatLastChange |
| == | commandAlignLine |
| = | commandAlignLines |
| ~ | commandChangeCase |
| <c-a> | commandAddToNumber |
| <c-x> | commandSubtractFromNumber |
Supported motions
| h | motionLeft |
| <left> | motionLeft |
| <backspace> | motionLeft |
| j | motionDown |
| <down> | motionDown |
| k | motionUp |
| <up> | motionUp |
| l | motionRight |
| <right> | motionRight |
| <space> | motionRight |
| $ | motionToEOL |
| <end> | motionToEOL |
| 0 | motionToColumn0 |
| <home> | motionToColumn0 |
| ^ | motionToFirstCharacterOfLine |
| f | motionFindChar |
| F | motionFindCharBackward |
| t | motionToChar |
| T | motionToCharBackward |
| gg | motionToLineFirst |
| G | motionToLineLast |
| w | motionWordForward |
| W | motionWORDForward |
| b | motionWordBackward |
| B | motionWORDBackward |
| e | motionToEndOfWord |
| E | motionToEndOfWORD |
| ge | motionToEndOfPrevWord |
| gE | motionToEndOfPrevWORD |
| | | motionToScreenColumn |
| % | motionToMatchingItem |
| ` | motionToMark |
| ‘ | motionToMarkLine |
| [[ | motionToPreviousBraceBlockStart |
| ]] | motionToNextBraceBlockStart |
| [] | motionToPreviousBraceBlockEnd |
| ][ | motionToNextBraceBlockEnd |
| * | motionToNextOccurrence |
| # | motionToPrevOccurrence |
Supported text objects
| iw | textObjectInnerWord |
| aw | textObjectAWord |
| i" | textObjectInnerQuoteDouble |
| a" | textObjectAQuoteDouble |
| i' | textObjectInnerQuoteSingle |
| a' | textObjectAQuoteSingle |
| i( | textObjectInnerParen |
| a( | textObjectAParen |
| i[ | textObjectInnerBracket |
| a[ | textObjectABracket |
| i, | textObjectInnerComma |
| a, | textObjectAComma |
Supported insert mode commands
| <c-d> | commandUnindent |
| <c-t> | commandIndent |
| <c-e> | commandInsertFromBelow |
| <c-y> | commandInsertFromAbove |
| <c-w> | commandDeleteWord |
| <c-home> | commandToFirstCharacterInFile |

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
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.
The source code for the vi mode is in kdelibs/kate/vimode.
d% works really wrong…
please report bugs at bugs.kde.org where it’s possible to follow them up.
“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.
It’s already implemented. You can find it in the git version of Kate and help to test it.
Thanks very much.
I’ll test it right now.
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
很不错的功能。支持
@李大双: 谢谢!:-)
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)
@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.
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.
@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!).