doums/coBra

Feature request: Overtype pair end

Closed this issue · 2 comments

When my cursor is right behind a closing end, and I type that character, I expect my cursor to jump over that character

Example:

| - cursor
Each line is a keystroke of "

|
"|"
""|

Current behavior:

|
"|"
""|"

coc-pairs behave like this, and I like this behavior. But yours can detect already matching pairs, and not match when not needed. And that's smart, not even vs-code does that!

doums commented

edit: This behaviors is already implemented for quotes too, I did not remember. But it's based on the syntax highlight group currently active under the cursor position (the only simple way to implement this without to have code hundred of lines). If this group name contains the word "string" so it's considered as a string. If not the AutoClose function is called.

" manage quote {{{
function s:ManageQuote(quote)
  if s:IsString(line("."), col("."))
        \ && s:IsString(line("."), col(".") - 1)
        \ && getline(".")[col(".") - 1] == a:quote
        \ && !s:IsEscaped()
    return "\<Right>"
  endif
  return s:AutoClose(a:quote, a:quote)
endfunction
" }}}

Hi, this behaviors work only with brackets character because I use vim functions for that:
search()
searchpos()
searchpair()
searchpairpos()

And these functions don't work with quotes character (presumably because a pair of quote is composed by the two same characters). But maybe I can do something using "String" syntax highlight group. I will check that.