set shiftwidth to 2 | format all files

big thanks to @ghifarit53
This commit is contained in:
siduck 2022-07-22 16:00:00 +00:00
parent ce027efbe9
commit 6f0aa376a8
22 changed files with 1341 additions and 1340 deletions

View file

@ -3,34 +3,34 @@
local M = {}
M.options = {
-- load your options here or load module with options
user = function() end,
-- load your options here or load module with options
user = function() end,
nvChad = {
update_url = "https://github.com/NvChad/NvChad",
update_branch = "main",
},
nvChad = {
update_url = "https://github.com/NvChad/NvChad",
update_branch = "main",
},
}
M.ui = {
-- hl = highlights
hl_add = {},
hl_override = {},
changed_themes = {},
theme_toggle = { "onedark", "one_light" },
theme = "onedark", -- default theme
transparency = false,
-- hl = highlights
hl_add = {},
hl_override = {},
changed_themes = {},
theme_toggle = { "onedark", "one_light" },
theme = "onedark", -- default theme
transparency = false,
}
M.plugins = {
override = {},
remove = {},
user = {},
options = {
lspconfig = {
setup_lspconf = "", -- path of lspconfig file
},
},
override = {},
remove = {},
user = {},
options = {
lspconfig = {
setup_lspconf = "", -- path of lspconfig file
},
},
}
-- check core.mappings for table structure

View file

@ -10,38 +10,38 @@ local api = vim.api
-- dont list quickfix buffers
autocmd("FileType", {
pattern = "qf",
callback = function()
vim.opt_local.buflisted = false
end,
pattern = "qf",
callback = function()
vim.opt_local.buflisted = false
end,
})
-- wrap the PackerSync command to warn people before using it in NvChadSnapshots
autocmd("VimEnter", {
callback = function()
vim.cmd "command! -nargs=* -complete=customlist,v:lua.require'packer'.plugin_complete PackerSync lua require('core.utils').packer_sync(<f-args>)"
end,
callback = function()
vim.cmd "command! -nargs=* -complete=customlist,v:lua.require'packer'.plugin_complete PackerSync lua require('core.utils').packer_sync(<f-args>)"
end,
})
-- Disable statusline in dashboard
autocmd("FileType", {
pattern = "alpha",
callback = function()
vim.opt.laststatus = 0
end,
pattern = "alpha",
callback = function()
vim.opt.laststatus = 0
end,
})
autocmd("BufUnload", {
buffer = 0,
callback = function()
vim.opt.laststatus = 3
end,
buffer = 0,
callback = function()
vim.opt.laststatus = 3
end,
})
-- Don't auto commenting new lines
autocmd("BufEnter", {
pattern = "*",
command = "set fo-=c fo-=r fo-=o",
pattern = "*",
command = "set fo-=c fo-=r fo-=o",
})
-- store listed buffers in tab local var
@ -50,34 +50,34 @@ vim.t.bufs = vim.api.nvim_list_bufs()
-- autocmds for tabufline -> store bufnrs on bufadd, bufenter events
-- thx to https://github.com/ii14 & stores buffer per tab -> table
autocmd({ "BufAdd", "BufEnter" }, {
callback = function(args)
if vim.t.bufs == nil then
vim.t.bufs = { args.buf }
else
local bufs = vim.t.bufs
callback = function(args)
if vim.t.bufs == nil then
vim.t.bufs = { args.buf }
else
local bufs = vim.t.bufs
-- check for duplicates
if not vim.tbl_contains(bufs, args.buf) and (args.event == "BufAdd" or vim.bo[args.buf].buflisted) then
table.insert(bufs, args.buf)
vim.t.bufs = bufs
end
-- check for duplicates
if not vim.tbl_contains(bufs, args.buf) and (args.event == "BufAdd" or vim.bo[args.buf].buflisted) then
table.insert(bufs, args.buf)
vim.t.bufs = bufs
end
end,
end
end,
})
autocmd("BufDelete", {
callback = function(args)
for _, tab in ipairs(api.nvim_list_tabpages()) do
local bufs = vim.t[tab].bufs
if bufs then
for i, bufnr in ipairs(bufs) do
if bufnr == args.buf then
table.remove(bufs, i)
vim.t[tab].bufs = bufs
break
end
end
end
callback = function(args)
for _, tab in ipairs(api.nvim_list_tabpages()) do
local bufs = vim.t[tab].bufs
if bufs then
for i, bufnr in ipairs(bufs) do
if bufnr == args.buf then
table.remove(bufs, i)
vim.t[tab].bufs = bufs
break
end
end
end
end,
end
end,
})

View file

