Skip to content

Commit

Permalink
clean config | fix (#1225) (#1226)
Browse files Browse the repository at this point in the history
  • Loading branch information
siduck committed Jun 18, 2022
1 parent 349ee96 commit 9bca3ea
Show file tree
Hide file tree
Showing 16 changed files with 69 additions and 165 deletions.
1 change: 0 additions & 1 deletion init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
require "core"
require "core.utils"
require "core.options"

vim.defer_fn(function()
Expand Down
2 changes: 2 additions & 0 deletions lua/core/init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
-- commands
vim.cmd "silent! command! NvChadUpdate lua require('nvchad').update_nvchad()"
vim.cmd "silent! command! NvChadSnapshotCreate lua require('nvchad').snap_create()"
vim.cmd "silent! command! NvChadSnapshotDelete lua require('nvchad').snap_delete()"
vim.cmd "silent! command! NvChadSnapshotCheckout lua require('nvchad').snap_checkout()"

-- autocmds
local autocmd = vim.api.nvim_create_autocmd

-- Disable statusline in dashboard
Expand Down
40 changes: 12 additions & 28 deletions lua/core/lazy_load.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
-- https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua
local lazy_load = function(tb)
-- thx to https://github.com/max397574/omega-nvim/blob/master/lua/omega/modules/ui/bufferline.lua
local M = {}

M.lazy_load = function(tb)
vim.api.nvim_create_autocmd(tb.events, {
pattern = "*",
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
Expand All @@ -21,12 +23,8 @@ local lazy_load = function(tb)
})
end

local M = {}

M.lazy_load = lazy_load

M.bufferline = function()
lazy_load {
M.lazy_load {
events = { "BufNewFile", "BufRead", "TabEnter" },
augroup_name = "BufferLineLazy",
plugins = "bufferline.nvim",
Expand All @@ -38,13 +36,13 @@ M.bufferline = function()
end

M.colorizer = function()
lazy_load {
M.lazy_load {
events = { "BufRead", "BufNewFile" },
augroup_name = "ColorizerLazy",
plugins = "nvim-colorizer.lua",

condition = function()
local items = { "#", "rgb", "hsl" }
local items = { "#", "rgb", "hsl", "rgba", "hsla" }

for _, val in ipairs(items) do
if vim.fn.search(val) ~= 0 then
Expand All @@ -56,28 +54,14 @@ M.colorizer = function()
end

-- 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

M.on_file_open = function()
lazy_load {
M.on_file_open = function(plugin_name)
M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen",
plugins = "nvim-lsp-installer indent-blankline.nvim",

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",

augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugins = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
Expand Down
24 changes: 22 additions & 2 deletions lua/core/mappings.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- n, v, i are mode names
-- n, v, i, tare mode names

This comment has been minimized.

Copy link
@budchirp

budchirp Jun 18, 2022

tare?

This comment has been minimized.

Copy link
@siduck

siduck Jun 18, 2022

Author Member

@CanKolay3499 t are , i missed the space. i'll add it in next commit

local function termcodes(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
Expand Down Expand Up @@ -147,7 +147,7 @@ M.lspconfig = {

["<leader>ra"] = {
function()
require("ui.renamer").open()
require("nvchad.ui.renamer").open()
end,
" lsp rename",
},
Expand Down Expand Up @@ -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
8 changes: 3 additions & 5 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ opt.title = true
opt.clipboard = "unnamedplus"
opt.cul = true -- cursor line

-- Indentline
-- Indenting
opt.expandtab = true
opt.shiftwidth = 2
opt.smartindent = true

-- disable tilde on end of buffer: https://github.com/neovim/neovim/pull/8546#issuecomment-643643758
opt.fillchars = { eob = " " }

opt.ignorecase = true
opt.smartcase = true
opt.mouse = "a"
Expand All @@ -53,10 +51,10 @@ opt.updatetime = 250
-- go to previous/next line with h,l,left arrow and right arrow
-- when cursor reaches end/beginning of line
opt.whichwrap:append "<>[]hl"

g.mapleader = " "

-- disable some builtin vim plugins

local default_plugins = {
"2html_plugin",
"getscript",
Expand Down Expand Up @@ -101,5 +99,5 @@ vim.schedule(function()
vim.cmd [[ silent! rsh ]]
end)

-- load user options if the file exists
-- load user options
config.options.user()
3 changes: 1 addition & 2 deletions lua/core/packer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ M.bootstrap = function()

if fn.empty(fn.glob(install_path)) > 0 then
print "Cloning packer .."

fn.system { "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path }

-- install plugins + compile their configs
Expand All @@ -23,7 +22,7 @@ M.options = {
compile_on_sync = true,
git = { clone_timeout = 6000 },
display = {
working_sym = " ",
working_sym = "",
error_sym = "",
done_sym = "",
removed_sym = "",
Expand Down
5 changes: 2 additions & 3 deletions lua/core/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ M.close_buffer = function(force)
end

force = force or not vim.bo.buflisted or vim.bo.buftype == "nofile"

-- if not force, change to prev buf and then close current
local close_cmd = force and ":bd!" or ":bp | bd" .. fn.bufnr()
vim.cmd(close_cmd)
Expand Down Expand Up @@ -150,9 +151,7 @@ M.load_override = function(default_table, plugin_name)

if type(user_table) == "function" then
user_table = user_table()
end

if type(user_table) == "table" then
elseif type(user_table) == "table" then
default_table = merge_tb("force", default_table, user_table)
else
default_table = default_table
Expand Down
25 changes: 3 additions & 22 deletions lua/plugins/configs/bufferline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ end
require("base46").load_highlight "bufferline"

vim.cmd [[
function! Toggle_theme(a,b,c,d)
lua require('base46').toggle_theme()
endfunction
Expand All @@ -25,18 +26,16 @@ local options = {
show_close_icon = false,
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 14,
max_name_length = 20,
max_prefix_length = 13,
tab_size = 20,
show_tab_indicators = true,
enforce_regular_tabs = false,
view = "multiwindow",
show_buffer_close_icons = true,
separator_style = "thin",
always_show_bufferline = true,
diagnostics = false,
themable = true,

-- top right buttons in bufferline
custom_areas = {
right = function()
return {
Expand All @@ -45,24 +44,6 @@ local options = {
}
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,
},
}

Expand Down
2 changes: 1 addition & 1 deletion lua/plugins/configs/lsp_installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 4 additions & 10 deletions lua/plugins/configs/lspconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ local utils = require "core.utils"
require "ui.lsp"

M.on_attach = function(client, bufnr)
client.server_capabilities.documentFormattingProvider = false
client.server_capabilities.documentRangeFormattingProvider = false
client.resolved_capabilities.document_formatting = false
client.resolved_capabilities.document_range_formatting = false

local lsp_mappings = utils.load_config().mappings.lspconfig
utils.load_mappings({ lsp_mappings }, { buffer = bufnr })

if client.supports_method "textDocument/signatureHelp" then
vim.api.nvim_create_autocmd({ "CursorHoldI" }, {
pattern = "*",
group = vim.api.nvim_create_augroup("LspSignature", {}),
callback = function()
vim.lsp.buf.signature_help()
end,
})
if client.server_capabilities.signatureHelpProvider then
require("nvchad.ui.signature").setup(client)
end
end

Expand Down
7 changes: 3 additions & 4 deletions lua/plugins/configs/nvimtree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ require("base46").load_highlight "nvimtree"
local options = {
filters = {
dotfiles = false,
exclude = { "custom" },
},
disable_netrw = true,
hijack_netrw = true,
open_on_setup = false,
ignore_ft_on_setup = { "alpha" },
open_on_tab = false,
hijack_cursor = true,
hijack_unnamed_buffer_when_opening = false,
update_cwd = true,
Expand Down Expand Up @@ -43,15 +42,15 @@ local options = {
indent_markers = {
enable = false,
},

icons = {
padding = " ",
symlink_arrow = "",
show = {
file = true,
folder = true,
folder_arrow = true,
git = false,
},

glyphs = {
default = "",
symlink = "",
Expand Down
5 changes: 3 additions & 2 deletions lua/plugins/configs/others.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ M.blankline = function()
buftype_exclude = { "terminal" },
show_trailing_blankline_indent = false,
show_first_indent_level = false,
show_current_context = true,
show_current_context_start = true,
}

options = load_override(options, "lukas-reineke/indent-blankline.nvim")
Expand All @@ -74,8 +76,6 @@ M.colorizer = function()
hsl_fn = false, -- CSS hsl() and hsla() functions
css = false, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB
css_fn = false, -- Enable all CSS *functions*: rgb_fn, hsl_fn

-- Available modes: foreground, background
mode = "background", -- Set the display mode.
},
}
Expand Down Expand Up @@ -146,6 +146,7 @@ M.devicons = function()

local options = { override = require("ui.icons").devicons }
options = require("core.utils").load_override(options, "kyazdani42/nvim-web-devicons")

devicons.setup(options)
end
end
Expand Down
8 changes: 5 additions & 3 deletions lua/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ local plugins = {

["lukas-reineke/indent-blankline.nvim"] = {
opt = true,
setup = function()
require("core.lazy_load").on_file_open "indent-blankline.nvim"
end,
config = function()
require("plugins.configs.others").blankline()
end,
Expand All @@ -61,9 +64,8 @@ local plugins = {

["nvim-treesitter/nvim-treesitter"] = {
module = "nvim-treesitter",
cmd = { "TSInstall", "TSUninstall" },
setup = function()
require("core.lazy_load").treesitter()
require("core.lazy_load").on_file_open "nvim-treesitter"
end,
run = ":TSUpdate",
config = function()
Expand All @@ -87,7 +89,7 @@ local plugins = {
["williamboman/nvim-lsp-installer"] = {
opt = true,
setup = function()
require("core.lazy_load").on_file_open()
require("core.lazy_load").on_file_open "nvim-lsp-installer"
end,
},

Expand Down
10 changes: 0 additions & 10 deletions lua/ui/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,3 @@ win.default_opts = function(options)
opts.border = "single"
return opts
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,
})
Loading

6 comments on commit 9bca3ea

@siduck
Copy link
Member Author

@siduck siduck commented on 9bca3ea Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

enabled blankline's context option and we can make it look like vim-matchup's match highlight and press <leader>bc to jump to the context's start line

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines maybe not block at 0.7,why rollback ? ,and why remove multiple lsp clients display

client.server_capabilities.documentFormattingProvider = false
 client.server_capabilities.documentRangeFormattingProvider = false

@siduck
Copy link
Member Author

@siduck siduck commented on 9bca3ea Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these lines maybe not block at 0.7,why rollback ? ,and why remove multiple lsp clients display

client.server_capabilities.documentFormattingProvider = false
 client.server_capabilities.documentRangeFormattingProvider = false

dac05df#commitcomment-76384097

And multiple lsp clients display cluttered the statusline, user can already see it in LspInfo

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok ,i think you can remove the tow lines, let the user decide to choose which formatter

 client.resolved_capabilities.document_formatting = false
  client.resolved_capabilities.document_range_formatting = false

@siduck
Copy link
Member Author

@siduck siduck commented on 9bca3ea Jun 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomasky many use null-ls or other formatters here and its annoying to add that code in every lspserver's setup table to disable their inbuilt formatter so i made that as default behaviour

@tomasky
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But many users use neovim 0.8 dev,like me , although I can handle it myself

Please sign in to comment.