Skip to content

Commit

Permalink
Speedup plugin loading
Browse files Browse the repository at this point in the history
Use "plugin" folder for plugins configuration to avoid require calls.
Loading files from "plugin" is much faster and not cached.
  • Loading branch information
Shatur committed Jun 29, 2021
1 parent efd3be9 commit 539e211
Show file tree
Hide file tree
Showing 49 changed files with 188 additions and 175 deletions.
18 changes: 9 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@
path = pack/plugins/opt/nvim-bufferline.lua
url = git@github.com:akinsho/nvim-bufferline.lua.git
ignore = dirty
[submodule "pack/plugins/opt/telescope.nvim"]
path = pack/plugins/opt/telescope.nvim
url = git@github.com:nvim-telescope/telescope.nvim.git
[submodule "pack/plugins/start/telescope.nvim"]
path = pack/plugins/start/telescope.nvim
url = https://github.com/nvim-telescope/telescope.nvim.git
ignore = dirty
[submodule "pack/plugins/opt/plenary.nvim"]
path = pack/plugins/opt/plenary.nvim
url = git@github.com:nvim-lua/plenary.nvim.git
[submodule "pack/plugins/start/plenary.nvim"]
path = pack/plugins/start/plenary.nvim
url = https://github.com/nvim-lua/plenary.nvim.git
ignore = dirty
[submodule "pack/plugins/opt/popup.nvim"]
path = pack/plugins/opt/popup.nvim
url = git@github.com:nvim-lua/popup.nvim.git
[submodule "pack/plugins/start/popup.nvim"]
path = pack/plugins/start/popup.nvim
url = https://github.com/nvim-lua/popup.nvim.git
ignore = dirty
[submodule "pack/plugins/start/nvim-autopairs"]
path = pack/plugins/start/nvim-autopairs
Expand Down
95 changes: 85 additions & 10 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,33 @@ vim.g.loaded_fzf = false
-- Disable default keybindings <C-a> and <C-x> for interactive rebase
vim.g.no_gitrebase_maps = false

-- Open folder in system explorer
vim.cmd('command! -complete=dir -nargs=* Explorer lua require("config_utils.gtfo").open_explorer(vim.fn.expand("<args>"))')

-- Open folder in system terminal
vim.cmd('command! -complete=dir -nargs=* Terminal lua require("config_utils.gtfo").open_terminal(vim.fn.expand("<args>"))')

-- Used to prevent opening new buffers in a small buffers
vim.cmd('command! SwitchToNormalBuffer lua require("config_utils.buffers").switch_to_normal_buffer()')

-- Delete buffer with saving the current layout (except special buffers)
vim.cmd('command! BDelete lua require("config_utils.buffers").close_current_buffer()')

-- Delete all buffers except the current one
vim.cmd('command! BDeleteOther lua require("config_utils.buffers").close_other_buffers()')

-- Update all plugins and commit changes
vim.cmd('command! -nargs=? UpdatePlugins lua require("config_utils.updater").update_plugins(<args>)')

-- Pull latest configuration changes from repo
vim.cmd('command! UpdateConfig lua require("config_utils.updater").update_config()')

-- Start debugging
vim.cmd('command! -complete=file -nargs=+ Gdb lua require("config_utils.debug").gdb(<f-args>)')

-- Toggle diagnostics
vim.cmd('command! LspToggleDiagnostics lua require("config_utils.diagnostics").toggle_diagnostics()')

-- Remap useless keys
vim.g.mapleader = ' '
vim.api.nvim_set_keymap('n', 'Y', 'y$', { noremap = true })
Expand Down Expand Up @@ -117,13 +144,61 @@ vim.api.nvim_set_keymap('c', '<C-l>', '<C-\\>e("")<CR>', { noremap = true })
-- Other
vim.api.nvim_set_keymap('', '<Leader>cd', '<Cmd>cd %:h<CR>', { noremap = true })

-- Tab control
vim.api.nvim_set_keymap('', '<A-q>', '<Cmd>tabclose<CR>', { noremap = true })
vim.api.nvim_set_keymap('i', '<A-q>', '<Esc><Cmd>tabclose<CR>', { noremap = true })
vim.api.nvim_set_keymap('', '<A-x>', '<Cmd>w<CR><Cmd>tabclose<CR>', { noremap = true })
vim.api.nvim_set_keymap('i', '<A-x>', '<Esc><Cmd>w<CR><Cmd>tabclose<CR>', { noremap = true })
vim.api.nvim_set_keymap('', ']t', '<Cmd>tabnext<CR>', { noremap = true })
vim.api.nvim_set_keymap('', '[t', '<Cmd>tabnext<CR>', { noremap = true })

