Is it possible to select text in Insert Mode?

434 Views Asked by At

I'm new to Neovim, I want to use Shift+Left and Shift+Right to select text, but I couldn't find any plugin/solution to achieve that.

I'm wondering if it is possible to do that. If it is achievable, what are the tools / Lua scripts I can use to make that. Or if it's not achievable, what's the way you'll prefer to select text?

I was trying to use some Visual Mode keymap to make it into what I want, but I just can't make it work.

1

There are 1 best solutions below

1
On BEST ANSWER
    {
        mode = { "i" },
        lhs = "<m-left>",
        rhs = "<c-o>v<c-g>",
        options = { silent = true },
        description = "Select previous word in insert mode",
    },
    {
        mode = { "s" },
        lhs = "<m-left>",
        rhs = "<c-g>h<c-g>",
        options = { silent = true },
        description = "Select previous word in insert mode",
    },

By using the two mappings, you can use <meta> + <left> (<ctrl> + <g> is used in my mapping) select text in insert mode. However, there are still many areas that are not covered, such as unable to use in the terminal or command mode.

This mapping simply simulates keystrokes based on the current mode. If the current mode is insert mode

  1. temporarily switch to normal mode first by press <ctrl-o>
  2. then press v to enter visual mode
  3. then press <ctrl-g> to enter select mode.

the second mapping is similar as the first one...

This is a very rudimentary implementation. If there are better methods of implementation, please kindly advise~

by the way, in insert mode, I am more accustomed to using some shortcuts:

  1. <ctrl-w> delete a word before cursor
  2. <ctrl-h> delete a char before cursor, like backspace
  3. <ctrl-u> clear the line
  4. ..., you can find more by using :h i_<some-key>