What is the return value for visual block mode in vimscript?

余生长醉 提交于 2019-12-24 08:11:13

问题


I'm trying to display the current mode of vim on the status line by mapping the return value of mode function by using a dictionary:

let g:modeMap={
    \ 'n'      : 'Normal',
    \ 'i'      : 'Insert',
    \ 'R'      : 'Replace',
              ...
    \ 'v'      : 'Visual',
    \ 'V'      : 'Visual Line',
    \ '\<C-V>' : 'Visual Block'
    \}

set laststatus=2
set statusline=%{g:modeMap[mode()]}

It works well for almost all modes, however it throws the following error message in case of switching to visual block mode:

E716: Key not present in Dictionary: ^V 

I've also tried the string <\C-V> found here, CTRL-V found here and ^V which was written out in the error message but neither of them was correct.

Tested with versions:

  • Vim 7.4, Ubuntu 16.04
  • Vim 8.1, Debian 9

回答1:


'\<C-V>' -- is a literal string in VimL.

You must use double quotes to make the substitution work: "\<C-V>".



来源:https://stackoverflow.com/questions/56274737/what-is-the-return-value-for-visual-block-mode-in-vimscript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!