| 1 | # Migrating from Vim |
| 2 | |
| 3 | - [Delete/Change Commands](#deletechange-commands) |
| 4 | - [Navigation](#navigation) |
| 5 | - [Line Deletes](#line-deletes) |
| 6 | - [Comment lines, Completion, Search](#comment-lines-completion-search) |
| 7 | - [File actions](#file-actions) |
| 8 | |
| 9 | Helix's editing model is strongly inspired from Vim and Kakoune, and a notable |
| 10 | difference from Vim (and the most striking similarity to Kakoune) is that Helix |
| 11 | follows the `selection → action` model. This means that whatever you are |
| 12 | going to act on (a word, a paragraph, a line, etc.) is selected first and the |
| 13 | action itself (delete, change, yank, etc.) comes second. A cursor is simply a |
| 14 | single width selection. |
| 15 | |
| 16 | *Note:* As Helix is inspired by Vim and [Kakoune](https://github.com/mawww/kakoune), the keybindings are similar but also have some differences. The content of this page is inspired by [Kakoune Wiki](https://github.com/mawww/kakoune/wiki/Migrating-from-Vim). |
| 17 | |
| 18 | NOTE: Unlike vim, `f`, `F`, `t` and `T` are not confined to the current line. |
| 19 | |
| 20 | ## Delete/Change Commands |
| 21 | |
| 22 | delete a word: |
| 23 | * vim: `dw` |
| 24 | * helix: `wd` |
| 25 | |
| 26 | change a word: |
| 27 | * vim: `cw` |
| 28 | * helix: `ec` or `wc` (includes the whitespace after the word) |
| 29 | |
| 30 | delete a character: |
| 31 | * vim: `x` |
| 32 | * helix: `d` or `;d` (`;` reduces the selection to a single char) |
| 33 | |
| 34 | copy a line: |
| 35 | * vim: `yy` |
| 36 | * helix: `Xy` (`X` extends all selections to whole lines) |
| 37 | |
| 38 | global replace: |
| 39 | * vim: `:%s/word/replacement/g<ret>` |
| 40 | * helix: `%sword<ret>creplacement<esc>` |
| 41 | |
| 42 | Explanation: `%` selects the entire buffer, `s` opens a prompt for a regex, `<ret>` validates the regex and reduces the selection to each match (hence, all occurrences of word are selected). `c` deletes the selection contents and enter insert mode, replacement is typed and then `<esc>` goes back to normal mode. |
| 43 | |
| 44 | ## Navigation |
| 45 | |
| 46 | go to first line: |
| 47 | * vim: `gg` |
| 48 | * helix: `gg` |
| 49 | |
| 50 | go to last line: |
| 51 | * vim: `G` |
| 52 | * helix: `ge` |
| 53 | |
| 54 | go to line start: |
| 55 | * vim: `0` |
| 56 | * helix: `gh` |
| 57 | |
| 58 | go to line first non-blank character: |
| 59 | * vim: `^` |
| 60 | * helix: `gs` |
| 61 | |
| 62 | go to line end: |
| 63 | * vim: `$` |
| 64 | * helix: `gl` |
| 65 | |
| 66 | jump to matching bracket: |
| 67 | * vim: `%` |
| 68 | * helix: `mm` |
| 69 | |
| 70 | ## Line Deletes |
| 71 | |
| 72 | delete to line end: |
| 73 | * vim: `D` |
| 74 | * helix: `vgld` or `t<ret>d` |
| 75 | |
| 76 | Note: `v` is used along with `gl` (go to line end), because [`gl` does not select text](https://github.com/helix-editor/helix/issues/1630). |
| 77 | `t<ret>` selects "'til" the newline represented by `<ret>`. |
| 78 | |
| 79 | delete entire line: |
| 80 | * vim: `dd` |
| 81 | * helix: `xd` |
| 82 | |
| 83 | Note: `x` selects the entire line under the cursor |
| 84 | |
| 85 | ## Comment lines, Completion, Search |
| 86 | |
| 87 | auto complete: |
| 88 | * vim: `C-p` |
| 89 | * helix: `C-x` |
| 90 | |
| 91 | comment lines: |
| 92 | * vim: `gc` |
| 93 | * helix: `Space-c` |
| 94 | |
| 95 | search for the word under the cursor: |
| 96 | * vim: `*` |
| 97 | * helix: `A-o*n` (if there's a tree-sitter grammar or LSP) or `be*n` |
| 98 | |
| 99 | Explanation: if there's a grammar or LSP, `A-o` expands selection to the parent syntax node (which would be the word in our case). Then `*` uses the current selection as the search pattern, and `n` goes to the next occurrence. `b` selects to the beginning of the word, and `e` selects to the end of the word, effectively selecting the whole word. |
| 100 | |
| 101 | block selection: |
| 102 | * vim: `C-v`, then expand your selection vertically and horizontally |
| 103 | * helix: There's no "block selection" mode, so instead you'd use multiple cursors. Expand your block selection vertically by adding new cursors on the line below with `C`, and horizontally using standard movements |
| 104 | |
| 105 | search "foo" and replace with "bar" in the current selection: |
| 106 | * vim: `:s/foo/bar/g<ret>` |
| 107 | * helix: `sfoo<ret>cbar<esc>,` |
| 108 | |
| 109 | Explanation: `s` will open a prompt in the command line for a regex, and select all matches inside the selection (effectively adding a new cursor on each match). Pressing enter will then finalise this step, and allow the `c` to change the selections to "bar". When done, go back to normal mode with `<esc>`, and keep only the primary selection with `,` (remove all the additional cursors). |
| 110 | |
| 111 | ## File actions |
| 112 | |
| 113 | select the whole file: |
| 114 | * vim: `ggVG` |
| 115 | * helix: `%` |
| 116 | |
| 117 | reload a file from disk: |
| 118 | * vim: `:e<ret>` |
| 119 | * helix: `:reload<ret>` (or `:reload-all<ret>` to reload all the buffers) |
| 120 | |
| 121 | run shell command: |
| 122 | * vim: `:!command` |
| 123 | * helix: `:sh command` (or `!command` to insert its output into the buffer) |
| 124 | |
| 125 | setting a bookmark (bookmarking a location): |
| 126 | * vim: `ma` to set bookmark with name a. Use `` `a `` to go back to this bookmarked location. |
| 127 | * helix: there are no named bookmarks, but you can save a location in the jumplist with `C-s`, then jump back to that location by opening the jumplist picker with `<space>-j`, or back in the jumplist with `C-o` and forward with `C-i` |
| 128 | |
| 129 | Helix allows [some limited movement in `insert` mode](https://docs.helix-editor.com/keymap.html#insert-mode) without switching to `normal` mode. |
| 130 | |
| 131 | Unlike Vim, under Helix, the cursor shape is the same (block) in insert mode and normal mode by default. |
| 132 | This can be adjusted in configuration: |
| 133 | |
| 134 | ```toml |
| 135 | [editor.cursor-shape] |
| 136 | insert = "bar" |
| 137 | ``` |
| 138 | |
| 139 | > TODO: Mention textobjects, surround, registers |
| 140 |