clean config | fix (#1225) (#1226)

This commit is contained in:
siduck 2022-06-18 09:57:17 +05:30
parent 349ee96a20
commit 9bca3eacae
16 changed files with 69 additions and 165 deletions

View File

@ -1,5 +1,4 @@
require "core" require "core"
require "core.utils"
require "core.options" require "core.options"
vim.defer_fn(function() vim.defer_fn(function()

View File

@ -1,8 +1,10 @@
-- commands
vim.cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()" vim.cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()"
vim.cmd "silent! command! NvChadSnapshotCreate lua require('nvchad').snap_create()" vim.cmd "silent! command! NvChadSnapshotCreate lua require('nvchad').snap_create()"
vim.cmd "silent! command! NvChadSnapshotDelete lua require('nvchad').snap_delete()" vim.cmd "silent! command! NvChadSnapshotDelete lua require('nvchad').snap_delete()"
vim.cmd "silent! command! NvChadSnapshotCheckout lua require('nvchad').snap_checkout()" vim.cmd "silent! command! NvChadSnapshotCheckout lua require('nvchad').snap_checkout()"
-- autocmds
local autocmd = vim.api.nvim_create_autocmd local autocmd = vim.api.nvim_create_autocmd
-- Disable statusline in dashboard -- Disable statusline in dashboard

View File

@ -1,5 +1,7 @@
-- https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua -- thx to https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua
local lazy_load = function(tb) local M = {}
M.lazy_load = function(tb)
vim.api.nvim_create_autocmd(tb.events, { vim.api.nvim_create_autocmd(tb.events, {
pattern = "*", pattern = "*",
group = vim.api.nvim_create_augroup(tb.augroup_name, {}), group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
@ -21,12 +23,8 @@ local lazy_load = function(tb)
}) })
end end
local M = {}
M.lazy_load = lazy_load
M.bufferline = function() M.bufferline = function()
lazy_load { M.lazy_load {
events = { "BufNewFile", "BufRead", "TabEnter" }, events = { "BufNewFile", "BufRead", "TabEnter" },
augroup_name = "BufferLineLazy", augroup_name = "BufferLineLazy",
plugins = "bufferline.nvim", plugins = "bufferline.nvim",
@ -38,13 +36,13 @@ M.bufferline = function()
end end
M.colorizer = function() M.colorizer = function()
lazy_load { M.lazy_load {
events = { "BufRead", "BufNewFile" }, events = { "BufRead", "BufNewFile" },
augroup_name = "ColorizerLazy", augroup_name = "ColorizerLazy",
plugins = "nvim-colorizer.lua", plugins = "nvim-colorizer.lua",
condition = function() condition = function()
local items = { "#", "rgb", "hsl" } local items = { "#", "rgb", "hsl", "rgba", "hsla" }
for _, val in ipairs(items) do for _, val in ipairs(items) do
if vim.fn.search(val) ~= 0 then if vim.fn.search(val) ~= 0 then
@ -56,28 +54,14 @@ M.colorizer = function()
end end
-- load certain plugins only when there's a file opened in the buffer -- load certain plugins only when there's a file opened in the buffer
-- if "nvim-file" is executed -> load the plugin after nvim gui loads -- if "nvim filename" is executed -> load the plugin after nvim gui loads
-- This gives an instant preview of nvim with the file opened -- This gives an instant preview of nvim with the file opened
M.on_file_open = function() M.on_file_open = function(plugin_name)
lazy_load { M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" }, events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen", augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugins = "nvim-lsp-installer indent-blankline.nvim", plugins = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end
M.treesitter = function()
lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "Treesitter_lazy",
plugins = "nvim-treesitter",
condition = function() condition = function()
local file = vim.fn.expand "%" local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= "" return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""

View File

@ -1,4 +1,4 @@
-- n, v, i are mode names -- n, v, i, tare mode names
local function termcodes(str) local function termcodes(str)
return vim.api.nvim_replace_termcodes(str, true, true, true) return vim.api.nvim_replace_termcodes(str, true, true, true)
@ -147,7 +147,7 @@ M.lspconfig = {
["<leader>ra"] = { ["<leader>ra"] = {
function() function()
require("ui.renamer").open() require("nvchad.ui.renamer").open()
end, end,
" lsp rename", " lsp rename",
}, },
@ -342,4 +342,24 @@ M.whichkey = {
}, },
} }
M.blankline = {
n = {
["<leader>bc"] = {
function()
local ok, start = require("indent_blankline.utils").get_current_context(
vim.g.indent_blankline_context_patterns,
vim.g.indent_blankline_use_treesitter_scope
)
if ok then
vim.api.nvim_win_set_cursor(vim.api.nvim_get_current_win(), { start, 0 })
vim.cmd [[normal! _]]
end
end,
" Jump to current_context",
},
},
}
return M return M

View File

@ -19,14 +19,12 @@ opt.title = true
opt.clipboard = "unnamedplus" opt.clipboard = "unnamedplus"
opt.cul = true -- cursor line opt.cul = true -- cursor line
-- Indentline -- Indenting
opt.expandtab = true opt.expandtab = true
opt.shiftwidth = 2 opt.shiftwidth = 2
opt.smartindent = true opt.smartindent = true
-- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758
opt.fillchars = { eob = " " } opt.fillchars = { eob = " " }
opt.ignorecase = true opt.ignorecase = true
opt.smartcase = true opt.smartcase = true
opt.mouse = "a" opt.mouse = "a"
@ -53,10 +51,10 @@ opt.updatetime = 250
-- go to previous/next line with h,l,left arrow and right arrow -- go to previous/next line with h,l,left arrow and right arrow
-- when cursor reaches end/beginning of line -- when cursor reaches end/beginning of line
opt.whichwrap:append "<>[]hl" opt.whichwrap:append "<>[]hl"
g.mapleader = " " g.mapleader = " "
-- disable some builtin vim plugins -- disable some builtin vim plugins
local default_plugins = { local default_plugins = {
"2html_plugin", "2html_plugin",
"getscript", "getscript",
@ -101,5 +99,5 @@ vim.schedule(function()
vim.cmd [[ silent! rsh ]] vim.cmd [[ silent! rsh ]]
end) end)
-- load user options if the file exists -- load user options
config.options.user() config.options.user()

View File

@ -8,7 +8,6 @@ M.bootstrap = function()
if fn.empty(fn.glob(install_path)) > 0 then if fn.empty(fn.glob(install_path)) > 0 then
print "Cloning packer .." print "Cloning packer .."
fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path } fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }
-- install plugins + compile their configs -- install plugins + compile their configs
@ -23,7 +22,7 @@ M.options = {
compile_on_sync = true, compile_on_sync = true,
git = { clone_timeout = 6000 }, git = { clone_timeout = 6000 },
display = { display = {
working_sym = " ", working_sym = "",
error_sym = "", error_sym = "",
done_sym = "", done_sym = "",
removed_sym = "", removed_sym = "",

View File

@ -21,6 +21,7 @@ M.close_buffer = function(force)
end end
force = force or not vim.bo.buflisted or vim.bo.buftype == "nofile" force = force or not vim.bo.buflisted or vim.bo.buftype == "nofile"
-- if not force, change to prev buf and then close current -- if not force, change to prev buf and then close current
local close_cmd = force and ":bd!" or ":bp | bd" .. fn.bufnr() local close_cmd = force and ":bd!" or ":bp | bd" .. fn.bufnr()
vim.cmd(close_cmd) vim.cmd(close_cmd)
@ -150,9 +151,7 @@ M.load_override = function(default_table, plugin_name)
if type(user_table) == "function" then if type(user_table) == "function" then
user_table = user_table() user_table = user_table()
end elseif type(user_table) == "table" then
if type(user_table) == "table" then
default_table = merge_tb("force", default_table, user_table) default_table = merge_tb("force", default_table, user_table)
else else
default_table = default_table default_table = default_table

View File

@ -7,6 +7,7 @@ end
require("base46").load_highlight "bufferline" require("base46").load_highlight "bufferline"
vim.cmd [[ vim.cmd [[
function! Toggle_theme(a,b,c,d) function! Toggle_theme(a,b,c,d)
lua require('base46').toggle_theme() lua require('base46').toggle_theme()
endfunction endfunction
@ -25,18 +26,16 @@ local options = {
show_close_icon = false, show_close_icon = false,
left_trunc_marker = "", left_trunc_marker = "",
right_trunc_marker = "", right_trunc_marker = "",
max_name_length = 14, max_name_length = 20,
max_prefix_length = 13, max_prefix_length = 13,
tab_size = 20, tab_size = 20,
show_tab_indicators = true, show_tab_indicators = true,
enforce_regular_tabs = false, enforce_regular_tabs = false,
view = "multiwindow",
show_buffer_close_icons = true, show_buffer_close_icons = true,
separator_style = "thin", separator_style = "thin",
always_show_bufferline = true,
diagnostics = false,
themable = true, themable = true,
-- top right buttons in bufferline
custom_areas = { custom_areas = {
right = function() right = function()
return { return {
@ -45,24 +44,6 @@ local options = {
} }
end, end,
}, },
custom_filter = function(buf_number)
-- Func to filter out our managed/persistent split terms
local present_type, type = pcall(function()
return vim.api.nvim_buf_get_var(buf_number, "term_type")
end)
if present_type then
if type == "vert" then
return false
elseif type == "hori" then
return false
end
return true
end
return true
end,
}, },
} }

View File

@ -28,7 +28,7 @@ local options = {
}, },
}, },
max_concurrent_installers = 20, max_concurrent_installers = 10,
} }
options = require("core.utils").load_override(options, "williamboman/nvim-lsp-installer") options = require("core.utils").load_override(options, "williamboman/nvim-lsp-installer")

View File

@ -12,20 +12,14 @@ local utils = require "core.utils"
require "ui.lsp" require "ui.lsp"
M.on_attach = function(client, bufnr) M.on_attach = function(client, bufnr)
client.server_capabilities.documentFormattingProvider = false client.resolved_capabilities.document_formatting = false
client.server_capabilities.documentRangeFormattingProvider = false client.resolved_capabilities.document_range_formatting = false
local lsp_mappings = utils.load_config().mappings.lspconfig local lsp_mappings = utils.load_config().mappings.lspconfig
utils.load_mappings({ lsp_mappings }, { buffer = bufnr }) utils.load_mappings({ lsp_mappings }, { buffer = bufnr })
if client.supports_method "textDocument/signatureHelp" then if client.server_capabilities.signatureHelpProvider then
vim.api.nvim_create_autocmd({ "CursorHoldI" }, { require("nvchad.ui.signature").setup(client)
pattern = "*",
group = vim.api.nvim_create_augroup("LspSignature", {}),
callback = function()
vim.lsp.buf.signature_help()
end,
})
end end
end end

View File

@ -9,12 +9,11 @@ require("base46").load_highlight "nvimtree"
local options = { local options = {
filters = { filters = {
dotfiles = false, dotfiles = false,
exclude = { "custom" },
}, },
disable_netrw = true, disable_netrw = true,
hijack_netrw = true, hijack_netrw = true,
open_on_setup = false,
ignore_ft_on_setup = { "alpha" }, ignore_ft_on_setup = { "alpha" },
open_on_tab = false,
hijack_cursor = true, hijack_cursor = true,
hijack_unnamed_buffer_when_opening = false, hijack_unnamed_buffer_when_opening = false,
update_cwd = true, update_cwd = true,
@ -43,15 +42,15 @@ local options = {
indent_markers = { indent_markers = {
enable = false, enable = false,
}, },
icons = { icons = {
padding = " ",
symlink_arrow = "",
show = { show = {
file = true, file = true,
folder = true, folder = true,
folder_arrow = true, folder_arrow = true,
git = false, git = false,
}, },
glyphs = { glyphs = {
default = "", default = "",
symlink = "", symlink = "",

View File

@ -48,6 +48,8 @@ M.blankline = function()
buftype_exclude = { "terminal" }, buftype_exclude = { "terminal" },
show_trailing_blankline_indent = false, show_trailing_blankline_indent = false,
show_first_indent_level = false, show_first_indent_level = false,
show_current_context = true,
show_current_context_start = true,
} }
options = load_override(options, "lukas-reineke/indent-blankline.nvim") options = load_override(options, "lukas-reineke/indent-blankline.nvim")
@ -74,8 +76,6 @@ M.colorizer = function()
hsl_fn = false, -- CSS hsl() and hsla() functions hsl_fn = false, -- CSS hsl() and hsla() functions
css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn
-- Available modes: foreground, background
mode = "background", -- Set the display mode. mode = "background", -- Set the display mode.
}, },
} }
@ -146,6 +146,7 @@ M.devicons = function()
local options = { override = require("ui.icons").devicons } local options = { override = require("ui.icons").devicons }
options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons") options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons")
devicons.setup(options) devicons.setup(options)
end end
end end

View File

@ -44,6 +44,9 @@ local plugins = {
["lukas-reineke/indent-blankline.nvim"] = { ["lukas-reineke/indent-blankline.nvim"] = {
opt = true, opt = true,
setup = function()
require("core.lazy_load").on_file_open "indent-blankline.nvim"
end,
config = function() config = function()
require("plugins.configs.others").blankline() require("plugins.configs.others").blankline()
end, end,
@ -61,9 +64,8 @@ local plugins = {
["nvim-treesitter/nvim-treesitter"] = { ["nvim-treesitter/nvim-treesitter"] = {
module = "nvim-treesitter", module = "nvim-treesitter",
cmd = { "TSInstall", "TSUninstall" },
setup = function() setup = function()
require("core.lazy_load").treesitter() require("core.lazy_load").on_file_open "nvim-treesitter"
end, end,
run = ":TSUpdate", run = ":TSUpdate",
config = function() config = function()
@ -87,7 +89,7 @@ local plugins = {
["williamboman/nvim-lsp-installer"] = { ["williamboman/nvim-lsp-installer"] = {
opt = true, opt = true,
setup = function() setup = function()
require("core.lazy_load").on_file_open() require("core.lazy_load").on_file_open "nvim-lsp-installer"
end, end,
}, },

View File

@ -45,13 +45,3 @@ win.default_opts = function(options)
opts.border = "single" opts.border = "single"
return opts return opts
end end
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
border = "single",
silent = true,
focusable = false,
close_events = { "InsertCharPre", "CursorMoved" },
anchor = "SW",
relative = "cursor",
row = -1,
})

View File

@ -1,60 +0,0 @@
-- credits to @Malace : https://www.reddit.com/r/neovim/comments/ql4iuj/rename_hover_including_window_title_and/
-- This is modified version of the above snippet
local M = {}
M.open = function()
local currName = vim.fn.expand "<cword>" .. " "
local win = require("plenary.popup").create(currName, {
title = "Renamer",
style = "minimal",
borderchars = { "", "", "", "", "", "", "", "" },
relative = "cursor",
borderhighlight = "RenamerBorder",
titlehighlight = "RenamerTitle",
focusable = true,
width = 25,
height = 1,
line = "cursor+2",
col = "cursor-1",
})
local map_opts = { noremap = true, silent = true }
vim.cmd "normal w"
vim.cmd "startinsert"
vim.api.nvim_buf_set_keymap(0, "i", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts)
vim.api.nvim_buf_set_keymap(0, "n", "<Esc>", "<cmd>stopinsert | q!<CR>", map_opts)
vim.api.nvim_buf_set_keymap(
0,
"i",
"<CR>",
"<cmd>stopinsert | lua require'ui.renamer'.apply(" .. currName .. "," .. win .. ")<CR>",
map_opts
)
vim.api.nvim_buf_set_keymap(
0,
"n",
"<CR>",
"<cmd>stopinsert | lua require'ui.renamer'.apply(" .. currName .. "," .. win .. ")<CR>",
map_opts
)
end
M.apply = function(curr, win)
local newName = vim.trim(vim.fn.getline ".")
vim.api.nvim_win_close(win, true)
if #newName > 0 and newName ~= curr then
local params = vim.lsp.util.make_position_params()
params.newName = newName
vim.lsp.buf_request(0, "textDocument/rename", params)
end
end
return M

View File

@ -149,18 +149,14 @@ end
M.LSP_status = function() M.LSP_status = function()
local clients = vim.lsp.get_active_clients() local clients = vim.lsp.get_active_clients()
local names = {} local name = false
for _, client in ipairs(clients) do for _, client in ipairs(clients) do
if client.attached_buffers[vim.api.nvim_get_current_buf()] then if client.attached_buffers[vim.api.nvim_get_current_buf()] then
table.insert(names, client.name) name = client.name
break
end end
end end
local name = false
if next(names) then
name = table.concat(names, '|')
end
local content = name and "  LSP ~ " .. name .. " " or false local content = name and "  LSP ~ " .. name .. " " or false
return content and ("%#St_LspStatus#" .. content) or "" return content and ("%#St_LspStatus#" .. content) or ""
end end
@ -174,19 +170,19 @@ end
M.cursor_position = function() M.cursor_position = function()
local left_sep = "%#St_pos_sep#" .. sep_l local left_sep = "%#St_pos_sep#" .. sep_l
local icon = "%#St_pos_icon#" .. " " local icon = "%#St_pos_icon#" .. " "
local current_line = fn.line "." local current_line = fn.line "."
local total_line = fn.line "$" local total_line = fn.line "$"
local text = math.modf((current_line / total_line) * 100) .. tostring "%%" local text = math.modf((current_line / total_line) * 100) .. tostring "%%"
if current_line == 1 then if current_line == 1 then
text = "Top " text = "Top"
elseif current_line == total_line then elseif current_line == total_line then
text = "Bot " text = "Bot"
end end
return left_sep .. icon .. "%#St_pos_text#" .. " " .. text return left_sep .. icon .. "%#St_pos_text#" .. " " .. text .. " "
end end
M.run = function() M.run = function()