codemirror-vim icon indicating copy to clipboard operation
codemirror-vim copied to clipboard

feat: implement select mode

Open superle3 opened this issue 7 months ago • 0 comments

Why

Implements #239

There are some usefull keybindings in insert mode while having something selected, for example surrounding the current selection with (), but selecting the right text is easier in visual mode than using a mouse or arrow keys. Vim also a select mode at https://vimhelp.org/visual.txt.html#Select, this only implements switching between visual and insert mode while keeping the selection and doesn't keep the selection mode (blockmode, linewise, normal).

Example:

https://github.com/user-attachments/assets/e3576505-6acf-4e5f-bb8a-e3d80fc8e65f

What changed

Adds an action binded to <C-g> that runs in insert mode and visual mode. If there is a selection, it switches between visual and insert mode while keeping the current selections. Ideally it doesn't overwrite the <C-g> keybinding when there is no selection, but couldn't find a way to do that.

Test plan

  1. given the following text and | is the cursor
Some important text|
  1. Select the text using the following
  • v0 (select the entire line)
  • <C-g> (switch to select mode)
  1. See the cursor change from block-cursor to insert cursor.
  2. Test a insert-only command, for example <C-x>, cuts the entire line/the selected text.
  3. Repeat 1-3 and test <C-g> again and test a visual-only command, for example d (cuts the entire line).

superle3 avatar Jul 20 '25 15:07 superle3