# Try Kakoune for a modern Vi

To put it politely, Vi is a "well-seasoned" text editor.
It's been around for a long time, it has lots of fans and users, and it ships with nearly every POSIX system available.
To its credit, Vi hasn't changed all that much, although it has managed to undergo some major improvements (in fact, most Vi users actually use Vi-improved, or `vim`).
One of the greatest things about open source is how it can be adapted and iterated upon, however, and so you might wonder what Vi might look like if it had been invented today.
You can get a glimpse of such an alternate timeline with [Kakoune](http://kakoune.org/), a modern Vi-like editor incorporating ideas from modern editors as well as Vi and Vim.

## Install

On Fedora, you can install Kakoune from your repository:

```bash
$ sudo dnf kakoune
```

On CentOS and RHEL, Kakoune is available from the EPEL project.

## Using Kakoune

Like Vi, Kakoune opens in a terminal window.
The command to launch it is `kak`, and you can start it with or without specifying a file to open.
This command opens the file `example.txt` in Kakoune, or creates the file if it doesn't already exist:

```bash
$ kak example.txt
```

## Modal editing 

Kakoune has two modes: **normal** mode and **insert** mode.
Its default state is normal mode, and it's the way you interact with Kakoune as an application in the way you interact with GUI applications with your mouse.
All interaction in Kakoune happens with the keyboard, whether you're moving your cursor up or down a line, deleting a character or a word or a line, copying and pasting, and anything else you might do in a text editor aside from entering text.

To enter insert mode, press `i`.
In insert mode, you type and edit text much as you would in any other editor.
Unlike Vi, Kakoune favours the modern keyboard, so keys like **Home** and **End**, and all the arrow keys, are considered standard keys for common actions such as moving to the beginning or the end of a line.
There's not much to learn about insert mode.
You *insert* text, and you may as well be in Gedit or Kate or [Notepadqq](https://opensource.com/article/17/12/editing-text-linux-desktop-notepadqq).

## Selection

There is always an active selection in Kakoune, even when it's just one character wide (in which case your cursor is also your selection.)
Certain kinds of navigation, such as jumping to the beginning or end of a word, implies a greater selection.
By combining common navigation with selection, Kakoune is one step ahead of you in many cases.
In other words, when you jump forward a word, you might just be jumping forward a word, in which case a selection is unimportant.
However, sometimes when you jump forward a word, it's because you need to select that word so you can copy or remove it.
In those cases, it saves you the trouble of selecting an object because it's always selected by the method you chose to navigate.

Kakoune calls the two edges of a section the *cursor* and the *anchor*.

### Paperclip assistant

Kakoune features an anthropomorphic paperclip as your editing assistant.
When you issue commands in Kakoune, your paperclip assistant appears and tells you all of the potential completions for the command you've typed.

![A helpful paperclip rendered in ASCII art](paperclip-with-at-symbols-for-eyes.jpg)

If you've had any previous negative experiences with paperclip assistants, don't worry.
Kakoune's paperclip is actually very useful, and dynamic.
It's a pop-up alert that disappears once your command is sufficiently unique or complete.

## Keyboard shortcuts

Unlike insert mode, normal mode has many keyboard shortcuts and commands to learn.
You can learn them all, or just the essentials.
They're designed specifically to enable you to do more with fewer key presses, so don't be surprised if you shave a few microseconds off the time it usually takes you to adjust a config file with Kakoune.

### Modes

* `esc` normal mode
* `i` insert mode
* `I` insert text at beginning of current line
* `a` append text after cursor
* `A` append text at end of current line

### Navigation 

Navigation in normal mode can happen on the home row of your QWERTY keyboard:

* `h` or **Left Arrow** cursor left
* `j` or **Down Arrow** cursor down (`j` looks trivially like a down arrow)
* `k` or **Up Arrow** cursor up
* `l` or **Right Arrow** cursor right
* `b` cursor to beginning of current word, anchor at the end
* `e` cursor to end of current word, anchor at the beginning
* **Home** go to beginning of line
* **End** go to end of line
* `gg` go to first line of file
* `Gk` cursor to first line of file, anchor at end
* `Ge` cursor to last line of file, anchor at beginning
* `7g` go to line 7 of file

### Copy and paste

* `y` copy ("yank") selection
* `p` paste

### Delete

* `x` delete character
* `dw` delete word
* `d$` delete from current position to end of line
* `d0` delete from current position to beginning of line
* `dG` delete to last line of file

### Undo

* `u` undo

### Save

* `:w` save
* `:wq` or `:ZZ` save and quit
* `:q!` force quit without saving

## Try Kakoune

Kakoune is an interesting and progressive take on a classic text editor.
It's different from Vim, particularly in the way it treats navigation essentially the same as selection, and also in many of its keyboard shortcuts.
However, if you're a fan of Vim looking for something new to try, then you should consider Kakoune.