-
Notifications
You must be signed in to change notification settings - Fork 715
Migrating from Vim
Kakoune is inspired heavily by Vim, it strives to be as efficient as Vim, more consistent and simpler. A big difference is that a lot of special features in Vim just become regular interaction of basic features in Kakoune.
Operations and moves are reversed in Kakoune. First select whatever text
you want to operate on, and then use an modifying operation. That makes
things more consistent (Vim needs a separate x
and d
operation
because of the operator -> move order, Kakoune only needs the d
operation). That also allows more complex selections.
delete a word:
- vim:
dw
- kak:
wd
delete a character:
- vim:
x
- kak:
d
or;d
(;
reduces the selection to a single char)
copy a line:
- vim:
yy
- kak:
xy
global replace:
- vim:
:%s/word/replacement<ret>
- kak:
%sword<ret>creplacement<esc>
Explanation: %
selects the entire buffer, s
opens a prompt for a
regex, <ret>
validates the regex and replace the selection with one
per matches (hence, all occurences of word are selected). c
deletes
the selection contents and enter insert mode, replacement is typed and
goes back to normal mode.
Note that the Kakoune version is one key less, and is not a special feature per se, but just a nice way Kakoune features work together.
replace in current curly braces block:
- vim:
viB:s/word/replacement<ret>
- kak:
<a-i>Bsword<ret>creplacement<esc>
Here again, we need to rely on another Vim special feature, visual mode.
join line with next:
- vim:
J
- kak:
alt-J
delete to line end:
- vim:
d$
- kak:
alt-ld
orGld
some classic vim moves are not bound to the same key, this is due to Kakoune using shifted moves to append to selection, so moves that were bound to non alphabetic chars had to change.
-
%
becomem
(for matching), howeverm
will replace selection with the next block, if you want to get a selection from current cursor to next block end, you should use;M
(;
clears the selection to one character) -
0
and$
becamealt-h
andalt-l
(selects from cursor to begin/end of line) orgh
andgl
(move cursor and anchor to begin/end of line).
:[gv]/re/cmd
to emulate :g
or :v
, use %
to select the whole buffer, alt-s
to
get one selection by line, and then alt-k
or alt-K
in order to keep
only the selections matching (or not matching) the entered regex.
Just like vim, you can keep an rc-file with your settings. It should
be located in $XDG_CONFIG_HOME/kak/kakrc
(usually ~/.config/kak/kakrc
)
Gists
Repos
Just like vi commands, Kakoune movements and selection commands can be composed. But knowing how many words there are between the cursor and the target is not a trivial task and takes quite some practice. In vi, it is not possible to incrementally change the effect of an operation in normal mode. But Kakoune is, so to speak, in visual mode by default. This makes composing operations, guess what, quite visual. Regarding selections, as Kakoune displays them, you should not have to count, you can just do 5 hit on W to add 5 words in the selection (just stop when you see the selection is good), or 5 hits on w to select the 5th word from current cursor (similarly, just stop when the word selected it the one you want).
Vim's autocmd
s equivalent in Kakoune terms are hooks.
They let you register commands to be executed when certain events arise.
To temporarily disable hooks for a given command, press \
key in normal mode. A [no-hooks] flag will appear in the status line.
The z
key is used to deal with marks (it's used for folding commands in vim). In kakoune marks are tightly related to registers
, i.e. when you want to set the a
mark the current selections coordinates are stored in the a
register.
There's currently no implementation of this feature. Follow this issue to discover how it goes: https://github.com/mawww/kakoune/issues/453
The terminology of some ui elements is a bit different, but they work the same:
-
listchars
,lsc
:add-highligher show_whitespaces
-
signs
, SignColumn (limited to 2 chars in vim):add-highlighter flag_lines
. See Line flags
By default in kakoune, multiple clients can share the same environment (opened buffers…) if they are connected to the same session.
For example if in a terminal you start a first instance of kakoune: kak -s mysession foo.txt
, you can then open a second terminal and connect a second kakoune client: kak -c mysession
.
So with a bit of coordination, you could tell that the first terminal is your main editor, and the second one displays related info such as the output of grep
or lint
commands and therefore conceptually acts as an equivalent of vim's Quickfix window. See Use kakoune as an IDE for a quick recipe.
Most of Vim's power comes from its huge ecosystem of plugins. Many of them are not needed in kakoune because they are already provided as native commands. Checkout this guide to learn mode about them.
You can of course write your own script if you need to extend the core functionalities. Kakoune has voluntarily no built-in language but offers a simple (but powerful) string expansion system, %sh{}
blocks, that let you express your thoughts from simple shell one-liners to complete programs in awk
, python
, ruby
, js
…
That's why there's no distinction between command
and function
. There are only commands.
Check the content of the rc
directory or this community contributions page to have a taste.
- Normal mode commands
- Avoid the escape key
- Implementing user mode (Leader key)
- Kakoune explain
- Kakoune TV