@ -4,37 +4,37 @@ local autocmd = vim.api.nvim_create_autocmd
-- This must be used for plugins that need to be loaded just after a file
-- ex : treesitter, lspconfig etc
M.lazy_load = function(tb)
autocmd(tb.events, {
pattern = "*",
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
callback = function()
if tb.condition() then
vim.api.nvim_del_augroup_by_name(tb.augroup_name)
autocmd(tb.events, {
pattern = "*",
group = vim.api.nvim_create_augroup(tb.augroup_name, {}),
callback = function()
if tb.condition() then
vim.api.nvim_del_augroup_by_name(tb.augroup_name)
-- dont defer for treesitter as it will show slow highlighting
-- This deferring only happens only when we do "nvim filename"
if tb.plugins ~= "nvim-treesitter" then
vim.defer_fn(function()
vim.cmd("PackerLoad " .. tb.plugins)
end, 0)
else
vim.cmd("PackerLoad " .. tb.plugins)
end
end
end,
})
-- dont defer for treesitter as it will show slow highlighting
-- This deferring only happens only when we do "nvim filename"
if tb.plugins ~= "nvim-treesitter" then
vim.defer_fn(function()
vim.cmd("PackerLoad " .. tb.plugins)
end, 0)
else
vim.cmd("PackerLoad " .. tb.plugins)
end
end
end,
})
end
M.colorizer = function()
M.lazy_load {
events = { "BufRead", "BufNewFile" },
augroup_name = "ColorizerLazy",
plugins = "nvim-colorizer.lua",
M.lazy_load {
events = { "BufRead", "BufNewFile" },
augroup_name = "ColorizerLazy",
plugins = "nvim-colorizer.lua",
condition = function()
return true
end,
}
condition = function()
return true
end,
}
end
-- load certain plugins only when there's a file opened in the buffer
@ -42,65 +42,65 @@ end
-- This gives an instant preview of nvim with the file opened
M.on_file_open = function(plugin_name)
M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugins = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
M.lazy_load {
events = { "BufRead", "BufWinEnter", "BufNewFile" },
augroup_name = "BeLazyOnFileOpen" .. plugin_name,
plugins = plugin_name,
condition = function()
local file = vim.fn.expand "%"
return file ~= "NvimTree_1" and file ~= "[packer]" and file ~= ""
end,
}
end
-- lspinstaller & lspconfig cmds for lazyloading
M.lsp_cmds = {
"LspInfo",
"LspStart",
"LspRestart",
"LspStop",
"LspInstall",
"LspUnInstall",
"LspUnInstallAll",
"LspInstall",
"LspInstallInfo",
"LspInstallLog",
"LspLog",
"LspPrintInstalled",
"LspInfo",
"LspStart",
"LspRestart",
"LspStop",
"LspInstall",
"LspUnInstall",
"LspUnInstallAll",
"LspInstall",
"LspInstallInfo",
"LspInstallLog",
"LspLog",
"LspPrintInstalled",
}
M.treesitter_cmds = {
"TSInstall",
"TSBufEnable",
"TSBufDisable",
"TSEnable",
"TSDisable",
"TSModuleInfo",
"TSInstall",
"TSBufEnable",
"TSBufDisable",
"TSEnable",
"TSDisable",
"TSModuleInfo",
}
M.gitsigns = function()
-- taken from https://github.com/max397574
autocmd({ "BufRead" }, {
callback = function()
local function onexit(code, _)
if code == 0 then
vim.schedule(function()
require("packer").loader "gitsigns.nvim"
end)
end
end
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
if lines ~= { "" } then
vim.loop.spawn("git", {
args = {
"ls-files",
"--error-unmatch",
vim.fn.expand "%:p:h",
},
}, onexit)
end
end,
})
-- taken from https://github.com/max397574
autocmd({ "BufRead" }, {
callback = function()
local function onexit(code, _)
if code == 0 then
vim.schedule(function()
require("packer").loader "gitsigns.nvim"
end)
end
end
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
if lines ~= { "" } then
vim.loop.spawn("git", {
args = {
"ls-files",
"--error-unmatch",
vim.fn.expand "%:p:h",
},
}, onexit)
end
end,
})
end
return M

View file

