552 lines
18 KiB
Lua
552 lines
18 KiB
Lua
-------------------------------------------------
|
|
-------------------OPTIONS-----------------------
|
|
-------------------------------------------------
|
|
|
|
-- enable animation of command like "<C-u>" and "<C-d>", or cursor
|
|
-- jump animation. (Performence will be effected)
|
|
local animation_enable = vim.g.animation_enable
|
|
local high_performence = vim.g.high_performence
|
|
|
|
-- false basicly enable plugins like noice, nvim-notify etc.
|
|
local classic_vim_ui = vim.g.classic_vim_ui
|
|
|
|
-------------------------------------------------
|
|
------------------UTILITIES----------------------
|
|
-------------------------------------------------
|
|
|
|
local vim = vim
|
|
function HasPlug(name)
|
|
return vim.fn.HasPlug(name)
|
|
end
|
|
|
|
-- use as a wrapper function to set keymap that call a function with
|
|
-- parameters
|
|
local _wrap = function(func, ...)
|
|
local args = { ... }
|
|
return function()
|
|
func(unpack(args))
|
|
end
|
|
end
|
|
|
|
-- use to print object
|
|
function _G.put(...)
|
|
local objects = {}
|
|
for i = 1, select('#', ...) do
|
|
local v = select(i, ...)
|
|
table.insert(objects, vim.inspect(v))
|
|
end
|
|
|
|
print(table.concat(objects, '\n'))
|
|
return ...
|
|
end
|
|
|
|
local wk = nil
|
|
local function wk_register(opt)
|
|
if wk == nil then
|
|
return
|
|
end
|
|
wk.register(opt)
|
|
end
|
|
|
|
-------------------------------------------------
|
|
----------------CONFIGURATION--------------------
|
|
-------------------------------------------------
|
|
|
|
local vim_version = vim.version()
|
|
|
|
local vim_version_minor = vim_version['minor']
|
|
|
|
local show_icon = false
|
|
if HasPlug('nvim-web-devicons') then
|
|
show_icon = true
|
|
end
|
|
|
|
local function nvim_noice_config()
|
|
if classic_vim_ui
|
|
or not HasPlug('noice.nvim')
|
|
or not HasPlug('nvim-notify')
|
|
or not HasPlug('nui.nvim') then
|
|
return
|
|
end
|
|
|
|
require("noice").setup({
|
|
lsp = {
|
|
-- override markdown rendering so that **cmp** and other plugins use **Treesitter**
|
|
override = {
|
|
["vim.lsp.util.convert_input_to_markdown_lines"] = true,
|
|
["vim.lsp.util.stylize_markdown"] = true,
|
|
["cmp.entry.get_documentation"] = true,
|
|
},
|
|
},
|
|
-- you can enable a preset for easier configuration
|
|
presets = {
|
|
bottom_search = true, -- use a classic bottom cmdline for search
|
|
-- command_palette = true, -- position the cmdline and popupmenu together
|
|
long_message_to_split = true, -- long messages will be sent to a split
|
|
inc_rename = false, -- enables an input dialog for inc-rename.nvim
|
|
lsp_doc_border = false, -- add a border to hover docs and signature help
|
|
},
|
|
cmdline = {
|
|
enabled = true, -- enables the Noice cmdline UI
|
|
-- view = "cmdline", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom
|
|
opts = {}, -- global options for the cmdline. See section on views
|
|
format = {
|
|
-- cmdline = false,
|
|
search_down = false,
|
|
search_up = false,
|
|
-- filter = false,
|
|
-- help = false,
|
|
-- input = {}, -- Used by input()
|
|
-- lua = false, -- to disable a format, set to `false`
|
|
},
|
|
},
|
|
messages = {
|
|
-- NOTE: If you enable messages, then the cmdline is enabled automatically.
|
|
-- This is a current Neovim limitation.
|
|
enabled = true, -- enables the Noice messages UI
|
|
view = "notify", -- default view for messages
|
|
view_error = "notify", -- view for errors
|
|
view_warn = "notify", -- view for warnings
|
|
view_history = "messages", -- view for :messages
|
|
view_search = false, -- view for search count messages. Set to `false` to disable
|
|
},
|
|
})
|
|
end
|
|
|
|
local function nvim_scrollbar_config()
|
|
if classic_vim_ui or
|
|
not HasPlug('nvim-scrollbar') then
|
|
return
|
|
end
|
|
require("scrollbar").setup({
|
|
excluded_filetypes = {
|
|
"prompt",
|
|
"TelescopePrompt",
|
|
"noice",
|
|
"startify",
|
|
"vista",
|
|
},
|
|
})
|
|
end
|
|
|
|
local function toggleterm_config()
|
|
if not HasPlug('toggleterm.nvim') then
|
|
return
|
|
end
|
|
require("toggleterm").setup({
|
|
open_mapping = [[<c-\>]],
|
|
})
|
|
function _G.set_terminal_keymaps()
|
|
local opts = {buffer = 0}
|
|
vim.keymap.set('t', '<esc>', [[<C-\><C-n>]], opts)
|
|
vim.keymap.set('t', 'jk', [[<C-\><C-n>]], opts)
|
|
vim.keymap.set('t', '<C-h>', [[<Cmd>wincmd h<CR>]], opts)
|
|
vim.keymap.set('t', '<C-j>', [[<Cmd>wincmd j<CR>]], opts)
|
|
vim.keymap.set('t', '<C-k>', [[<Cmd>wincmd k<CR>]], opts)
|
|
vim.keymap.set('t', '<C-l>', [[<Cmd>wincmd l<CR>]], opts)
|
|
vim.keymap.set('t', '<C-w>', [[<C-\><C-n><C-w>]], opts)
|
|
end
|
|
|
|
vim.cmd('autocmd! TermOpen term://* lua set_terminal_keymaps()')
|
|
end
|
|
|
|
local function vim_illuminate_config()
|
|
if not HasPlug('vim-illuminate') then
|
|
return
|
|
end
|
|
local illuminate = require('illuminate')
|
|
illuminate.configure({
|
|
providers = {
|
|
'lsp',
|
|
'treesitter',
|
|
'regex',
|
|
},
|
|
delay = 0,
|
|
filetype_overrides = {},
|
|
filetypes_denylist = {
|
|
'dirvish',
|
|
'fugitive',
|
|
'NvimTree',
|
|
'help',
|
|
'vista',
|
|
},
|
|
filetypes_allowlist = {},
|
|
modes_denylist = {},
|
|
modes_allowlist = {},
|
|
providers_regex_syntax_denylist = {},
|
|
providers_regex_syntax_allowlist = {},
|
|
under_cursor = true,
|
|
large_file_cutoff = nil,
|
|
large_file_overrides = nil,
|
|
min_count_to_highlight = 1,
|
|
})
|
|
end
|
|
|
|
local function which_key_config()
|
|
if not HasPlug('which-key.nvim') then
|
|
return
|
|
end
|
|
wk = require("which-key")
|
|
wk.setup()
|
|
end
|
|
|
|
local function telescope_config()
|
|
if not HasPlug('telescope.nvim') then
|
|
return
|
|
end
|
|
if HasPlug('telescope-fzf-native.nvim') then
|
|
require('telescope').setup {
|
|
pickers = {
|
|
colorscheme = {
|
|
enable_preview = true
|
|
}
|
|
},
|
|
extensions = {
|
|
fzf = {
|
|
fuzzy = true, -- false will only do exact matching
|
|
override_generic_sorter = true,
|
|
override_file_sorter = true,
|
|
case_mode = "smart_case", -- or "ignore_case" or "respect_case"
|
|
}
|
|
}
|
|
}
|
|
require('telescope').load_extension('fzf')
|
|
end
|
|
|
|
local builtin = require('telescope.builtin')
|
|
|
|
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = "Search files inside cwd" })
|
|
-- need to install ripgrep
|
|
vim.keymap.set('n', '<leader>fr', builtin.live_grep, { desc = "Regex search inside files" })
|
|
vim.keymap.set('n', '<leader>fb', builtin.buffers, { desc = "Search buffers" })
|
|
vim.keymap.set('n', '<leader>fc', builtin.colorscheme, { desc = "Search colorscheme" })
|
|
wk_register({ ["<leader>f"] = { name = "+Telescope" }})
|
|
|
|
vim.api.nvim_create_autocmd("User", {
|
|
pattern = "TelescopePreviewerLoaded",
|
|
command = "setlocal wrap number" })
|
|
end
|
|
|
|
local function github_theme_config()
|
|
if not HasPlug('github-nvim-theme') then
|
|
return
|
|
end
|
|
-- Example config in Lua
|
|
require("github-theme").setup({
|
|
-- Overwrite the highlight groups
|
|
overrides = function(c)
|
|
return {
|
|
NormalFloat = { link = 'Pmenu' },
|
|
}
|
|
end
|
|
})
|
|
end
|
|
|
|
local function animate_config()
|
|
if not animation_enable then
|
|
return
|
|
end
|
|
|
|
if HasPlug('mini.animate') then
|
|
|
|
local animate = require('mini.animate')
|
|
animate.setup({
|
|
cursor = {
|
|
-- Whether to enable this animation
|
|
enable = true,
|
|
-- Timing of animation (how steps will progress in time)
|
|
-- timing = --<function: implements linear total 250ms animation duration>,
|
|
},
|
|
scroll = {
|
|
-- Whether to enable this animation
|
|
enable = true,
|
|
-- Timing of animation (how steps will progress in time)
|
|
timing = animate.gen_timing.linear({ duration = 150, unit = 'total' }),
|
|
},
|
|
open = {
|
|
-- Whether to enable this animation
|
|
enable = false,
|
|
},
|
|
})
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason",
|
|
"NvimTree", "vista", "toggleterm", "noice" },
|
|
callback = function()
|
|
vim.b.minianimate_disable = true
|
|
end,
|
|
})
|
|
end
|
|
|
|
-- if HasPlug('neoscroll.nvim') then
|
|
-- require('neoscroll').setup({
|
|
-- -- Set any options as needed
|
|
-- mappings = {'<C-u>', '<C-d>', '<C-b>', '<C-f>',
|
|
-- },
|
|
-- })
|
|
|
|
-- local t = {}
|
|
-- -- Syntax: t[keys] = {function, {function arguments}}
|
|
-- t['<C-u>'] = {'scroll', {'-vim.wo.scroll', 'true', '150'}}
|
|
-- t['<C-d>'] = {'scroll', { 'vim.wo.scroll', 'true', '150'}}
|
|
-- t['<C-b>'] = {'scroll', {'-vim.api.nvim_win_get_height(0)', 'true', '200'}}
|
|
-- t['<C-f>'] = {'scroll', { 'vim.api.nvim_win_get_height(0)', 'true', '200'}}
|
|
-- -- t['zb'] = {'zb', {'250'}}
|
|
|
|
-- require('neoscroll.config').set_mappings(t)
|
|
-- end
|
|
end
|
|
|
|
local function indentline_config()
|
|
if not animation_enable then
|
|
if HasPlug('indent-blankline.nvim') then
|
|
-- Example config in Lua
|
|
require("indent_blankline").setup {
|
|
show_current_context = true,
|
|
filetype_exclude = { "lspinfo", "packer", "checkhealth",
|
|
"help", "man", "", "startify", }
|
|
-- use_treesitter = true,
|
|
}
|
|
end
|
|
else
|
|
if HasPlug('mini.indentscope') then
|
|
MiniIndentscope = require('mini.indentscope')
|
|
MiniIndentscope.setup({
|
|
symbol = '│',
|
|
-- draw = {
|
|
-- animation = MiniIndentscope.gen_animation.linear({
|
|
-- easing = 'out',
|
|
-- duration = 150,
|
|
-- unit = 'total'
|
|
-- })
|
|
-- },
|
|
})
|
|
vim.api.nvim_create_autocmd("FileType", {
|
|
pattern = { "help", "alpha", "dashboard", "neo-tree", "Trouble", "lazy", "mason",
|
|
"NvimTree", "vista", "startify", "toggleterm" },
|
|
callback = function()
|
|
vim.b.miniindentscope_disable = true
|
|
end,
|
|
})
|
|
end
|
|
end
|
|
end
|
|
|
|
local function transparent_config()
|
|
if not HasPlug('nvim-transparent') then
|
|
return
|
|
end
|
|
require("transparent").setup({
|
|
enable = true, -- boolean: enable transparent
|
|
extra_groups = { -- table/string: additional groups that should be cleared
|
|
-- In particular, when you set it to 'all', that means all available groups
|
|
"NvimTreeNormal",
|
|
"VertSplit",
|
|
},
|
|
exclude = {}, -- table: groups you don't want to clear
|
|
})
|
|
end
|
|
|
|
local function lualine_config()
|
|
if not HasPlug('lualine.nvim') then
|
|
return
|
|
end
|
|
|
|
vim.api.nvim_set_hl(0, 'CocstatusSucceed', { fg = "#e32be0"})
|
|
vim.api.nvim_set_hl(0, 'CocstatusLoading', { fg = "#35f0e9"})
|
|
-- custom lualine plugin show coc lsp status
|
|
local function cocstatus()
|
|
local loading = {"⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"}
|
|
local step = #loading
|
|
local ok, result = pcall( vim.fn.CocAction, 'services')
|
|
if not ok then
|
|
return
|
|
end
|
|
local ft = vim.bo.filetype
|
|
local state, id
|
|
for _, entry in ipairs(result) do
|
|
if entry['languageIds'][1] == ft then
|
|
state = entry['state']
|
|
id = entry['id']
|
|
break
|
|
end
|
|
end
|
|
|
|
local speed = 1600
|
|
local loadidx = (vim.loop.now() % speed)
|
|
local msg = "LSP(" .. id .. ")"
|
|
if state == "starting" then
|
|
return msg .. " %#CocstatusLoading#" .. loading[math.floor(loadidx/(step * (speed/100))) + 1]
|
|
end
|
|
return msg .. " %#CocstatusSucceed#✔"
|
|
end
|
|
|
|
local disabled_filetypes_data = {}
|
|
if vim_version_minor < 7 then
|
|
-- globalstatus only work for nvim >= 0.7
|
|
disabled_filetypes_data = { -- Filetypes to disable lualine for.
|
|
statusline = {}, -- only ignores the ft for statusline.
|
|
winbar = {}, -- only ignores the ft for winbar.
|
|
'NvimTree',
|
|
'vista'
|
|
}
|
|
end
|
|
|
|
local opt = {
|
|
options = {
|
|
icons_enabled = show_icon,
|
|
theme = 'auto', -- lualine theme
|
|
-- theme = 'ayu', -- lualine theme
|
|
-- component_separators = { left = '', right = ''},
|
|
-- section_separators = { left = '', right = ''},
|
|
component_separators = { left = '', right = ''},
|
|
section_separators = { left = '', right = ''},
|
|
|
|
always_divide_middle = false,
|
|
globalstatus = true,
|
|
disabled_filetypes = disabled_filetypes_data,
|
|
refresh = {statusline = 200}
|
|
},
|
|
sections = {
|
|
lualine_a = { 'mode' },
|
|
lualine_b = {},
|
|
lualine_c = {
|
|
{
|
|
'buffers',
|
|
mode = 2,
|
|
filetype_names = {
|
|
TelescopePrompt = 'Telescope',
|
|
dashboard = 'Dashboard',
|
|
packer = 'Packer',
|
|
fzf = 'FZF',
|
|
alpha = 'Alpha',
|
|
NvimTree = '',
|
|
vista = ''
|
|
},
|
|
symbols = {
|
|
modified = ' ●', -- Text to show when the buffer is modified
|
|
alternate_file = '', -- Text to show to identify the alternate file
|
|
directory = '', -- Text to show when the buffer is a directory
|
|
},
|
|
}
|
|
},
|
|
-- lualine_x = {'encoding', 'fileformat', 'filetype'},
|
|
lualine_x = { cocstatus },
|
|
lualine_y = {'encoding'},
|
|
lualine_z = {'location' }
|
|
},
|
|
}
|
|
|
|
require('lualine').setup(opt)
|
|
|
|
for i=1,9 do
|
|
-- :nnoremap <silent> <Leader>1 :LualineBuffersJump 1<CR>
|
|
vim.api.nvim_set_keymap('n', '<Leader>' .. i, ':LualineBuffersJump ' .. i .. '<CR>',
|
|
{ noremap = true, silent = true, nowait = true })
|
|
end
|
|
for i=10,20 do
|
|
-- :nnoremap <silent> <Leader>1 :LualineBuffersJump 1<CR>
|
|
vim.api.nvim_set_keymap('n', '<Space>' .. i, ':LualineBuffersJump ' .. i .. '<CR>',
|
|
{ noremap = true, silent = true, nowait = true })
|
|
end
|
|
|
|
end
|
|
|
|
local function nvim_treesitter_config()
|
|
if not HasPlug('nvim-treesitter') then
|
|
return
|
|
end
|
|
require('nvim-treesitter.configs').setup {
|
|
-- ensure_installed = { "c", "bash", "lua" },
|
|
sync_install = false,
|
|
auto_install = true,
|
|
-- ignore_install = { "javascript" },
|
|
highlight = {
|
|
enable = true,
|
|
additional_vim_regex_highlighting = false,
|
|
},
|
|
}
|
|
end
|
|
|
|
local function nvim_tree_config()
|
|
if not HasPlug('nvim-tree.lua') then
|
|
return
|
|
end
|
|
-- disable netrw at the very start of your init.lua (strongly advised)
|
|
vim.g.loaded_netrw = 1
|
|
vim.g.loaded_netrwPlugin = 1
|
|
|
|
-- set termguicolors to enable highlight groups
|
|
vim.opt.termguicolors = true
|
|
|
|
-- setup with some options
|
|
require("nvim-tree").setup({
|
|
sort_by = "case_sensitive",
|
|
view = {
|
|
width = 30,
|
|
mappings = {
|
|
list = {
|
|
{ key = "C-[", action = "dir_up" },
|
|
{ key = "C-]", action = "cd" },
|
|
{ key = "<C-k>", action = "toggle_file_info" },
|
|
},
|
|
},
|
|
},
|
|
renderer = {
|
|
group_empty = true,
|
|
icons = {
|
|
show = {
|
|
file = show_icon,
|
|
folder = show_icon,
|
|
folder_arrow = show_icon,
|
|
git = show_icon,
|
|
modified = show_icon,
|
|
}
|
|
}
|
|
},
|
|
filters = {
|
|
dotfiles = false,
|
|
},
|
|
actions = {
|
|
open_file = {
|
|
quit_on_open = true,
|
|
resize_window = true,
|
|
window_picker = {
|
|
exclude = {
|
|
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
|
|
buftype = { "nofile", "terminal", "help" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
vim.api.nvim_set_keymap('n', '<Leader>e', ':NvimTreeFindFileToggle<CR>', { noremap = true, silent = true })
|
|
end
|
|
|
|
if vim_version_minor >= 5 then
|
|
vim_illuminate_config()
|
|
transparent_config()
|
|
github_theme_config()
|
|
indentline_config()
|
|
which_key_config()
|
|
animate_config()
|
|
nvim_scrollbar_config()
|
|
end
|
|
if vim_version_minor >= 7 then
|
|
nvim_treesitter_config()
|
|
telescope_config()
|
|
toggleterm_config()
|
|
end
|
|
if vim_version_minor >= 8 then
|
|
nvim_tree_config()
|
|
nvim_noice_config()
|
|
end
|
|
|
|
local function late_loading()
|
|
lualine_config()
|
|
end
|
|
|
|
-- late loading
|
|
vim.api.nvim_create_autocmd({ "VimEnter" },
|
|
{ pattern = { "*" }, callback = late_loading, })
|