4

I'm mostly a Neovim user and I would like to share part of my config with regular Vim. Here's the problem: my init.vim is organized in such a way that at the top there are the general Vim options, custom mappings and things that don't depend on any plugin being installed. At the bottom there's the usual vim-plug block plus all the options as they related to specific plugins.

What I would like to do is to symlink my ~/.vimrc to my ~/.config/nvim/init.vim and have something like this in my init.vim:

" General options

if !has('nvim')
    " Stop sourcing here if regular vim is sourcing this file
endif

" Plugins options

When I open Vim, I usually don't need my plugins but I would still like to keep my settings, mappings and whatnot. However, I'm having a hard time finding which instruction I should use instead of that comment.

I tried using return but I got an error during startup saying that the keyword can be used only inside of functions. I also tried using exit but that causes Vim to close itself right away.

Is there any way to achieve this?

P.S. I know I could use

if has('nvim')
   " Plugins options
endif

but the plugins section spans several lines and I just think the other way is cleaner.

6

The command is called finish. So it's pretty trivial

if !has('nvim')
    " Stop sourcing here if regular vim is sourcing this file
    finish
endif
| improve this answer | |
  • Exactly what I needed. Thanks! – brainplot Jul 8 at 23:21

Not the answer you're looking for? Browse other questions tagged or ask your own question.