@ -1,387 +1,387 @@
-- n, v, i, t = mode names
local function termcodes(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
local M = {}
M.general = {
i = {
i = {
-- go to beginning and end
["<C-b>"] = { "<ESC>^i", "論 beginning of line" },
["<C-e>"] = { "<End>", "壟 end of line" },
-- go to beginning and end
["<C-b>"] = { "<ESC>^i", "論 beginning of line" },
["<C-e>"] = { "<End>", "壟 end of line" },
-- navigate within insert mode
["<C-h>"] = { "<Left>", " move left" },
["<C-l>"] = { "<Right>", " move right" },
["<C-j>"] = { "<Down>", " move down" },
["<C-k>"] = { "<Up>", " move up" },
},
-- navigate within insert mode
["<C-h>"] = { "<Left>", " move left" },
["<C-l>"] = { "<Right>", " move right" },
["<C-j>"] = { "<Down>", " move down" },
["<C-k>"] = { "<Up>", " move up" },
},
n = {
n = {
["<ESC>"] = { "<cmd> noh <CR>", " no highlight" },
["<ESC>"] = { "<cmd> noh <CR>", " no highlight" },
-- switch between windows
["<C-h>"] = { "<C-w>h", " window left" },
["<C-l>"] = { "<C-w>l", " window right" },
["<C-j>"] = { "<C-w>j", " window down" },
["<C-k>"] = { "<C-w>k", " window up" },
-- switch between windows
["<C-h>"] = { "<C-w>h", " window left" },
["<C-l>"] = { "<C-w>l", " window right" },
["<C-j>"] = { "<C-w>j", " window down" },
["<C-k>"] = { "<C-w>k", " window up" },
-- save
["<C-s>"] = { "<cmd> w <CR>", "﬚ save file" },
-- save
["<C-s>"] = { "<cmd> w <CR>", "﬚ save file" },
-- Copy all
["<C-c>"] = { "<cmd> %y+ <CR>", " copy whole file" },
-- Copy all
["<C-c>"] = { "<cmd> %y+ <CR>", " copy whole file" },
-- line numbers
["<leader>n"] = { "<cmd> set nu! <CR>", " toggle line number" },
["<leader>rn"] = { "<cmd> set rnu! <CR>", " toggle relative number" },
-- line numbers
["<leader>n"] = { "<cmd> set nu! <CR>", " toggle line number" },
["<leader>rn"] = { "<cmd> set rnu! <CR>", " toggle relative number" },
-- update nvchad
["<leader>uu"] = { "<cmd> :NvChadUpdate <CR>", " update nvchad" },
-- update nvchad
["<leader>uu"] = { "<cmd> :NvChadUpdate <CR>", " update nvchad" },
["<leader>tt"] = {
function()
require("base46").toggle_theme()
end,
["<leader>tt"] = {
function()
require("base46").toggle_theme()
end,
" toggle theme",
},
" toggle theme",
},
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
},
-- Allow moving the cursor through wrapped lines with j, k, <Up> and <Down>
-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/
-- empty mode is same as using <cmd> :map
-- also don't use g[j|k] when in operator pending mode, so it doesn't alter d, y or c behaviour
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
},
t = {
["<C-x>"] = { termcodes "<C-\\><C-N>", " escape terminal mode" },
},
t = {
["<C-x>"] = { termcodes "<C-\\><C-N>", " escape terminal mode" },
},
v = {
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
-- Don't copy the replaced text after pasting in visual mode
-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste
["p"] = { 'p:let @+=@0<CR>:let @"=@0<CR>', opts = { silent = true } },
},
v = {
["j"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
["k"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Up>"] = { 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', opts = { expr = true } },
["<Down>"] = { 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', opts = { expr = true } },
-- Don't copy the replaced text after pasting in visual mode
-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#Alternative_mapping_for_paste
["p"] = { 'p:let @+=@0<CR>:let @"=@0<CR>', opts = { silent = true } },
},
}
M.tabufline = {
n = {
-- new buffer
["<S-b>"] = { "<cmd> enew <CR>", "烙 new buffer" },
n = {
-- new buffer
["<S-b>"] = { "<cmd> enew <CR>", "烙 new buffer" },
-- cycle through buffers
["<TAB>"] = { "<cmd> Tbufnext <CR>", " goto next buffer" },
["<S-Tab>"] = { "<cmd> Tbufprev <CR> ", " goto prev buffer" },
-- cycle through buffers
["<TAB>"] = { "<cmd> Tbufnext <CR>", " goto next buffer" },
["<S-Tab>"] = { "<cmd> Tbufprev <CR> ", " goto prev buffer" },
-- cycle through tabs
["<leader>tp"] = { "<cmd> tabprevious <CR>", " goto next tab" },
["<leader>tn"] = { "<cmd> tabnext <CR> ", " goto prev tab" },
-- cycle through tabs
["<leader>tp"] = { "<cmd> tabprevious <CR>", " goto next tab" },
["<leader>tn"] = { "<cmd> tabnext <CR> ", " goto prev tab" },
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
require("core.utils").close_buffer()
end,
" close buffer",
},
},
-- close buffer + hide terminal buffer
["<leader>x"] = {
function()
require("core.utils").close_buffer()
end,
" close buffer",
},
},
}
M.comment = {
-- toggle comment in both modes
n = {
["<leader>/"] = {
function()
require("Comment.api").toggle_current_linewise()
end,
-- toggle comment in both modes
n = {
["<leader>/"] = {
function()
require("Comment.api").toggle_current_linewise()
end,
"蘒 toggle comment",
},
},
"蘒 toggle comment",
},
},
v = {
["<leader>/"] = {
"<ESC><cmd>lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>",
"蘒 toggle comment",
},
},
v = {
["<leader>/"] = {
"<ESC><cmd>lua require('Comment.api').toggle_linewise_op(vim.fn.visualmode())<CR>",
"蘒 toggle comment",
},
},
}
M.lspconfig = {
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
-- See `<cmd> :help vim.lsp.*` for documentation on any of the below functions
n = {
["gD"] = {
function()
vim.lsp.buf.declaration()
end,
" lsp declaration",
},
n = {
["gD"] = {
function()
vim.lsp.buf.declaration()
end,
" lsp declaration",
},
["gd"] = {
function()
vim.lsp.buf.definition()
end,
" lsp definition",
},
["gd"] = {
function()
vim.lsp.buf.definition()
end,
" lsp definition",
},
["K"] = {
function()
vim.lsp.buf.hover()
end,
" lsp hover",
},
["K"] = {
function()
vim.lsp.buf.hover()
end,
" lsp hover",
},
["gi"] = {
function()
vim.lsp.buf.implementation()
end,
" lsp implementation",
},
["gi"] = {
function()
vim.lsp.buf.implementation()
end,
" lsp implementation",
},
["<leader>ls"] = {
function()
vim.lsp.buf.signature_help()
end,
" lsp signature_help",
},
["<leader>ls"] = {
function()
vim.lsp.buf.signature_help()
end,
" lsp signature_help",
},
["<leader>D"] = {
function()
vim.lsp.buf.type_definition()
end,
" lsp definition type",
},
["<leader>D"] = {
function()
vim.lsp.buf.type_definition()
end,
" lsp definition type",
},
["<leader>ra"] = {
function()
require("nvchad_ui.renamer").open()
end,
" lsp rename",
},
["<leader>ra"] = {
function()
require("nvchad_ui.renamer").open()
end,
" lsp rename",
},
["<leader>ca"] = {
function()
vim.lsp.buf.code_action()
end,
" lsp code_action",
},
["<leader>ca"] = {
function()
vim.lsp.buf.code_action()
end,
" lsp code_action",
},
["gr"] = {
function()
vim.lsp.buf.references()
end,
" lsp references",
},
["gr"] = {
function()
vim.lsp.buf.references()
end,
" lsp references",
},
["<leader>f"] = {
function()
vim.diagnostic.open_float()
end,
" floating diagnostic",
},
["<leader>f"] = {
function()
vim.diagnostic.open_float()
end,
" floating diagnostic",
},
["[d"] = {
function()
vim.diagnostic.goto_prev()
end,
" goto prev",
},
["[d"] = {
function()
vim.diagnostic.goto_prev()
end,
" goto prev",
},
["d]"] = {
function()
vim.diagnostic.goto_next()
end,
" goto_next",
},
["d]"] = {
function()
vim.diagnostic.goto_next()
end,
" goto_next",
},
["<leader>q"] = {
function()
vim.diagnostic.setloclist()
end,
" diagnostic setloclist",
},
["<leader>q"] = {
function()
vim.diagnostic.setloclist()
end,
" diagnostic setloclist",
},
["<leader>fm"] = {
function()
vim.lsp.buf.formatting()
end,
" lsp formatting",
},
["<leader>fm"] = {
function()
vim.lsp.buf.formatting()
end,
" lsp formatting",
},
["<leader>wa"] = {
function()
vim.lsp.buf.add_workspace_folder()
end,
" add workspace folder",
},
["<leader>wa"] = {
function()
vim.lsp.buf.add_workspace_folder()
end,
" add workspace folder",
},
["<leader>wr"] = {
function()
vim.lsp.buf.remove_workspace_folder()
end,
" remove workspace folder",
},
["<leader>wr"] = {
function()
vim.lsp.buf.remove_workspace_folder()
end,
" remove workspace folder",
},
["<leader>wl"] = {
function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end,
" list workspace folders",
},
},
["<leader>wl"] = {
function()
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end,
" list workspace folders",
},
},
}
M.nvimtree = {
n = {
-- toggle
["<C-n>"] = { "<cmd> NvimTreeToggle <CR>", " toggle nvimtree" },
n = {
-- toggle
["<C-n>"] = { "<cmd> NvimTreeToggle <CR>", " toggle nvimtree" },
-- focus
["<leader>e"] = { "<cmd> NvimTreeFocus <CR>", " focus nvimtree" },
},
-- focus
["<leader>e"] = { "<cmd> NvimTreeFocus <CR>", " focus nvimtree" },
},
}
M.telescope = {
n = {
-- find
["<leader>ff"] = { "<cmd> Telescope find_files <CR>", " find files" },
["<leader>fa"] = { "<cmd> Telescope find_files follow=true no_ignore=true hidden=true <CR>", " find all" },
["<leader>fw"] = { "<cmd> Telescope live_grep <CR>", " live grep" },
["<leader>fb"] = { "<cmd> Telescope buffers <CR>", " find buffers" },
["<leader>fh"] = { "<cmd> Telescope help_tags <CR>", " help page" },
["<leader>fo"] = { "<cmd> Telescope oldfiles <CR>", " find oldfiles" },
["<leader>tk"] = { "<cmd> Telescope keymaps <CR>", " show keys" },
n = {
-- find
["<leader>ff"] = { "<cmd> Telescope find_files <CR>", " find files" },
["<leader>fa"] = { "<cmd> Telescope find_files follow=true no_ignore=true hidden=true <CR>", " find all" },
["<leader>fw"] = { "<cmd> Telescope live_grep <CR>", " live grep" },
["<leader>fb"] = { "<cmd> Telescope buffers <CR>", " find buffers" },
["<leader>fh"] = { "<cmd> Telescope help_tags <CR>", " help page" },
["<leader>fo"] = { "<cmd> Telescope oldfiles <CR>", " find oldfiles" },
["<leader>tk"] = { "<cmd> Telescope keymaps <CR>", " show keys" },
-- git
["<leader>cm"] = { "<cmd> Telescope git_commits <CR>", " git commits" },
["<leader>gt"] = { "<cmd> Telescope git_status <CR>", " git status" },
-- git
["<leader>cm"] = { "<cmd> Telescope git_commits <CR>", " git commits" },
["<leader>gt"] = { "<cmd> Telescope git_status <CR>", " git status" },
-- pick a hidden term
["<leader>pt"] = { "<cmd> Telescope terms <CR>", " pick hidden term" },
-- pick a hidden term
["<leader>pt"] = { "<cmd> Telescope terms <CR>", " pick hidden term" },
-- theme switcher
["<leader>th"] = { "<cmd> Telescope themes <CR>", " nvchad themes" },
},
-- theme switcher
["<leader>th"] = { "<cmd> Telescope themes <CR>", " nvchad themes" },
},
}
M.nvterm = {
t = {
-- toggle in terminal mode
["<A-i>"] = {
function()
require("nvterm.terminal").toggle "float"
end,
" toggle floating term",
},
t = {
-- toggle in terminal mode
["<A-i>"] = {
function()
require("nvterm.terminal").toggle "float"
end,
" toggle floating term",
},
["<A-h>"] = {
function()
require("nvterm.terminal").toggle "horizontal"
end,
" toggle horizontal term",
},
["<A-h>"] = {
function()
require("nvterm.terminal").toggle "horizontal"
end,
" toggle horizontal term",
},
["<A-v>"] = {
function()
require("nvterm.terminal").toggle "vertical"
end,
" toggle vertical term",
},
},
["<A-v>"] = {
function()
require("nvterm.terminal").toggle "vertical"
end,
" toggle vertical term",
},
},
n = {
-- toggle in normal mode
["<A-i>"] = {
function()
require("nvterm.terminal").toggle "float"
end,
" toggle floating term",
},
n = {
-- toggle in normal mode
["<A-i>"] = {
function()
require("nvterm.terminal").toggle "float"
end,
" toggle floating term",
},
["<A-h>"] = {
function()
require("nvterm.terminal").toggle "horizontal"
end,
" toggle horizontal term",
},
["<A-h>"] = {
function()
require("nvterm.terminal").toggle "horizontal"
end,
" toggle horizontal term",
},
["<A-v>"] = {
function()
require("nvterm.terminal").toggle "vertical"
end,
" toggle vertical term",
},
["<A-v>"] = {
function()
require("nvterm.terminal").toggle "vertical"
end,
" toggle vertical term",
},
-- new
-- new
["<leader>h"] = {
function()
require("nvterm.terminal").new "horizontal"
end,
" new horizontal term",
},
["<leader>h"] = {
function()
require("nvterm.terminal").new "horizontal"
end,
" new horizontal term",
},
["<leader>v"] = {
function()
require("nvterm.terminal").new "vertical"
end,
" new vertical term",
},
},
["<leader>v"] = {
function()
require("nvterm.terminal").new "vertical"
end,
" new vertical term",
},
},
}
M.whichkey = {
n = {
["<leader>wK"] = {
function()
vim.cmd "WhichKey"
end,
" which-key all keymaps",
},
["<leader>wk"] = {
function()
local input = vim.fn.input "WhichKey: "
vim.cmd("WhichKey " .. input)
end,
" which-key query lookup",
},
},
n = {
["<leader>wK"] = {
function()
vim.cmd "WhichKey"
end,
" which-key all keymaps",
},
["<leader>wk"] = {
function()
local input = vim.fn.input "WhichKey: "
vim.cmd("WhichKey " .. input)
end,
" which-key query lookup",
},
},
}
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
)
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,
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",
},
},
" Jump to current_context",
},
},
}
return M

View file

@ -20,8 +20,10 @@ opt.cul = true -- cursor line
-- Indenting
opt.expandtab = true
opt.shiftwidth = 3
opt.shiftwidth = 2
opt.smartindent = true
opt.tabstop = 2
opt.softtabstop = 2
opt.fillchars = { eob = " " }
opt.ignorecase = true
@ -39,7 +41,6 @@ opt.shortmess:append "sI"
opt.signcolumn = "yes"
opt.splitbelow = true
opt.splitright = true
opt.tabstop = 8
opt.termguicolors = true
opt.timeoutlen = 400
opt.undofile = true
@ -55,53 +56,53 @@ g.mapleader = " "
-- disable some builtin vim plugins
local default_plugins = {
"2html_plugin",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
"2html_plugin",
"getscript",
"getscriptPlugin",
"gzip",
"logipat",
"netrw",
"netrwPlugin",
"netrwSettings",
"netrwFileHandlers",
"matchit",
"tar",
"tarPlugin",
"rrhelper",
"spellfile_plugin",
"vimball",
"vimballPlugin",
"zip",
"zipPlugin",
"tutor",
"rplugin",
"syntax",
"synmenu",
"optwin",
"compiler",
"bugreport",
"ftplugin",
}
for _, plugin in pairs(default_plugins) do
g["loaded_" .. plugin] = 1
g["loaded_" .. plugin] = 1
end
local default_providers = {
"node",
"perl",
"python3",
"ruby",
"node",
"perl",
"python3",
"ruby",
}
for _, provider in ipairs(default_providers) do
vim.g["loaded_" .. provider .. "_provider"] = 0
vim.g["loaded_" .. provider .. "_provider"] = 0
end
-- set shada path
vim.schedule(function()
vim.opt.shadafile = vim.fn.expand "$HOME" .. "/.local/share/nvim/shada/main.shada"
vim.cmd [[ silent! rsh ]]
vim.opt.shadafile = vim.fn.expand "$HOME" .. "/.local/share/nvim/shada/main.shada"
vim.cmd [[ silent! rsh ]]
end)
-- load user options

