10

I am starting to find parentheses / square bracket autocompletion annoying. The cursor remains inside the braces, and I have to reach the right arrow with my right pinky to get out of the bracket and continue typing.

On the other hand, I recognize that it saves time by not having to close it myself.

Is there any common feature in IDEs that would allow me to keep the best of both words, ie, keep the autocompletion, while having a quicker shortcut to jump out of them than the right arrow?

I'm currently using VS Code with Vim mode, but I'd also be interested in hearing general solutions from other text editors / IDEs.

alexcs
  • 203
  • 2
  • 4
  • Note that Vim uses h/j/k/l as arrow keys, so you don't have to stretch your pinky. – Ben Voigt Feb 12 '18 at 06:34
  • CudaText has option "auto_close_brackets" which has set of chars to autoclose, eg "([{". – RProgram Feb 12 '18 at 06:41
  • 1
    @BenVoigt Because of he still in insert mode, use arrow key can move without leaving insert mode. – foxiris Feb 12 '18 at 07:23
  • @foxiris: Yeah, I guess my mind was on normal mode because of Lieven's answer. – Ben Voigt Feb 12 '18 at 07:24
  • Does it possible use tab key to jump out the parentheses? In some snippets, you can jump to next definition. – foxiris Feb 12 '18 at 07:31
  • Not long ago, humans had to chip rocks to make spears, trudge miles through the snow, and kill mastodons for food just to survive. You're bothered by the need to extend your right pinky. Times and problems have changed. :-) – fixer1234 Feb 13 '18 at 02:07

3 Answers3

3

In VS Code with vim mode, you can choose between following options

  • Esc to normal mode and use the right arrow as you are doing (or the vim way: L)
  • Esc to normal mode and use A (append to end of line)
  • Stay in insert mode and type the closing delimiter. VS Code automatically jumps past the delimiter it started with autocomplete and you can just continue typing.
Lieven Keersmaekers
  • 1,513
  • 1
  • 9
  • 22
  • Probably worth adding that in vim normal mode, [l] (ell) is mapped the same as right arrow. – Ben Voigt Feb 12 '18 at 06:36
  • 1
    I knew that most editors I used allowed would skip over a self-closed bracket, but it hadn't occurred to me to use the feature. I think this is a pretty good solution as I find typing the bracket more comfortable than reaching for the right arrow, and at least the editor assists me in not forgetting brackets. – alexcs Feb 12 '18 at 13:22
  • Two keystrokes versus one if you close it yourself. – Miron Tewfik Mar 25 '22 at 06:26
  • I use "CTRL-o L" when writing lists to move between quote sign and parenthesis. I'm a vanilla guy and refuse to remap, it's hard enough to memorize vim's own key bindings. – Miron Tewfik Mar 25 '22 at 06:40
  • @MironTewfik - funny, I’m just recently trying to get into the habit of using CTRL-o more io ESC. Most of the time, indeed less keystrokes. – Lieven Keersmaekers Mar 25 '22 at 07:02
3

The idea of auto-close functionality is that it saves you time if there are brace(s) at the end of the typed text, so you can just leave insert mode before them, and don't need to type them. Also, you don't need to count to get the right amount of closing braces.

If you need to move over some braces, much of the promise of the functionality is lost (you could have just typed the closing brace(s) yourself). The plugin should ensure that there's no loss of efficiency; i.e. moving over braces should be easy. Instead of using , many plugins support just typing the brace character itself (I use this plugin for Vim, and it has this), and it will move over the identical character to the right of the cursor, instead of inserting a new one. That's faster and easier than leaving the home row for the cursor keys.

Ingo Karkat
  • 22,638
  • 2
  • 45
  • 58
0

Small delay my solution: I have included the following in my settings.json file. It jumps to the end of the line but works fine for jumping to the right ") ] ... in insert mode

{
    "vim.insertModeKeyBindings": [
    {
        "before": ["<C-j>"],
        "after": ["<ESC>", "A"]
    }
    ]
}
Improved it a bit (analogue to vim-latex).
My "setting.json" file :

{
      "vim.insertModeKeyBindings": [
    {
        "before": ["<C-j>"],
        "after": ["<ESC>", "/","<","+","+",">","<CR>","i","<DEL>","<DEL>","<DEL>","<DEL>"]
    },
    {
        "before": ["("],
        "after": ["(",")","<","+","+",">","<ESC>","4","h","i"]
        
    },
    {
        "before": ["["],
        "after": ["[","]","<","+","+",">","<ESC>","4","h","i"]
        
    },
    {
        "before": ["{"],
        "after": ["{","}","<","+","+",">","<ESC>","4","h","i"]
        
    },
    {
        "before": ["'"],
        "after": ["\"","\"","<","+","+",">","<ESC>","4","h","i"]
        
    }



    ],
  // "terminal.integrated.defaultProfile.linux": "zsh",
  //  "terminal.external.linuxExec": "gnome-terminal",
    "editor.autoClosingBrackets": "never",
    "editor.autoClosingQuotes": "never"
}