Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Migrating from Vim

Nikita Ivanov edited this pageApr 30, 2025 ·34 revisions

Vi(m) to Kakoune:

Kakoune is inspired heavily by Vim. It strives to be as efficient asVim, more consistent and simpler. A big difference is that a lot ofspecial features in Vim just become regular interaction of basicfeatures in Kakoune.

Operations and moves are reversed in Kakoune. First select whatever textyou want to operate on, and then use a modifying operation. That makesthings more consistent (Vim needs a separatex andd operationbecause of the operator -> move order, Kakoune only needs thedoperation). 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/g<ret>
  • kak:%sword<ret>creplacement<esc>

Explanation:% selects the entire buffer,s opens a prompt for aregex,<ret> validates the regex and replace the selection with oneper matches (hence, all occurences of word are selected).c deletesthe selection contents and enter insert mode, replacement is typed and goes back to normal mode.

Note that the Kakoune version is three key less, and is not a specialfeature per se, but just a nice way Kakoune features work together.

Substitute in selection (assume that selection has been made already) with sub-patterns:

  • vim::'<,'>s/(word1):(word2):(word3):(word4)/\4\2\3\1/
  • kak:s(word1):(word2):(word3):(word4)<ret>c<c-r>4<c-r>2<c-r>3<c-r>1<esc>
  • kak:| sed -e 's/\(word1\)\(word2\)\(word3\)\(word4\)/\4\2\3\1/'

Note that again the first Kakoune version is again some keys shorter. The secondone shows at the same time, how to use external tools with pipes.

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, visualmode.

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 toKakoune using shifted moves to append to selection, so moves that werebound to non alphabetic chars had to change.

  • % becomem (for matching), howeverm will replace selection withthe next block, if you want to get a selection from current cursor tonext block end, you should use;M (; clears the selection to onecharacter)

  • 0 and$ becamealt-h andalt-l (selects from cursor to begin/endof line) orgh andgl (move cursor and anchor to begin/end of line).

Edit lines matching a regex:

  • vim::g/re/cmd
  • kak:%<a-s><a-k>re<ret>cmd

Explanation: to emulate:g, use% to select the wholebuffer,alt-s to split the selection into lines, thenalt-k tokeep selections matching a regex (oralt-K to drop selections,if you're trying to emulate:v). Thecmd refers to the command toperform, for example substitution.

Repeat the last movement:

  • vim:;
  • kak:<a-.>

Explanation:<a-.> is used to repeat the last movement. It workswith all theft selection, but also with the<a-i> and<a-a>command. Type:doc keys in kakoune for more infos.

Switch from Insert to Normal mode for one command:

  • vim:<c-o> (in Insert mode)
  • kak:<a-;> (in Insert mode)

Explanation: Like Vim, Kakoune has a command that will switch to Normal modefor a single command, then switch back. Unlike Vim, if this Normal modeenters a new Insert mode (likei oro), it will benested: when you hit<esc> to leave, you'll wind up in the original Insert mode you started in,and you'll have to hit<esc> again to get back to Normal mode. Normallythis is what you want (especially for scripting and mappings), but if youuse it interactively you may get a surprise.

Edit alternate file / Previously edited file:

  • vim:<c-^> (in Normal mode)
  • kak:ga (in Normal mode)

Yourkakrc

Just like vim, you can keep an rc-file with your settings. It shouldbe located in$XDG_CONFIG_HOME/kak/kakrc (usually~/.config/kak/kakrc)GistsRepos

Composing commands

Just like vi commands, Kakoune movements and selection commands can becomposed. But knowing how many words there are between the cursor andthe 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 innormal 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 tocount, you can just do 5 hit on W to add 5 words in the selection (juststop when you see the selection is good), or 5 hits on w to select the5th word from current cursor (similarly, just stop when the wordselected it the one you want).

Smarttab, expandtab and noexpandtab

You can usesmarttab.kak plugin. It provides these commands to toggle different policies when usingTab and> keys:

  • noexpandtab - usetab for everything.
    Tab will insert\t character, and> will use\t character when indenting. Aligning cursors with& uses\t character.
  • expandtab - usespace for everything.
    Tab will insert%opt{tabstop} amount of spaces, and> will indent with spaces.
  • smarttab - indent withtab, align withspace.
    Tab will insert\t character if your cursor is inside indentation area, e.g. before any non-whitespace character, and insert spaces if cursor is after any non-whitespace character. Aligning cursors with& usesspace.

If you are looking for a more faithful implementation of vim'sexpandtab andsofttabstop options, try this gist:vimtab.kak. Just copy and paste it into yourkakrc file and set the options as you wish. It also respects the usage of\ to disable hooks for insert mode, thus allowing you to insert a<tab> even whenexpandtab is enabled.

Autocmd

Vim'sautocmds equivalent in Kakoune terms arehooks.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.

Whichwrap

Vim defaultwhichwrap does not exist in Kakoune but is easily programmable with hooks on the move command:

hookglobalNormalKey h %{try %{execute-keys <a-k>$<ret> l    }}hookglobalNormalKey l %{try %{execute-keys <a-k>^<ret>h    }}

Marks

Thez key is used to deal with marks (it's used for folding commands in vim). In kakoune marks are tightly related toregisters, i.e. when you want to set thea mark the current selections coordinates are stored in thea register.

Code folding

There's currently no implementation of this feature. Follow this issue to discover how it goes:https://github.com/mawww/kakoune/issues/453

Highlight current line/column

Kakoune doesn't havecursorline orcursorcolumn commands but you can usekak-crosshairs plugin.

UI

The terminology of some ui elements is a bit different, but they work the same:

  • listchars,lsc:add-highlighter show_whitespaces
  • signs, SignColumn (limited to 2 chars in vim):add-highlighter flag_lines. SeeLine flags

Quickfix and Location windows

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 ofgrep orlint commands and therefore conceptually acts as an equivalent of vim's Quickfix window. SeeUse kakoune as an IDE for a quick recipe.

Vim plugins - VimL, VimScript

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.Check outthis guide to learn more about them.

You can of course write your own script if you need to extend the core functionalities. Kakoune intentionally offers 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 inawk,python,ruby,js

That's why there's no distinction betweencommand andfunction. There are only commands.

Check the content of therc directory or thiscommunity contributions page to have a taste.

Bring your Vim colorscheme to Kakoune

You can export Vim color themes for use in Kakoune usingexport-colorscheme.nvim.

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp