junegunn / vim-plug

:hibiscus: Minimalist Vim Plugin Manager
https://junegunn.github.io/vim-plug/
MIT License
33.7k stars 1.9k forks source link

[Feature Request]plugin installation declaration and plugin configuration put together #1246

Closed YuFei29 closed 1 year ago

YuFei29 commented 1 year ago

When we install a plug-in, we basically need to personalize the configuration of the plug-in. If the plug-in configuration can be placed where the plug-in is declared, the readability of the configuration file will be greatly enhanced. I often struggle to find the configuration of the corresponding plugin 😭

The emacs community has something like this, neovim's plug-in manager can generally put the configuration together, and kakoune can also.

If I'm not mistaken, this plugin currently has no way to declare the plugin configuration between plug#begin() and plug#end(), sorry if I'm wrong

emacs use-package package config example

(use-package vkill
  :commands vkill
  :idle (some-important-configuration-here)
  :bind ("C-x L" . vkill-and-helm-occur)
  :init
  (defun vkill-and-helm-occur ()
    (interactive)
    (vkill)
    (call-interactively #'helm-occur))

  :config
  (setq vkill-show-all-processes t))

neovim Lazy plugin manager

{
  "nvim-neo-tree/neo-tree.nvim",
    keys = {
      { "<leader>ft", "<cmd>Neotree toggle<cr>", desc = "NeoTree" },
    },
    config = function()
      require("neo-tree").setup()
    end,
}

kakoune kak-bundle plguin manager

bundle kak-lsp https://github.com/kak-lsp/kak-lsp %{
  # Configure here...
  hook global KakEnd .* lsp-exit
} %{
  # Post-install code here...
  cargo install --locked --force --path .
}
}
junegunn commented 1 year ago

this plugin currently has no way to declare the plugin configuration between plug#begin() and plug#end()

You can put plugin configuration anywhere in your Vim configuration file because most Vim plugins are configured via global variables (i.e. let g:something_something = ...). Here is an excerpt from my configuration. I'm using an extra indentation level to clarify the structure.

Plug 'tpope/vim-commentary'
  map  gc  <Plug>Commentary
  nmap gcc <Plug>CommentaryLine

Plug 'mbbill/undotree', { 'on': 'UndotreeToggle' }
  let g:undotree_WindowLayout = 2
  nnoremap U :UndotreeToggle<CR>

Plug 'inkarkat/vim-ReplaceWithRegister'

Plug 'AndrewRadev/splitjoin.vim'
  let g:splitjoin_split_mapping = ''
  let g:splitjoin_join_mapping = ''
  nnoremap gss :SplitjoinSplit<cr>
  nnoremap gsj :SplitjoinJoin<cr>

Plug 'AndrewRadev/switch.vim'
  let g:switch_mapping = '-'
  let g:switch_custom_definitions = [
  \   ['MON', 'TUE', 'WED', 'THU', 'FRI']
  \ ]

Plug 'sgur/vim-editorconfig'

" Browsing
Plug 'Yggdroot/indentLine', { 'on': 'IndentLinesEnable' }
  autocmd! User indentLine doautocmd indentLine Syntax
  let g:indentLine_color_term = 239
  let g:indentLine_color_gui = '#616161'

But if your plugin is configured via an autoload function (i.e. call something#setup(...)), the function is not available before plug#end(). in that case you can circumvent the limitation using autoload VimEnter.

Plug 'junegunn/vim-after-object'
  autocmd VimEnter * silent! call after_object#enable('=', ':', '#', ' ', '|')
YuFei29 commented 1 year ago

I tried your reply, it works. I always thought that it is not possible to put statements between plug#begin() and plug#end(). Thank you!