0

I have recently been trying to separate my neovim config into multiple files. After moving everything involving vim-fugitive and vim-gitgutter into a separate file, git-gutter is not loading and I cant perform any fugitive actions. I imagine this is a problem caused by how I used vim-plug here. Could anyone help me resolve this error?

here is my init.vim:

source $HOME/.config/nvim/default.vim
source $HOME/.config/nvim/fugitive.vim

call plug#begin()

Plug 'morhetz/gruvbox'
Plug 'mbbill/undotree'
Plug 'vim-airline/vim-airline'
Plug 'junegunn/vim-slash'
Plug 'preservim/nerdcommenter'
Plug 'tpope/vim-surround'
Plug 'Shougo/deoplete.nvim', { 'do': 'UpdateRemotePlugins' }
Plug 'zchee/deoplete-jedi'
Plug 'jiangmiao/auto-pairs'
Plug 'davidhalter/jedi-vim'
Plug 'junegunn/fzf', { 'do': { ->fzf#install() } }
Plug 'junegunn/fzf.vim' 
Plug 'airblade/vim-rooter'
"Plug 'stsewd/fzf-checkout.vim'

call plug#end()

"Plugin specific configuration

colorscheme gruvbox
set background=dark
let g:airline_powerline_fonts = 1

let g:fzf_layout = { 'window': {'width': 0.8, 'height': 0.8 }}
let $FZF_DEFAULT_OPS='--reverse'

" plugin key mappings
nmap <leader>c <plug>NERDCommenterToggle<SPACE>
nnoremap <leader>u :UndotreeShow<CR>
nnoremap <leader>pv :wincmd v<bar> :Ex <bar> :vertical resize 30<CR>
nnoremap <leader>ps :Rg<SPACE>

let g:deoplete#enable_at_startup = 1
autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif

" disable autocompletion, cause we use deoplete for completion
let g:jedi#completions_enabled = 0

" open the go-to function in split, not another buffer
let g:jedi#use_splits_not_buffers = "right"4

and here is my fugitive.vim

call plug#begin()
Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
call plug#end()

"key mappings for fugitive
nmap <leader>gs :G<CR>
nmap <leader>gj :diffget //3<CR>
nmap <leader>gf :diffget //2<CR>
nnoremap <leader>gc :GCheckout<CR>
5
  • Re: multiple files, everything in the plugin directory gets sourced unless you specify --noplugin. My own setup places lots of files in ~/.vim/plugin
    – D. Ben Knoble
    Sep 18, 2020 at 19:34
  • so if I just placed my fugitve.vim file into the plugin folder it will load without me having to say source fugitive.vim? Sep 18, 2020 at 22:05
  • Yep @destroyer449
    – D. Ben Knoble
    Sep 18, 2020 at 22:20
  • does this work on neovim? I tried this and it did not seem to make it function Sep 18, 2020 at 23:01
  • You probably need the right directory: whatever your neovim config dir is + plugin
    – D. Ben Knoble
    Sep 18, 2020 at 23:01

1 Answer 1

0

The problem is that you're using two separate plug#begin() blocks for vim-plug and that's not really supported. You should have a single plug#begin() and plug#end() and all the plug-ins registered inside that block.

You could fix that by using the following inside your init.vim:

source $HOME/.config/nvim/default.vim

call plug#begin()

source $HOME/.config/nvim/fugitive.vim

Plug 'morhetz/gruvbox'
" ...

call plug#end()

And then in fugitive.vim:

Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'

"key mappings for fugitive
nmap <leader>gs :G<CR>
nmap <leader>gj :diffget //3<CR>
nmap <leader>gf :diffget //2<CR>
nnoremap <leader>gc :GCheckout<CR>

It's fine to add other unrelated configurations such as mappings inside the plug#begin() to plug#end() block.

(Note 1: You should probably use nnoremap for the mappings above, there's really no reason not to use non-recursive mappings, which are generally safer.)

(Note 2: Instead of sourcing separate *.vim files from your init.vim, consider keeping everything inside init.vim and using folding for organization. Fold markers tend to work great on *.vim files.)

3
  • 1
    I’ve found i dont mind having separate files for some things, but i put them in plugin. YMMV
    – D. Ben Knoble
    Sep 19, 2020 at 3:28
  • @Ben But as far as I can tell, you can't (or shouldn't?) load new plug-ins (as in vim-plug plug-ins) from a plugin/*.vim file. I believe that's too late in startup to do that. Perhaps it works, but I don't believe it's actually supported... For instance, if you modify &rtp after Vim is finished with the vimrc file, I'm not sure it will correctly load the plugin/*.vim files from the new directory you added to &rtp...
    – filbranden
    Sep 19, 2020 at 3:40
  • 1
    Yes, that all seems true. I was referring more generally to note 2, but in that context i agree.
    – D. Ben Knoble
    Sep 19, 2020 at 3:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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