用于切换colorschemes的vim函数
发布时间:2020-12-16 01:34:24 所属栏目:安全 来源:网络整理
导读:目前我正在使用两个不同的键来设置colorscheme map F8 :colors wombat256 crmap F9 :colors dimtag cr 我想实现像这样的切换行为 function! ToggleDimTags()if (g:colors_name == "wombat256") colors dimtagelse colors wombat256endifendfunction 我的问题
目前我正在使用两个不同的键来设置colorscheme
map <F8> :colors wombat256 <cr> map <F9> :colors dimtag <cr> 我想实现像这样的切换行为 function! ToggleDimTags() if (g:colors_name == "wombat256") colors dimtag else colors wombat256 endif endfunction 我的问题是ToogleDimTags()在每次调用时都将光标位置重置为第一行,这是不可取的.任何建议赞赏.
正如评论中所讨论的,问题是您的地图调用:执行
行为有点不同,你可能想要的是:改为: nnoremap <F5> :call ToggleDimTags() 为了澄清@ZyX的说法,:h:exec包含以下文本: :exe :execute :exe[cute] {expr1} .. Executes the string that results from the evaluation of {expr1} as an Ex command. [...] 那么:执行的确是评估表达式寻找字符串 exec ToggleDimTags() | " <-- ToggleDimTags() is evaluated and returns 0 exec 0 这是: :0 现在,:h:电话: :cal :call E107 E117 :[range]cal[l] {name}([arguments]) Call a function. The name of the function and its arguments are as specified with |:function|. Up to 20 arguments can be used. **The returned value is discarded**. [...] 更新 我一直在考虑你的功能,并使用三元运算符和一点点 nnoremap <silent> <F9> :exec "color " . ((g:colors_name == "wombat256") ? "dimtag" : "wombat256")<CR> 这里,这个nnoremap不会产生输出(< silent>)并且基于 "color " . ((g:colors_name == "wombat256") ? "dimtag" : "wombat256") 当g:colors_name设置为wombat256时,表达式的计算结果为: "color dimtag" 或者,否则: "color wombat256" 然后通过以下任一方法评估:exec.当然你可以加入这些台词(不要忘记删除反斜杠),我这样做只是为了避免太长的路线. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |