简体   繁体   English

如何从我的.vimrc文件中调用插件?

[英]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 spellset 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.

相关问题 如何从插件外部调用插件的功能 - How to call a function of a plugin from outside of that plugin 如何在主题为function.php的函数中调用插件简码? - How can i call a plugin shortcode from within a function with theme functions.php file? 如何从vimrc中执行menu.vim函数? - How to execute a menu.vim function from within vimrc? 如何从插件外部调用插件的方法(函数) - How to call a method(function) of a plugin from outside of that plugin vimrc的语法是什么,如何在vimrc中使用变量,函数? - What's the grammar of vimrc, how to use variable, function in vimrc? 如何从我的 python 类创建一个可调用的函数,而不必在调用时运行整个文件? - How to make a call-able function from my python Class, without having to run the entire file if called? 如何从WordPress插件中的一个函数调用函数? - How to call function from one function in WordPress plugin? 为什么.vimrc中的函数会被自动调用? - Why my function in .vimrc got called automatically? 如何在我的回调函数中添加一个额外的参数并从另一个文件中调用它 - How to add an extra parameter in my callback function and call it from another file 如何在点击WordPress插件的按钮上从WordPress插件设置页面调用函数 - how to Call a function from wordpress plugin settings page on a button click of wordpress plugin
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM