Vim在退格上显示着色标记

时间:2016-02-01 16:18:10

标签: vim

每次我处于插入模式时,当我按退格键时,会出现类似下图所示的内容。在保存时,一切都得到了妥善保存,但在此之前 - 它看起来很糟糕。

好像是贝壳颜色字符,但我不太确定。

经过一些测试,并删除.vimrc的部分,似乎是delimitMate的问题。

可能是什么原因?

weird display

1 个答案:

答案 0 :(得分:1)

s:ExtraMappings()plugin/delimitMate.vim中定义 Backspace 的地图:

" If pair is empty, delete both delimiters:
inoremap <silent> <Plug>delimitMateBS <C-R>=delimitMate#BS()<CR>
if !hasmapto('<Plug>delimitMateBS','i')
  if empty(maparg('<BS>', 'i'))
    silent! imap <unique> <buffer> <BS> <Plug>delimitMateBS
  endif
  if empty(maparg('<C-H>', 'i'))
    silent! imap <unique> <buffer> <C-h> <Plug>delimitMateBS
  endif
endif

请注意,<Plug>delimitMateBS已映射到<C-R>=delimitMate#BS()<CR><C-R>=输入一个表达式,该表达式将由delimitMate#BS()返回。见:help c_CTRL-R_=

'='     the expression register: you are prompted to
        enter an expression (see expression)

delimitMate#BS()返回关键输入以处理autoload/delimitMate.vim中的对:

function! delimitMate#BS() " {{{
  if s:is_forbidden("")
    let extra = ''
  elseif &bs !~ 'start\|2'
    let extra = ''
  elseif delimitMate#WithinEmptyPair()
    let extra = "\<Del>"
  elseif s:is_space_expansion()
    let extra = "\<Del>"
  elseif s:is_cr_expansion()
    let extra = repeat("\<Del>",
          \ len(matchstr(getline(line('.') + 1), '^\s*\S')))
  else
    let extra = ''
  endif
  return "\<BS>" . extra
endfunction " }}} delimitMate#BS()

通过查看代码,您可以知道返回值可以是:

  • "\<BS>"
  • "\<BS>\<Del>"
  • "\<BS>\<Del>\<Del>"
  • ...

我认为这是处理 Backspace 删除的问题。有关其他信息,请参阅:help :fixdel

:fix[del]               Set the value of 't_kD':
                                't_kb' is     't_kD' becomes
                                  CTRL-?        CTRL-H
                                not CTRL-?      CTRL-?

                        (CTRL-? is 0177 octal, 0x7f hex) {not in Vi}

                        If your delete key terminal code is wrong, but the
                        code for backspace is alright, you can put this in
                        your .vimrc:
                                :fixdel
                        This works no matter what the actual code for
                        backspace is.

                        If the backspace key terminal code is wrong you can
                        use this:
                                :if &term == "termname"
                                :  set t_kb=^V<BS>
                                :  fixdel
                                :endif
                        Where "^V" is CTRL-V and "<BS>" is the backspace key
                        (don't type four characters!).  Replace "termname"
                        with your terminal name.

                        If your <Delete> key sends a strange key sequence (not
                        CTRL-? or CTRL-H) you cannot use ":fixdel".  Then use:
                                :if &term == "termname"
                                :  set t_kD=^V<Delete>
                                :endif
                        Where "^V" is CTRL-V and "<Delete>" is the delete key
                        (don't type eight characters!).  Replace "termname"
                        with your terminal name.