require('config.utils') -- Contains custom scripted things
require('config.plugins')
-- Buffers / tabs control
vim.api.nvim_set_keymap('', '<C-q>', '<Cmd>BDelete<CR>', { noremap = true })
vim.api.nvim_set_keymap('i', '<C-q>', '<Esc><Cmd>BDelete<CR>', { noremap = true })
vim.api.nvim_set_keymap('t', '<C-q>', '<Esc><Cmd>BDelete<CR>', { noremap = true })
vim.api.nvim_set_keymap('', '<C-x>', '<Cmd>w<CR><Cmd>BDelete<CR>', { noremap = true })
vim.api.nvim_set_keymap('i', '<C-x>', '<Esc><Cmd>w<CR><Cmd>BDelete<CR>', { noremap = true })
vim.api.nvim_set_keymap('', 'Q', '<Cmd>SwitchToNormalBuffer<CR><Cmd>BDeleteOther<CR>', { noremap = true })
vim.api.nvim_set_keymap('', '<Backspace>', '<Cmd>SwitchToNormalBuffer<CR><Cmd>buffer #<CR>', { noremap = true })

-- Open current file folder
vim.api.nvim_set_keymap('', 'got', '<Cmd>lua require("config_utils.gtfo").open_terminal(vim.fn.expand("%:h"))<CR>', { noremap = true })
vim.api.nvim_set_keymap('', 'goT', '<Cmd>lua require("config_utils.gtfo").open_terminal()<CR>', { noremap = true })
vim.api.nvim_set_keymap('', 'gof', '<Cmd>lua require("config_utils.gtfo").open_explorer(vim.fn.expand("%:h"))<CR>', { noremap = true })
vim.api.nvim_set_keymap('', 'goF', '<Cmd>lua require("config_utils.gtfo").open_explorer()<CR>', { noremap = true })

--- Custom group for all autocmd's in configuration
vim.cmd('augroup vimrc')
vim.cmd('autocmd!')
--- Highligh yanked text
vim.cmd('autocmd TextYankPost * silent! lua vim.highlight.on_yank()')
vim.cmd('augroup END')

-- Load some plugins conditionally
if vim.g.started_by_firenvim == true then
vim.cmd('packadd! firenvim')
else
vim.cmd('packadd! LuaSnip')
vim.cmd('packadd! asynctasks.vim')
vim.cmd('packadd! cfilter')
vim.cmd('packadd! diffview.nvim')
vim.cmd('packadd! gitlinker.nvim')
vim.cmd('packadd! gitsigns.nvim')
vim.cmd('packadd! lsp-status.nvim')
vim.cmd('packadd! lsp-trouble.nvim')
vim.cmd('packadd! lsp_signature.nvim')
vim.cmd('packadd! lualine.nvim')
vim.cmd('packadd! neogit')
vim.cmd('packadd! neovim-cmake')
vim.cmd('packadd! neovim-session-manager')
vim.cmd('packadd! nvim-bufferline.lua')
vim.cmd('packadd! nvim-dap')
vim.cmd('packadd! nvim-dap-virtual-text')
vim.cmd('packadd! nvim-lastplace')
vim.cmd('packadd! nvim-lspconfig')
vim.cmd('packadd! nvim-luaref')
vim.cmd('packadd! nvim-spectre')
vim.cmd('packadd! nvim-tree.lua')
vim.cmd('packadd! nvim-treesitter')
vim.cmd('packadd! nvim-web-devicons')
vim.cmd('packadd! octo.nvim')
vim.cmd('packadd! quickfix-reflector.vim')
vim.cmd('packadd! telescope-asynctasks.nvim')
vim.cmd('packadd! telescope-dap.nvim')
vim.cmd('packadd! vim-eunuch')
vim.cmd('packadd! vim-scriptease')
vim.cmd('packadd! vim-sleuth')
vim.cmd('packadd! vim-terminal-help')
end
1 change: 0 additions & 1 deletion lua/config/plugins/gitlinker.lua

This file was deleted.

2 changes: 0 additions & 2 deletions lua/config/plugins/indent-blankline.lua

This file was deleted.

73 changes: 0 additions & 73 deletions lua/config/plugins/init.lua

This file was deleted.

18 changes: 0 additions & 18 deletions lua/config/plugins/nerdfont.lua

This file was deleted.

1 change: 0 additions & 1 deletion lua/config/plugins/nvim-lastplace.lua

This file was deleted.

49 changes: 0 additions & 49 deletions lua/config/utils/init.lua

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions plugin/ayu.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('ayu').colorscheme()
4 changes: 4 additions & 0 deletions lua/config/plugins/bufferline.lua → plugin/bufferline.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

require('bufferline').setup{
highlights = {
buffer_selected = {
Expand Down
4 changes: 4 additions & 0 deletions lua/config/plugins/cmake.lua → plugin/cmake.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

vim.g.cmake_configure_arguments = '-G Ninja -D CMAKE_EXPORT_COMPILE_COMMANDS=1'
if vim.fn.has('unix') == 1 then
vim.g.cmake_configure_arguments = vim.g.cmake_configure_arguments .. ' -D CMAKE_CXX_FLAGS=-gdwarf-4'
Expand Down
2 changes: 1 addition & 1 deletion lua/config/plugins/compe.lua → plugin/compe.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ require('compe').setup{
}

-- luaeval is used because of this issue: https://github.com/neovim/neovim/issues/13862
vim.api.nvim_set_keymap('i', '<C-Space>', [[luaeval('require("config.utils.completion").trigger_completion()')]], { noremap = true, expr = true, silent = true })
vim.api.nvim_set_keymap('i', '<C-Space>', [[luaeval('require("config_utils.completion").trigger_completion()')]], { noremap = true, expr = true, silent = true })
vim.api.nvim_set_keymap('i', '<C-e>', 'compe#close("<C-e>")', { noremap = true, expr = true, silent = true })
4 changes: 4 additions & 0 deletions lua/config/plugins/dap.lua → plugin/dap.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

local dap = require('dap')

dap.adapters.cpp = {
Expand Down
4 changes: 4 additions & 0 deletions lua/config/plugins/diffview.lua → plugin/diffview.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

local callback = require('diffview.config').diffview_callback

require('diffview').setup {
Expand Down
4 changes: 4 additions & 0 deletions lua/config/plugins/firenvim.lua → plugin/firenvim.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim ~= true then
return
end

vim.g.laststatus = 0
vim.g.showtabline = 0

Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions plugin/gitlinker.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if vim.g.started_by_firenvim == true then
return
end

require('gitlinker').setup()
4 changes: 4 additions & 0 deletions lua/config/plugins/gitsigns.lua → plugin/gitsigns.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

require('gitsigns').setup {
signs = {
add = {text = ''},
Expand Down
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions plugin/lastplace.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if vim.g.started_by_firenvim == true then
return
end

require('nvim-lastplace').setup{}
4 changes: 4 additions & 0 deletions lua/config/plugins/lsp-trouble.lua → plugin/lsp-trouble.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

vim.api.nvim_set_keymap('', '<S-F3>', '<Cmd>LspTroubleDocumentToggle<CR>', { noremap = true })
vim.api.nvim_set_keymap('i', '<S-F3>', '<Cmd>LspTroubleDocumentToggle<CR>', { noremap = true })
vim.api.nvim_set_keymap('', '<A-F3>', '<Cmd>LspTroubleWorkspaceToggle<CR>', { noremap = true })
Expand Down
4 changes: 4 additions & 0 deletions lua/config/plugins/lsp.lua → plugin/lsp.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

local lspconfig = require('lspconfig')
local lsp_signature = require('lsp_signature')

Expand Down
4 changes: 4 additions & 0 deletions lua/config/plugins/lualine.lua → plugin/lualine.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
if vim.g.started_by_firenvim == true then
return
end

local lualine = require('lualine')
local colors = require('ayu.colors')
local theme_utils = require('ayu.utils')
Expand Down
12 changes: 8 additions & 4 deletions lua/config/plugins/luasnip.lua → plugin/luasnip.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
if vim.g.started_by_firenvim == true then
return
end

require'luasnip'.snippets={
all = {}
}

vim.api.nvim_set_keymap('i', '<Tab>', [[luaeval('require("config.utils.completion").tab_snippet()')]], { expr = true })
vim.api.nvim_set_keymap('i', '<S-Tab>', [[luaeval('require("config.utils.completion").s_tab_snippet()')]], { expr = true })
vim.api.nvim_set_keymap('s', '<Tab>', [[luaeval('require("config.utils.completion").tab_snippet()')]], { noremap = true, expr = true })
vim.api.nvim_set_keymap('s', '<S-Tab>', [[luaeval('require("config.utils.completion").s_tab_snippet()')]], { noremap = true, expr = true })
vim.api.nvim_set_keymap('i', '<Tab>', [[luaeval('require("config_utils.completion").tab_snippet()')]], { expr = true })
vim.api.nvim_set_keymap('i', '<S-Tab>', [[luaeval('require("config_utils.completion").s_tab_snippet()')]], { expr = true })
vim.api.nvim_set_keymap('s', '<Tab>', [[luaeval('require("config_utils.completion").tab_snippet()')]], { noremap = true, expr = true })
vim.api.nvim_set_keymap('s', '<S-Tab>', [[luaeval('require("config_utils.completion").s_tab_snippet()')]], { noremap = true, expr = true })
Loading

0 comments on commit 539e211

Please sign in to comment.