Chapter 9. The VI Input Mode

Erlend Hamberg

VI Input Mode

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 KatePart text editor as their internal editor.

The VI mode aims to integrate nicely with the program and deviate from Vim’s behavior where it makes sense. For example, :w will open a save dialog in KatePart’s VI mode.

To enable the VI Input Mode for all new views, go to SettingsConfigure KatePart...+EditingVI Input Mode. On this tab you can set options for the VI Input Mode and define and edit the key mapping in this mode. VI Input Mode 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).

Note

Many Vi Mode keyboard commands are case-sensitive, unlike most KDE keyboard shortcuts. That means that y and Y are different commands. To enter the y (yank) command, make sure Caps Lock is disabled and press Y. To enter the Y (yank to end of line) command, Shift+Y.

This does not apply to commands that use the Ctrl key, which may be entered regardless of Caps Lock mode and without pressing Shift. However, some commands require the use of a Ctrl-key combination followed by another key which is case sensitive. For instance, to input Ctrl+W, h (switch to split view right) make sure Caps Lock is disabled, press Ctrl+W, release, and then press H.

Incompatibilities with Vim

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

  • KatePart: 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 KatePart’s VI mode is that the shortcut Ctrl+R by default is taken by KatePart’s replace function (search and replace). By default, the VI mode won’t override KatePart’s shortcuts (this can be configured in SettingsConfigure KatePart...+EditingVi Input Mode), therefore a redo-action needs to be available as a regular key press, too. Besides, the behavior of the U command in Vim does not map well to KatePart’s internal undo system, so it would be non-trivial to support anyway.

  • KatePart: print shows the Print dialog.

    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 KatePart, too - therefore the :print command opens the print dialog - following the principle of least surprise instead of mimicking Vim’s behavior.

  • KatePart: Y yanks to end of line.

    Vim: Y yanks whole line, just like yy.

    VI’s behavior 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 KatePart’s VI Mode Y will yank to the end of the line. This is described as more logical in the Vim documentation.

  • KatePart: 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 behavior on a vim IRC channel (#vim on Libera Chat).

Switching Modes

  • Normal Mode permits you to enter commands to navigate or edit a document, and is the default mode. You can return to it from any other mode by pressing Esc.

  • Visual Mode permits you to highlight text in a document. Most Normal Mode commands are also valid in this mode. You can enter it by pressing v to select characters or V to select lines.

  • Insert Mode permits you to edit the document directly. You can enter it by pressing i or one of several other commands listed below.

  • Command Mode invokes KatePart's command line, permitting you to run many commands available in Vi implementations as well as some specific to KatePart. For more information on these commands, see the section called “The Editor Component Command Line”. To use it, press :, enter the command, and press Enter.

Integration with Kate features

  • Visual Mode is entered automatically when text is selected with the mouse. It is also entered when using functions of Kate that select text, such as Select All (either from the menu or via Ctrl+A.)

  • Vi marks and Kate bookmarks are integrated. When a mark is created in Vi Mode, a corresponding Kate bookmark is created and appears in the Bookmarks menu. Conversely, when a Kate bookmark is created, a corresponding Vi mark at the 0 column is also created.

Supported normal/visual mode commands

a

Enter Insert Mode; append after cursor

A

Enter Insert Mode; append after line

i

Enter Insert Mode; insert before cursor

Ins

Enter Insert Mode; insert before cursor

I

Enter Insert Mode; insert before first non-blank char on line

gi

Enter Insert Mode; insert before place, where leaving the last insert mode

v

Enter Visual Mode; select characters

V

Enter Visual Mode; select lines

Ctrl+v

Enter Visual Mode; select blocks

gb

Enter Visual Mode; reselect the last selection

o

Open a new line below current line

O

Open a new line above current line

J

Join lines

c

Change: follow by a motion to delete and enter Insert mode

C

Change to end of line: Delete to end of line and enter Insert Mode

cc

Change line: Delete line and enter Insert Mode

s

Substitute character

S

Substitute line

dd

Delete line

d

Follow by a motion to delete

D

Delete to end of line

x

Delete character to right of cursor

Del

Delete character to right of cursor

X

Delete character to left of cursor

gu

Follow with a motion to make lowercase

guu

Make the current line lowercase

gU

Follow with a motion to make uppercase

gUU

Make the current line uppercase

y

Follow by a motion to yank (copy)

yy

Yank (copy) line

Y

Yank (copy) line

p

Paste after cursor

P

Paste before cursor

]p

Paste after cursor indented

