插入模式下的VIM Single Compile命令 [英] VIM Single Compile command from insert mode

查看:104
本文介绍了插入模式下的VIM Single Compile命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注在Vim中映射键-教程(第1部分) -6.2插入模式图,并显示:

The <C-R>= command doesn't create a new undo point.
You can also call Vim functions using the <C-R>= command:

:inoremap <F2> <C-R>=MyVimFunc()<CR>

我正试图用它来调用SingleCompile#Compile(),例如:

I'm trying to use this to call SingleCompile#Compile() like:

map! <F5> <C-R>=SingleCompile#Compile()<CR>

它正在工作,但是问题是当我回到插入模式时,会插入0字符作为副作用.

It's working, but the problem is that when I get back to insert mode, a 0 character is inserted as a side-effect.

为什么会这样,我该如何避免呢?

Why is this and how can I avoid it?

我正在使用<C-R>,因为它不会创建撤消点,并且具有调用函数的目的,而不是像<C-O>那样输入命令的目的.我不想创建一个撤消点.

I'm using <C-R> because it doesn't create a undo point and has the purpose of calling a function instead of entering a command like <C-O> does. I don't want to create a undo point.

我已经根据Ingo Karkat提供的三元运算符技巧更新了VIM Wiki.

I've updated the VIM wiki based on the ternary operator trick provided by Ingo Karkat.

推荐答案

函数的隐式返回值为0.您需要修改SingleCompile#Compile()或编写返回空字符串的包装器:

The implicit return value of a function is 0. You need to either modify SingleCompile#Compile() or write a wrapper that returns the empty string:

function! SingleCompileWrapper()
    call SingleCompile#Compile()
    return ''
endfunction

map! <F5> <C-R>=SingleCompileWrapper()<CR>

另一种巧妙的技巧是在?:三元运算符内部评估函数:

An alternative clever trick is to evaluate the function inside the ?: ternary operator:

map! <F5> <C-R>=SingleCompile#Compile()?'':''<CR>

这篇关于插入模式下的VIM Single Compile命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