View file

@ -1,59 +1,59 @@
local M = {}
M.bootstrap = function()
local fn = vim.fn
local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
local fn = vim.fn
local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim"
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "#1e222a" })
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 }
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
vim.cmd "packadd packer.nvim"
require "plugins"
vim.cmd "PackerSync"
end
-- install plugins + compile their configs
vim.cmd "packadd packer.nvim"
require "plugins"
vim.cmd "PackerSync"
end
end
M.options = {
auto_clean = true,
compile_on_sync = true,
git = { clone_timeout = 6000 },
display = {
working_sym = "",
error_sym = "",
done_sym = "",
removed_sym = "",
moved_sym = "",
open_fn = function()
return require("packer.util").float { border = "single" }
end,
},
auto_clean = true,
compile_on_sync = true,
git = { clone_timeout = 6000 },
display = {
working_sym = "",
error_sym = "",
done_sym = "",
removed_sym = "",
moved_sym = "",
open_fn = function()
return require("packer.util").float { border = "single" }
end,
},
}
-- merge overrides if there are any
M.options = require("core.utils").load_override(M.options, "wbthomason/packer.nvim")
M.run = function(plugins)
local present, packer = pcall(require, "packer")
local present, packer = pcall(require, "packer")
if not present then
return
end
if not present then
return
end
-- Override with chadrc values
plugins = require("core.utils").remove_default_plugins(plugins)
plugins = require("core.utils").merge_plugins(plugins)
-- Override with chadrc values
plugins = require("core.utils").remove_default_plugins(plugins)
plugins = require("core.utils").merge_plugins(plugins)
packer.init(M.options)
packer.init(M.options)
packer.startup(function(use)
for _, v in pairs(plugins) do
use(v)
end
end)
packer.startup(function(use)
for _, v in pairs(plugins) do
use(v)
end
end)
end
return M