[p

Paste before cursor indented

r

Follow with a character to replace the character after the cursor

R

Enter Replace Mode

:

Enter Command Mode

/

Search

u

Undo

Ctrl+R

Redo

U

Redo

m

Set mark (can be used by motions later)

n

Find next

N

Find previous

>>

Indent line

<<

Unindent line

>

Indent lines

<

Unindent lines

Ctrl+F

Page down

Ctrl+B

Page up

ga

Print the ASCII value of the character

.

Repeat last change

==

commandAlignLine

=

commandAlignLines

~

Change case of current character

Ctrl+S

Split view horizontally

Ctrl+V

Split view vertically

Ctrl+W, w

Cycle to next split window

Ctrl+W, h

Ctrl+W Left

Go to left split window

Ctrl+W, l

Ctrl+W Right

Go to right split window

Ctrl+W, k

Ctrl+W Up

Go to above split window

Ctrl+W, j

Ctrl+W Down

Go to below split window

Supported motions

These may be used to move around a document in Normal or Visual mode, or in conjunction with one of the above commands. They may be preceded by a count, which indicates how many of the appropriate movements to make.

h

Left

Left

Left

Backspace

Left

j

Down

Down

Down

k

Up

Up

Up

l

Right

Right

Right

Space

Right

$

End of line

End

End of line

0

First character of line (Column 0)

Home

First character of line

^

First non-blank character of line

f

Follow by character to move to right of cursor

F

Follow by character to move to left of cursor

t

Follow by character to move to right of cursor, placing the cursor on character before it

T

Follow by character to move to left of cursor, placing the cursor on character before it

gg

First line

G

Last line

w

Next Word

W

Next word separated by whitespace

b

Previous word

B

Previous word separated by whitespace

e

End of word

E

End of word separated by whitespace

ge

End of previous word

gE

End of previous word separated by whitespace

|

Follow by a column number to move to that column

%

Follow by an item to move to that item

`

Mark

First non-whitespace character of the line the mark is on

[[

Previous opening bracket

]]

Next opening bracket

[]

Previous closing bracket

][

Next closing bracket

Ctrl+I

Jump to next location

Ctrl+O

Jump to previous location

H

Go to first line of screen

M

Go to middle line of screen

L

Go to last line of screen

%percentage

Go to specified percentage of the document

gk

Go one line up visually (when using dynamic word wrap)

gj

Go one line down visually (when using dynamic word wrap)

Ctrl+Left

Move one word left

Ctrl+Right

Move one word right

Supported text objects

These may be used to select certain portions of a document.

iw

Inner word: word including whitespace

aw

A word: word excluding whitespace

i"

Previous double-quote (") to next double-quote, including quotation marks

a”

Previous double-quote (") to next double-quote, excluding quotation marks

i'

Previous single-quote (') to next single-quote, including quotation marks

a'

Previous single-quote (') to next single-quote, excluding quotation marks

i(

Previous opening parenthesis [(] to next closing parenthesis [)], including the parenthesis

a(

Previous opening parenthesis [(] to next closing parenthesis [)], excluding the parenthesis

i[

Previous opening square bracket ([) to next closing square bracket (]), including the brackets

a[

Previous opening square bracket ([) to next closing square bracket (]), excluding the brackets

i{

Previous opening curly bracket ({) to next closing curly bracket (}), including the brackets

a{

Previous opening curly bracket ({) to next closing curly bracket (}), excluding the brackets

i<

Previous opening angle bracket (<) to next closing angle bracket (>), including the brackets

a<

Previous opening angle bracket (<) to next closing square bracket (>), excluding the brackets

i`

Previous backtick (`) to next backtick, including the backticks

a`

Previous backtick (`) to next backtick, excluding the backticks

Supported insert mode commands

Ctrl+D

Unindent

Ctrl+T

Indent

Ctrl+E

Insert from below

Ctrl+Y

Delete word

Ctrl+W

Delete word

Ctrl+U

Delete line

Ctrl+J

New line

Ctrl+H

Delete char backward

Ctrl+Home

Move to first character in the document

Ctrl+R n

Insert the contents of register n

Ctrl+O, command

Enter normal mode for one command only

Ctrl+A

Increment currently selected number

Ctrl+X

Decrement currently selected number

The Comma Text Object

This object is 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, the three ranges this text object can span are highlighted.

An example of Comma Text Object

Comma text object ranges. If the cursor is over e.g. arg2, pressing ci, (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.

Missing Features

As stated earlier, the goal of KatePart’s VI Mode is not to support 100% of Vim’s features.