3

When I'm choosing an option from the autocomplete suggestions, it automatically puts my cursor in the following location:

function(|)

Then I type the value that I want, and in order to get out of the brackets (forward) I have to use the right arrow button, to yield:

function(value)|

Which is pretty inconvenient. Is there any better option?

EDIT: As mentioned in one of the comments, the ) char can be used, but for me personally it's not more convenient. I would like to map'the return (Enter) key to function as the right arrow key in this specific situation.

8
  • If you're using "auto-pairs" plug-in, you should be able to type ) when over a closing paren to get out of it. Doesn't that work for you? (Happy to turn this into an answer if it does work for you and was what you were actually looking for...)
    – filbranden
    Commented Nov 29, 2019 at 12:12
  • Thanks for asking that. I forgot to mention that the solution you mentioned is available for me but from my subjective point of my personal comfort, this method for me is like using the arrow key for doing the job. I would like to "map" a key (perhaps even the return key) to do that in the mentioned particular case.
    – idankor
    Commented Nov 29, 2019 at 12:15
  • Auto-pairs has two default mappings that might also help: <M-e> for "fast wrap" and <M-n> to jump to the next closed pair. It seems to me the former might fit your use case? <M-e> typically means you need to press "Alt-e" to access it. Does that help? Not sure if mapping the Return key to get out of a pair would be feasible, since you often want line breaks within a pair and that's what Return does there, right?
    – filbranden
    Commented Nov 29, 2019 at 12:22
  • Thanks again, @filbranden, I'm not sure how to use the "fast wrap". Can you specify the exact key strokes?
    – idankor
    Commented Nov 29, 2019 at 12:25
  • Take a look at the full Readme for auto-pairs. There's also Fly mode which you might find interesting. The original intent is that you'd type the closing bracket to get out of it and continue typing the expression. Other shortcut exists, the ones I mentioned earlier. If you want something different, please update the question to explain why these don't work for you and what you'd like to have instead...
    – filbranden
    Commented Nov 29, 2019 at 12:26

3 Answers 3

2

I use <esc>A, it's 2.5 key strokes(0.5 for shift), it's not the shortest solution, but it's the most natural one if you are used to move around in normal mode. IMO, <esc> doesn't count as a keystroke.

<c-o>A works too, but I don't like it, I can't remember the last time i use :h i_CTRL-O .

You can also create a map for this:

inoremap <c-l> <right>

Change <c-l> to whatever key you like, I wouldn't use it, this kind of map is unnatural, it's also a burden to create, maintain and remember maps for trivial stuff.

3
  • why <c-o>A is not recommended, though?
    – Maxim Kim
    Commented Nov 29, 2019 at 12:53
  • @MaximKim It's just a habit, my fingers are used to it. Don't want to choose between esc and c-o, as brain need time to choose.
    – dedowsdi
    Commented Nov 29, 2019 at 13:29
  • For me it is quite natural, use it all the time. Also I usually use C-[ instead of ESC and it is next to C-o in terms of fingers used.
    – Maxim Kim
    Commented Nov 29, 2019 at 14:19
0

vim-rsi: Readline key bindings

The plugin vim-rsi by tpope provides readline style insert mode mappings. Following two might be of help in your case

                                        *rsi-CTRL-E*
<C-e>           Go to end of line.  Falls back to |i_CTRL-E| if
                already at the end of the line.  (|c_CTRL-E| already
                goes to end of line, so it is not mapped.)

                                        *rsi-CTRL-F*
<C-f>           Move forward one character.  Falls back to
                |i_CTRL-F| or |c_CTRL-F| at the end of the line.
0

Here's a quick hack you could put in your .vimrc:

inoremap <Enter> <esc>:call DetectIfParens()<cr> i     // exits the insert mode and will return to it when the function ends

function DetectIfParens()
    let char = getline('.')[col('.')]                 // here we are in normal mode; check if the character to the right of the cursor is a closing parenthesis
    if (char==")")
        normal l                                      // puts the cursor after the parenthesis (sends the "l" key in normal mode)
    endif
endfunction                                          // after the function ends, you'll be in insert mode again 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.