[英]How to call a plugin from my .vimrc file?
I am using a VIM plugin called Goyo (for writing markdown files). 我正在使用一个名为Goyo的VIM插件(用于编写降价文件)。 It is similar to Distraction Free mode in SublimeText. 它类似于SublimeText中的免干扰模式。 I want to create a write-mode in my .vimrc
that I can toggle. 我想在.vimrc
中创建一个可以切换的写模式。 This toggle will set various options on in write-mode, such as set spell
, set wrap
etc. 此切换将在写入模式下设置各种选项,例如set spell
, set wrap
等。
I have everything working here, except calling the Goyo
function. 除了调用Goyo
函数外,这里所有工作都在这里进行。 How can I execute the Goyo plugin from within my ToggleWrite() function? 如何在ToggleWrite()函数中执行Goyo插件?
Here is my code: 这是我的代码:
" Write toggle switch
let b:write = "no"
function! ToggleWrite()
if exists("b:write") && b:write == "yes"
let b:write = "no"
set nowrap
set nolinebreak
set textwidth=100
set wrapmargin=0
set nospell
" ↓↓↓ I want to call this ↓↓↓
":Goyo
else
let b:write = "yes"
set wrap
set linebreak
set textwidth=100
set wrapmargin=0
set spell
" ↓↓↓ I want to call this ↓↓↓
":Goyo 60x100%
endif
endfunction
" Set up the toggle sequence
nmap <expr> ,w ToggleWrite()
I put my comment as an answer: 我把我的评论作为答案:
Your mapping uses <expr>
, which is not right in your case. 您的映射使用<expr>
,这种情况不适合您。 You should try this mapping instead: 您应该尝试使用此映射:
nmap ,w :call ToggleWrite()<cr>
or 要么
nmap <silent> ,w :call ToggleWrite()<cr>
<expr>
lets you make "custom" mappings, depending on the return of a function. <expr>
允许您根据函数的返回进行“自定义”映射。 It's rarely used in common cases. 在常见情况下很少使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.