f1lt3r
f1lt3r

Reputation: 2223

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()

Upvotes: 0

Views: 642

Answers (1)

yolenoyer
yolenoyer

Reputation: 9445

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.

Upvotes: 1

Related Questions