简体   繁体   中英

How to call a plugin from my .vimrc file?

I am using a VIM plugin called Goyo (for writing markdown files). It is similar to Distraction Free mode in SublimeText. I want to create a write-mode in my .vimrc that I can toggle. This toggle will set various options on in write-mode, such as set spell , set wrap etc.

I have everything working here, except calling the Goyo function. How can I execute the Goyo plugin from within my ToggleWrite() function?

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. 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. It's rarely used in common cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM