#+title: Vim Comparison

* Intro

Despite being another modal editing scheme, meow is not very similar
to [[https://www.vim.org/][Vim]], but instead tends to be more like [[https://kakoune.org/][kakoune]].

The primary difference to Vim are that there is no dedicated visual mode
in meow, since it's essentially built into normal mode. Almost every
movement in normal mode creates a visual selection on which some
command can act on.

The other main difference is that the language grammar you use in Vim is
flipped in meow.

In Vim, you might use something like =4w= to move 4 words forward. =4=
acts as a quantifier, and =w= is the so called "verb." In meow, we think
about commands the opposite way. We'd first select a single word, with
=meow-next-word= (which, critically, both moves the point *and* creates a
selection), and /then/ press =3= to select three more words. This process
can be indefinitely extended. For example, if you say 2 and 6
afterwards you select another 8 words forward.

Once you have a selection, you can decide to execute an action
("verb") representing what you want to do on this selection.

In vim, to change (delete and enter insert mode) 3 words, you might
press =c3w=. In meow, this would be =e3c= since the grammar is inverted.

Meow has the clear advantage that when you create the selection, you
get visual feedback on what your target selection is, and then can
decide which verb to execute. You can choose to abort if you selected
something wrong, or better, revert your selection to make a new
one. In Vim on the other hand, you commit on the verb right away, then
guess at your selection target (which is harder the more things you want
to act on). If you mess up, you have no choice but to undo everything
and try again.

Since many people who want to give meow a try, come from a Vim / Evil
background, here is an overview of typical Vim keybindings for common
actions and how they can be achieved in meow.

*Note:*

We provide only command names here, this is because
meow has no built-in keybind set (yet?). If you decide to use the
suggested [[https://github.com/meow-edit/meow/blob/master/KEYBINDING_QWERTY.org][QWERTY]] keybindings, you can look up the default binding to
each command there.

For ease of reading, all ~meow-~ prefixes are stripped.

Italic (e.g. /negative-argument/) represents a builtin command.

Brackets (e.g. [reverse]) represents an optional step. You don't
always replicate the same cursor movement, the selection does the
job sometimes.

* Movement

| Vim      | Meow                              | Description ; Tips                                                                                |
|----------+-----------------------------------+---------------------------------------------------------------------------------------------------|
| h        | left                              | character left                                                                                    |
| j        | next                              | next line                                                                                         |
| k        | prev                              | previous line                                                                                     |
| l        | right                             | character right                                                                                   |
| w        | next-word                         | next word                                                                                         |
| W        | next-symbol                       | next symbol (as determined by the [[https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Tables.html][syntax table]])                                                   |
| b        | back-word                         | last word                                                                                         |
| B        | back-symbol                       | last symbol                                                                                       |
| e        | mark-word                         | end of word                                                                                       |
| E        | mark-symbol                       | end of symbol                                                                                     |
| ge       | back-word back-word [reverse]     | end of previous word; no need to reverse before append                                            |
| gE       | back-symbol back-symbol [reverse] | end of previous symbol; no need to reverse before append                                          |
| 0        | line [reverse] OR /C-a/             | beginning of line; no need to reverse before insert                                               |
| ^​        | join                              | first none whitespace character                                                                   |
| $​        | line                              | EOL                                                                                               |
| f <char> | find <char>                       | forward to next char                                                                              |
| F <char> | /negative-argument/ find <char>     | backward to last char                                                                             |
| t <char> | till <char>                       | till next char                                                                                    |
| T <char> | /negative-argument/ till <char>     | backward till next char                                                                           |
| %        | block OR to-block                 | jump to matching paren; not one to one replacement can jump from anywhere inside the block to end |
| ;        | /repeat/                            | repeat last f or t movement; builtin repeat works with any command                                |
| C-u      | page-up OR /M-v/                    | page up; depends on whether to select or not                                                      |
| C-d      | page-down OR /C-v/                  | page down                                                                                         |
| gg       | beginning-of-thing b OR /M-</       | beginning of file                                                                                 |
| G        | end-of-thing OR /M->/               | end of file                                                                                       |
| :<num>   | goto-line                         | go to line number                                                                                 |
| C-o      | meow-pop-to-mark                  | last position in jumplist; mark-ring based, only in current buffer                                |
| C-i      | meow-unpop-to-mark                | next position in jumplist; mark-ring based, only in current buffer                                |

* Search

| Vim | Meow                                    | Description                                                                             |
|-----+-----------------------------------------+-----------------------------------------------------------------------------------------|
| =/=  | visit OR /C-s/ OR /C-M-s/                   | forward search; depends on whether you need incremental search                          |
| ?   | /negative-argument/ visit OR C-r OR /C-M-r/ | backward search                                                                         |
| n   | search                                  | next match                                                                              |
| p   | /negative-argument/ search                | last match; the direction preserves, you only need negative argument for the first time |

* Switch into insert mode

| Vim | Meow        | Description                                           |
|-----+-------------+-------------------------------------------------------|
| i   | insert      | insert                                                |
| a   | append      | append (needs ~(setq meow-use-cursor-position-hack t)~) |
| I   | join append | insert before first character in line                 |
| A   | line append | append end of line                                    |
| o   | open-below  | insert into line beneath                              |
| O   | open-above  | insert into line above                                |

* Delete and go to insert mode

| Vim            | Meow                | Description                                           |
|----------------+---------------------+-------------------------------------------------------|
| c <num> <noun> | <noun> <num> change | change                                                |
| r <char>       |                     | replace a single character and go back to normal mode |


* Normal mode modifications

| Vim            | Meow                     | Description                                                                                                                                                       |
|----------------+--------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ~              | /M-l/ & /M-u/ & /M-c/          | toggle case under cursor; not one to one replacement                                                                                                              |
| C-x            | *Not implemented* see [[https://www.emacswiki.org/emacs/IncrementNumber][here]] | decrement number under cursor.                                                                                                                                    |
| C-a            | *Not implemented* see [[https://www.emacswiki.org/emacs/IncrementNumber][here]] | increment number under cursor                                                                                                                                     |
| gUw            | word /C-x C-u/             | uppercase word (works with all nouns)                                                                                                                             |
| guw            | word /C-x C-l/             | lowercase word (works with all nouns)                                                                                                                             |
| x              | delete                   | delete under cursor                                                                                                                                               |
| D              | kill                     | delete to end of line                                                                                                                                             |
| dd             | kill OR kill-whole-line  | delete line                                                                                                                                                       |
| d <num> <noun> | <noun> <num> kill        |                                                                                                                                                                   |
| u              | undo                     | undo                                                                                                                                                              |
| C-r            | cancel undo              | redo; Emacs has a [[https://www.emacswiki.org/emacs/RedoMode][different undo system]] with a stack, so to undo the undo, you do some action which has no effect and afterwards ~meow-undo~ works in the other way |

* Macros

Vim uses registers to store macros. Meow only has a key to start a
macro and afterwards play it. When a new macro is recorded the old one
will be overridden.  The reason is that meow just wraps the [[https://www.emacswiki.org/emacs/KeyboardMacros][default
Emacs Macro]] behavior.

If you want to store the last recorded macro, you can give it a name
with ~kmacro-name-last-macro~ or give it a key with
~kmacro-to-register~. You can afterwards execute that command from the
~M-x~ menu.

| Vim          | Meow                           | Description              |
|--------------+--------------------------------+--------------------------|
| q <register> | start-kmacro-or-insert-counter | start a macro recording  |
| q            | end-or-call-kmacro             | finish a macro recording |
| @ <register> | end-or-call-kmacro             | play a macro             |

* Adjectives

Except for some cases, namely =meow-word=, =meow-line= and =meow-block=,
meow generalizes the idea of selection in and around "things". You may
select inside any "thing" by first calling =meow-inner-of-thing= and
then following the onscreen prompts. Meow makes it easy to define your
own "things" as well, all it takes is a pair of regular expressions!

| Vim          | Meow                     | Description             |
|--------------+--------------------------+-------------------------|
| <action> iw  | mark-word <action>       | current word            |
| <action> iW  | mark-symbol <action>     | current symbol          |
| <action> i[  | inner-of-thing <action>  | inside square brackets) |
| <action> ci[ | bounds-of-thing <action> | around square brackets) |

* Command Mode Operations
Generally there is no mode in meow similar to command mode. But there
is Keypad Mode (entered with space) which let's you execute normal
emacs commands without holding modifier keys. Many things done in
command mode can be achieved via this mode and some common and useful
examples are given here.

| Vim | Meow                 | Description          |
|-----+----------------------+----------------------|
| :w  | SPC x s              | (save buffer)        |
| :qa | SPC m x "kill-emacs" | close vim / emacs    |
| :wq | SPC x c              | save and close emacs |

* Vim Plugin

| Vim            | Meow            | Description                                 |
|----------------+-----------------+---------------------------------------------|
| commentary.vim | /M-;/             |                                             |
| vim-surround   | *Not implemented* | See [[surround][https://github.com/mkleehammer/surround]] |
