From Vim to Kakoune
I recently switched from Vim to kakoune.
The problem with Vim #
Trying to stick to the _worse is better_ philosophy brings me to thinks regularly on my tool stack. One of the most complex tool I use everyday was the venerable Vim. Each time I was thinking about it, Vim was not really a strict Unix following subject.
Vim got lot of features out of the file edition necessary scope:
- Directory management
- Split and tab management
- Embed a terminal
- Embed a ctags management
- File inclusion scrolling and definitions searching
I once said "Vim is awesome, I use it from years and I continue to learn things about it regularly". I think today that something is wrong about this simple fact.
From this statement, I tried to search alternatives. My goal was:
- Text editions features that Vim provides
- No out of scope features that Vim provides
In short, a worse is better Vim like text editor.
Discovering Kakoune #
I rapidly found a tool named Kakoune. I jumped on the design doc page and what I read glued me on the spot:
Kakoune is a code editor. It is not an IDE, not a file browser, not a word processor and not a window manager. It should be very efficient at editing code, and should, as a side effect, be very efficient at editing text in general.
Being limited in scope to code edition should not isolate Kakoune from its environment. On the contrary, Kakoune is expected to run on a Unix-like system, along with a lot of text-based tools, and should make it easy to interact with these tools.
Kakoune should be fast, fast to use, as in a lot of editing in a few keystrokes, and fast to execute.
Kakoune is inspired by Vim, and should try to keep its commands close to Vim’s if there are no compelling reasons to change. However self-consistency is more important than Vim compatibility.
I jump on the car and used it some days to have a better look. Here the difference with Vim:
Visual is the new Normal mode #
In kakoune you don't have a visual mode. In fact, the normal mode is the visual mode. You always got a selection and it is, at minimal, your cursor. So in Kakoune you don't `x` do delete the char bellow your cursor. You'll just `d` (which is honestly logic).
When you move your cursor with `hjkl` or with `wb`, you'll in fact select the given subject. In consequence, replacing the next word is `wc`. You extend your selection with capitalized subject. You can `wWWW` to select the next 4 words.
In kakoune you don't `dd` to suppress the current line. I always found this `dd` logic inconsistent anyway. In kakoune you `xd` where `x` is the way to select a line.
Subject + Verb a lesson from Verb + Subject #
One of the most destabilizing thing about Kakoune is the way operation are done.
If you want to remove the next 4 words with Vim, then you `d4w`. But guess what, you miss-counted the words and you had to remove only 3 words. So you have to `u` then `d3w` again.
Kakoune use a more interactive way to do that. In Kakoune you'll `4W` then seeing you miss-counted, you'll `B` to reduce the last word from selection, then `d`.
This is a more visual editor. This way is more interactive and less programmatic. There is some advantages to this approach:
- You make less mistakes as you can see the selected range
- Someone behind you can understand actions you are doing as they see them
Multi-selection by nature #
Kakoune is designed to allow multi-selection in its core. This features allow powerful possibilities. Let's take an example to show how Kakoune make things easier than in Vim.
You want to change a variable name from "foo" to "bar" in your buffer.
In Vim you'll do it in one operation `:%s/foo/bar/g`
In Kakoune, you'll do it with multiples operations, with more feedback but in short `%sfoo<Cr>cbar<Esc>`.
Firstly you `%` which will select all the buffer content. Then you `s` to "select" which will split the selection on pattern. You type `foo<Cr>` and now only "foo" words are selected in the buffer. Then you press `c` to change those selected parts and you type `bar<Esc>`. The input count is lower than in Vim. In general cases, Kakoune got a better score than Vim in Vimgolf. Plus, you got less chances to have unexpected impact on the content as you can see interactively your commands. Plus you can "select" in chain to reduce granulately your next action. Plus, after your change, you still can `i` content or do other actions as your selections persists.
No out of scope features #
Having no netrw and no splits was firstly hard to manage cause my workflows was not accustomed to it. But Kakoune got something I really loved to have in Vim and this close the gap. Kakoune is server-client based.
When you run `kak` you in fact start a server and connect a client instance to it. You can read in the bottom-right corner the session id. You then can `kak -c session-id` to connect another Kakoune client. All session clients share buffers, clipboard content, macros, etc. Having splits in Kakoune is as having multiple terminal in the same session. This is your tmux or WM role to manage the layout. In fact, you'll commonly `:new` from a Kakoune client to generate a new client in another window. Plus, if you are in a tmux context `:new` will automatically connect a new client in another split.
From this point, I wanted to wrap a common file browser as nnn from kak to have a full, independent file browser tool to browse my projects and open file to Kakoune. Fortunately someone did that before me, and this person did it Right!
Connect is some scripts that allow to `:connect-terminal` which will open a new terminal instance with some specific environment. By example, $EDITOR will be "edit" which is `.config/kak/autoload/connect/paths/commands/edit` which will open files in the linked kak instance. You then just `nnn` and `e` the files you want to edit in Kakoune. Connect got some modules to directly `:nnn` from Kakoune and this will open a linked nnn instance from the current buffer directory.
I really love the Kakoune approach. We are really using the one software for one task approach here. We got a simple and powerful text editor and we branch to it single and powerful tools. Maintaining this independents software is saner and this garantee those projects to last longer.
I really recommends you to give Kakoune a try as I think it is Vim text edition feature complete and it is a saner project.