View file

@ -4,225 +4,225 @@ local api = vim.api
local merge_tb = vim.tbl_deep_extend
M.close_buffer = function(bufnr)
if vim.bo.buftype == "terminal" then
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
elseif vim.bo.modified then
print "save the file bruh"
else
bufnr = bufnr or api.nvim_get_current_buf()
require("core.utils").tabuflinePrev()
vim.cmd("bd" .. bufnr)
end
if vim.bo.buftype == "terminal" then
vim.cmd(vim.bo.buflisted and "set nobl | enew" or "hide")
elseif vim.bo.modified then
print "save the file bruh"
else
bufnr = bufnr or api.nvim_get_current_buf()
require("core.utils").tabuflinePrev()
vim.cmd("bd" .. bufnr)
end
end
M.load_config = function()
local config = require "core.default_config"
local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
local config = require "core.default_config"
local chadrc_exists, chadrc = pcall(require, "custom.chadrc")
if chadrc_exists then
-- merge user config if it exists and is a table; otherwise display an error
if type(chadrc) == "table" then
M.remove_default_keys()
config = merge_tb("force", config, chadrc)
else
error "chadrc must return a table!"
end
end
if chadrc_exists then
-- merge user config if it exists and is a table; otherwise display an error
if type(chadrc) == "table" then
M.remove_default_keys()
config = merge_tb("force", config, chadrc)
else
error "chadrc must return a table!"
end
end
config.mappings.disabled = nil
return config
config.mappings.disabled = nil
return config
end
M.remove_default_keys = function()
local chadrc = require "custom.chadrc"
local user_mappings = chadrc.mappings or {}
local user_keys = {}
local user_sections = vim.tbl_keys(user_mappings)
local chadrc = require "custom.chadrc"
local user_mappings = chadrc.mappings or {}
local user_keys = {}
local user_sections = vim.tbl_keys(user_mappings)
-- push user_map keys in user_keys table
for _, section in ipairs(user_sections) do
user_keys = vim.tbl_deep_extend("force", user_keys, user_mappings[section])
end
-- push user_map keys in user_keys table
for _, section in ipairs(user_sections) do
user_keys = vim.tbl_deep_extend("force", user_keys, user_mappings[section])
end
local function disable_key(mode, keybind, mode_mapping)
local keys_in_mode = vim.tbl_keys(user_keys[mode] or {})
local function disable_key(mode, keybind, mode_mapping)
local keys_in_mode = vim.tbl_keys(user_keys[mode] or {})
if vim.tbl_contains(keys_in_mode, keybind) then
mode_mapping[keybind] = nil
if vim.tbl_contains(keys_in_mode, keybind) then
mode_mapping[keybind] = nil
end
end
local default_mappings = require("core.default_config").mappings
-- remove user_maps from default mapping table
for _, section_mappings in pairs(default_mappings) do
for mode, mode_mapping in pairs(section_mappings) do
for keybind, _ in pairs(mode_mapping) do
disable_key(mode, keybind, mode_mapping)
end
end
local default_mappings = require("core.default_config").mappings
-- remove user_maps from default mapping table
for _, section_mappings in pairs(default_mappings) do
for mode, mode_mapping in pairs(section_mappings) do
for keybind, _ in pairs(mode_mapping) do
disable_key(mode, keybind, mode_mapping)
end
end
end
end
end
end
M.load_mappings = function(mappings, mapping_opt)
-- set mapping function with/without whichkey
local set_maps
local whichkey_exists, wk = pcall(require, "which-key")
-- set mapping function with/without whichkey
local set_maps
local whichkey_exists, wk = pcall(require, "which-key")
if whichkey_exists then
set_maps = function(keybind, mapping_info, opts)
wk.register({ [keybind] = mapping_info }, opts)
if whichkey_exists then
set_maps = function(keybind, mapping_info, opts)
wk.register({ [keybind] = mapping_info }, opts)
end
else
set_maps = function(keybind, mapping_info, opts)
local mode = opts.mode
opts.mode = nil
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
mappings = mappings or vim.deepcopy(M.load_config().mappings)
mappings.lspconfig = nil
for _, section in pairs(mappings) do
for mode, mode_values in pairs(section) do
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
if mapping_info.opts then
mapping_info.opts = nil
end
set_maps(keybind, mapping_info, opts)
end
else
set_maps = function(keybind, mapping_info, opts)
local mode = opts.mode
opts.mode = nil
vim.keymap.set(mode, keybind, mapping_info[1], opts)
end
end
mappings = mappings or vim.deepcopy(M.load_config().mappings)
mappings.lspconfig = nil
for _, section in pairs(mappings) do
for mode, mode_values in pairs(section) do
for keybind, mapping_info in pairs(mode_values) do
-- merge default + user opts
local default_opts = merge_tb("force", { mode = mode }, mapping_opt or {})
local opts = merge_tb("force", default_opts, mapping_info.opts or {})
if mapping_info.opts then
mapping_info.opts = nil
end
set_maps(keybind, mapping_info, opts)
end
end
end
end
end
end
-- remove plugins defined in chadrc
M.remove_default_plugins = function(plugins)
local removals = M.load_config().plugins.remove or {}
local removals = M.load_config().plugins.remove or {}
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
plugins[plugin] = nil
end
end
if not vim.tbl_isempty(removals) then
for _, plugin in pairs(removals) do
plugins[plugin] = nil
end
end
return plugins
return plugins
end
-- merge default/user plugin tables
M.merge_plugins = function(default_plugins)
local user_plugins = M.load_config().plugins.user
local user_plugins = M.load_config().plugins.user
-- merge default + user plugin table
default_plugins = merge_tb("force", default_plugins, user_plugins)
-- merge default + user plugin table
default_plugins = merge_tb("force", default_plugins, user_plugins)
local final_table = {}
local final_table = {}
for key, _ in pairs(default_plugins) do
default_plugins[key][1] = key
final_table[#final_table + 1] = default_plugins[key]
end
for key, _ in pairs(default_plugins) do
default_plugins[key][1] = key
final_table[#final_table + 1] = default_plugins[key]
end
return final_table
return final_table
end
M.load_override = function(default_table, plugin_name)
local user_table = M.load_config().plugins.override[plugin_name] or {}
user_table = type(user_table) == "table" and user_table or user_table()
return merge_tb("force", default_table, user_table)
local user_table = M.load_config().plugins.override[plugin_name] or {}
user_table = type(user_table) == "table" and user_table or user_table()
return merge_tb("force", default_table, user_table)
end
M.packer_sync = function(...)
local git_exists, git = pcall(require, "nvchad.utils.git")
local defaults_exists, defaults = pcall(require, "nvchad.utils.config")
local packer_exists, packer = pcall(require, "packer")
local git_exists, git = pcall(require, "nvchad.utils.git")
local defaults_exists, defaults = pcall(require, "nvchad.utils.config")
local packer_exists, packer = pcall(require, "packer")
if git_exists and defaults_exists then
local current_branch_name = git.get_current_branch_name()
if git_exists and defaults_exists then
local current_branch_name = git.get_current_branch_name()
-- warn the user if we are on a snapshot branch
if current_branch_name:match(defaults.snaps.base_snap_branch_name .. "(.+)" .. "$") then
vim.api.nvim_echo({
{ "WARNING: You are trying to use ", "WarningMsg" },
{ "PackerSync" },
{
" on a NvChadSnapshot. This will cause issues if NvChad dependencies contain "
.. "any breaking changes! Plugin updates will not be included in this "
.. "snapshot, so they will be lost after switching between snapshots! Would "
.. "you still like to continue? [y/N]\n",
"WarningMsg",
},
}, false, {})
-- warn the user if we are on a snapshot branch
if current_branch_name:match(defaults.snaps.base_snap_branch_name .. "(.+)" .. "$") then
vim.api.nvim_echo({
{ "WARNING: You are trying to use ", "WarningMsg" },
{ "PackerSync" },
{
" on a NvChadSnapshot. This will cause issues if NvChad dependencies contain "
.. "any breaking changes! Plugin updates will not be included in this "
.. "snapshot, so they will be lost after switching between snapshots! Would "
.. "you still like to continue? [y/N]\n",
"WarningMsg",
},
}, false, {})
local ans = vim.trim(string.lower(vim.fn.input "-> "))
local ans = vim.trim(string.lower(vim.fn.input "-> "))
if ans ~= "y" then
return
end
if ans ~= "y" then
return
end
end
end
end
if packer_exists then
packer.sync(...)
else
error "Packer could not be loaded!"
end
if packer_exists then
packer.sync(...)
else
error "Packer could not be loaded!"
end
end
M.bufilter = function()
local bufs = vim.t.bufs
local bufs = vim.t.bufs
for i = #bufs, 1, -1 do
if not vim.api.nvim_buf_is_valid(bufs[i]) then
table.remove(bufs, i)
end
end
for i = #bufs, 1, -1 do
if not vim.api.nvim_buf_is_valid(bufs[i]) then
table.remove(bufs, i)
end
end
return bufs
return bufs
end
M.tabuflineNext = function()
local bufs = M.bufilter() or {}
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == #bufs and "b" .. bufs[1] or "b" .. bufs[i + 1])
break
end
end
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == #bufs and "b" .. bufs[1] or "b" .. bufs[i + 1])
break
end
end
end
M.tabuflinePrev = function()
local bufs = M.bufilter() or {}
local bufs = M.bufilter() or {}
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == 1 and "b" .. bufs[#bufs] or "b" .. bufs[i - 1])
break
end
end
for i, v in ipairs(bufs) do
if api.nvim_get_current_buf() == v then
vim.cmd(i == 1 and "b" .. bufs[#bufs] or "b" .. bufs[i - 1])
break
end
end
end
-- closes tab + all of its buffers
M.closeAllBufs = function(action)
local bufs = vim.t.bufs
local bufs = vim.t.bufs
if action == "closeTab" then
vim.cmd "tabclose"
end
if action == "closeTab" then
vim.cmd "tabclose"
end
for _, buf in ipairs(bufs) do
M.close_buffer(buf)
end
for _, buf in ipairs(bufs) do
M.close_buffer(buf)
end
if action ~= "closeTab" then
vim.cmd "enew"
end
if action ~= "closeTab" then
vim.cmd "enew"
end
end
return M