aboutsummaryrefslogtreecommitdiff
path: root/store/home/config/nvim/lua/setup
diff options
context:
space:
mode:
Diffstat (limited to 'store/home/config/nvim/lua/setup')
-rw-r--r--store/home/config/nvim/lua/setup/init.lua45
-rw-r--r--store/home/config/nvim/lua/setup/lsp/clangd.lua25
-rw-r--r--store/home/config/nvim/lua/setup/lsp/init.lua25
-rw-r--r--store/home/config/nvim/lua/setup/lsp/lua_ls.lua29
-rw-r--r--store/home/config/nvim/lua/setup/plugins/cmp.lua33
-rw-r--r--store/home/config/nvim/lua/setup/plugins/gitsigns.lua40
-rw-r--r--store/home/config/nvim/lua/setup/plugins/init.lua14
-rw-r--r--store/home/config/nvim/lua/setup/plugins/lint.lua80
-rw-r--r--store/home/config/nvim/lua/setup/plugins/telescope.lua11
-rw-r--r--store/home/config/nvim/lua/setup/win.lua16
10 files changed, 318 insertions, 0 deletions
diff --git a/store/home/config/nvim/lua/setup/init.lua b/store/home/config/nvim/lua/setup/init.lua
new file mode 100644
index 0000000..91bd718
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/init.lua
@@ -0,0 +1,45 @@
+local function close_float()
+ local wins = vim.api.nvim_list_wins()
+ for _, v in ipairs(wins) do
+ if vim.api.nvim_win_get_config(v).relative ~= '' then
+ vim.api.nvim_win_close(v, false)
+ end
+ end
+end
+
+local function setup()
+ if vim.fn.has("win32") ~= 0 then
+ require("setup.win").setup()
+ end
+
+ -- spellchecker: ignore termguicolors
+ vim.opt.termguicolors = true;
+ vim.opt.fileformats = "unix,dos";
+ vim.opt.number = true;
+
+ vim.g.load_doxygen_syntax = true;
+ vim.g.doxygen_javadoc_autobrief = false;
+
+ vim.keymap.set("n", "<c-tab>", "<cmd>bnext<cr>")
+ vim.keymap.set("n", "<c-s-tab>", "<cmd>bNext<cr>")
+ vim.keymap.set("n", "<esc>", close_float)
+ vim.keymap.set('t', '<A-n>', '<C-\\><C-n>')
+ vim.keymap.set('t', '<A-p>', function()
+ local register = vim.fn.input("Enter register: ")
+ if register == "" then
+ register = '"'
+ end
+ return '<C-\\><C-N>"' .. register .. 'pi'
+ end, { expr = true })
+
+ vim.cmd("autocmd FileType gitcommit,gitrebase,gitconfig set bufhidden=delete")
+
+ vim.diagnostic.config({ virtual_text = true })
+
+ require("setup.lsp").setup()
+ require("setup.plugins").setup()
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/lsp/clangd.lua b/store/home/config/nvim/lua/setup/lsp/clangd.lua
new file mode 100644
index 0000000..6080510
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/lsp/clangd.lua
@@ -0,0 +1,25 @@
+local lspconfig = require("lspconfig")
+
+local brew_clangd_path = "/usr/local/opt/llvm/bin/clangd"
+
+local function setup()
+ local clangd = "clangd"
+
+ if vim.uv.fs_stat(brew_clangd_path) ~= nil then
+ clangd = brew_clangd_path
+ end
+
+ -- setup lsp clangd
+ lspconfig.clangd.setup {
+ cmd = { clangd },
+ on_attach = function(_, bufnr)
+ vim.keymap.set('n', 'grs', "<cmd>ClangdSwitchSourceHeader<cr>", {
+ buffer = bufnr
+ })
+ end
+ }
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/lsp/init.lua b/store/home/config/nvim/lua/setup/lsp/init.lua
new file mode 100644
index 0000000..e87c2be
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/lsp/init.lua
@@ -0,0 +1,25 @@
+local lspconfig = require("lspconfig")
+local cmp_nvim_lsp = require("cmp_nvim_lsp")
+local cmp_default_caps = cmp_nvim_lsp.default_capabilities()
+
+local lspconfig_default_caps = lspconfig.util.default_config.capabilities
+
+lspconfig.util.default_config = vim.tbl_extend(
+ "force",
+ lspconfig.util.default_config,
+ {
+ capabilities = vim.tbl_extend("force", lspconfig_default_caps, cmp_default_caps),
+ autostart = false,
+ })
+
+local function setup()
+ lspconfig.cmake.setup {}
+ lspconfig.bashls.setup {}
+ require("setup.lsp.clangd").setup()
+ require("setup.lsp.lua_ls").setup()
+end
+
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/lsp/lua_ls.lua b/store/home/config/nvim/lua/setup/lsp/lua_ls.lua
new file mode 100644
index 0000000..93aa503
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/lsp/lua_ls.lua
@@ -0,0 +1,29 @@
+local lspconfig = require("lspconfig")
+
+local function setup()
+ lspconfig.lua_ls.setup {
+ settings = {
+ Lua = {
+ runtime = {
+ version = "LuaJIT"
+ },
+ diagnostics = {
+ globals = { "vim" },
+ },
+ workspace = {
+ library = {
+ [vim.fn.expand "$VIMRUNTIME/lua"] = true,
+ [vim.fn.expand "$VIMRUNTIME/lua/vim/lsp"] = true,
+ [vim.fn.stdpath "data" .. "/lazy/lazy.nvim/lua/lazy"] = true,
+ },
+ maxPreload = 100000,
+ preloadFileSize = 10000,
+ },
+ },
+ },
+ }
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/plugins/cmp.lua b/store/home/config/nvim/lua/setup/plugins/cmp.lua
new file mode 100644
index 0000000..c977943
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/plugins/cmp.lua
@@ -0,0 +1,33 @@
+local function setup()
+ local cmp = require("cmp")
+
+ cmp.setup {
+ snippet = {
+ expand = function(args)
+ vim.snippet.expand(args.body)
+ end,
+ },
+ window = {
+ completion = cmp.config.window.bordered(),
+ documentation = cmp.config.window.bordered(),
+ },
+ mapping = cmp.mapping.preset.insert({
+ ['<C-b>'] = cmp.mapping.scroll_docs(-4),
+ ['<C-f>'] = cmp.mapping.scroll_docs(4),
+ ['<C-j>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
+ ['<C-k>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
+ ['<C-y>'] = cmp.mapping.confirm({ select = true }),
+ ['<CR>'] = cmp.mapping.confirm({ select = true }),
+ }),
+ sources = cmp.config.sources({
+ { name = 'nvim_lsp' },
+ { name = 'path' },
+ }, {
+ { name = 'buffer' },
+ })
+ }
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/plugins/gitsigns.lua b/store/home/config/nvim/lua/setup/plugins/gitsigns.lua
new file mode 100644
index 0000000..957c661
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/plugins/gitsigns.lua
@@ -0,0 +1,40 @@
+local function setup()
+ local gitsigns = require('gitsigns')
+
+ gitsigns.setup {
+ on_attach = function(bufnr)
+ local function map(mode, l, r, opts)
+ opts = opts or {}
+ opts.buffer = bufnr
+ vim.keymap.set(mode, l, r, opts)
+ end
+
+ -- Navigation
+ map('n', ']c', function()
+ if vim.wo.diff then
+ vim.cmd.normal({ ']c', bang = true })
+ else
+ gitsigns.nav_hunk('next')
+ end
+ end)
+
+ map('n', '[c', function()
+ if vim.wo.diff then
+ vim.cmd.normal({ '[c', bang = true })
+ else
+ gitsigns.nav_hunk('prev')
+ end
+ end)
+
+ -- Actions
+ map('n', '<leader>gc', gitsigns.preview_hunk)
+ map('n', '<leader>gt', gitsigns.toggle_deleted)
+ map('n', '<leader>gd', gitsigns.diffthis)
+ map('n', '<leader>gb', function() gitsigns.blame_line { full = true } end)
+ end
+ }
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/plugins/init.lua b/store/home/config/nvim/lua/setup/plugins/init.lua
new file mode 100644
index 0000000..0e2a839
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/plugins/init.lua
@@ -0,0 +1,14 @@
+local function setup()
+ require("setup.plugins.lint").setup()
+ require("setup.plugins.cmp").setup()
+ require("setup.plugins.telescope").setup()
+ require("setup.plugins.gitsigns").setup()
+
+ require('lualine').setup {}
+ require("nvim-tree").setup {}
+ require("nvim-autopairs").setup {}
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/plugins/lint.lua b/store/home/config/nvim/lua/setup/plugins/lint.lua
new file mode 100644
index 0000000..688e5ca
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/plugins/lint.lua
@@ -0,0 +1,80 @@
+local lint = require("lint")
+
+local cspell = {
+ name = "cspell",
+ config_patterns = {
+ ".cspell.json",
+ "cspell.json",
+ ".cSpell.json",
+ "cSpell.json",
+ "cspell.config.js",
+ "cspell.config.cjs",
+ "cspell.config.json",
+ "cspell.config.yaml",
+ "cspell.config.yml",
+ "cspell.yaml",
+ "cspell.yml",
+ },
+ fast = true,
+}
+
+local linters = { cspell }
+
+local linter_names = vim.tbl_map(function(l) return l.name end, linters)
+
+local function cru_lint(linter, opt)
+ opt = opt or {}
+
+ if not opt.buf then
+ opt.buf = 0
+ end
+
+ if 0 ~= #vim.fs.find(linter.config_patterns, {
+ path = vim.api.nvim_buf_get_name(opt.buf), upward = true }) then
+ lint.try_lint(linter.name)
+ end
+end
+
+local function cru_lint_one(name, opt)
+ for _, linter in ipairs(linters) do
+ if linter.name == name then
+ cru_lint(linter, opt)
+ return
+ end
+ end
+ vim.notify("No linter named " .. name .. " is configured.", vim.log.levels.ERROR, {})
+end
+
+local function cru_lint_all(opt, fast)
+ for _, linter in ipairs(linters) do
+ if not fast or linter.fast then
+ cru_lint(linter, opt)
+ end
+ end
+end
+
+local function cru_lint_all_fast(opt)
+ local buf = opt.buf
+ if vim.api.nvim_get_option_value("buftype", { buf = buf }) == "" then
+ cru_lint_all(opt, true)
+ end
+end
+
+local function setup()
+ vim.api.nvim_create_autocmd({ "BufReadPost", "InsertLeave", "TextChanged" }, { callback = cru_lint_all_fast })
+
+ local function cru_lint_cmd(opt)
+ if #opt.args == 0 then
+ cru_lint_all(opt, false)
+ else
+ cru_lint_one(opt.args, opt)
+ end
+ end
+
+ vim.api.nvim_create_user_command("CruLint", cru_lint_cmd,
+ { nargs = '?', complete = function() return linter_names end })
+end
+
+return {
+ setup = setup,
+}
diff --git a/store/home/config/nvim/lua/setup/plugins/telescope.lua b/store/home/config/nvim/lua/setup/plugins/telescope.lua
new file mode 100644
index 0000000..d68b7f2
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/plugins/telescope.lua
@@ -0,0 +1,11 @@
+local function setup()
+ local builtin = require('telescope.builtin')
+ vim.keymap.set('n', '<leader>ff', builtin.find_files, {})
+ vim.keymap.set('n', '<leader>fg', builtin.live_grep, {})
+ vim.keymap.set('n', '<leader>fb', builtin.buffers, {})
+ vim.keymap.set('n', '<leader>fh', builtin.help_tags, {})
+end
+
+return {
+ setup = setup
+}
diff --git a/store/home/config/nvim/lua/setup/win.lua b/store/home/config/nvim/lua/setup/win.lua
new file mode 100644
index 0000000..90e168a
--- /dev/null
+++ b/store/home/config/nvim/lua/setup/win.lua
@@ -0,0 +1,16 @@
+-- spellchecker: words pwsh
+-- spellchecker: ignore shellcmdflag shellredir shellpipe shellquote shellxquote
+local function setup()
+ vim.cmd([[
+ let &shell = executable('pwsh') ? 'pwsh' : 'powershell'
+ let &shellcmdflag = '-NoLogo -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.UTF8Encoding]::new();$PSDefaultParameterValues[''Out-File:Encoding'']=''utf8'';Remove-Alias -Force -ErrorAction SilentlyContinue tee;'
+ let &shellredir = '2>&1 | %%{ "$_" } | Out-File %s; exit $LastExitCode'
+ let &shellpipe = '2>&1 | %%{ "$_" } | tee %s; exit $LastExitCode'
+ set shellquote= shellxquote=
+ ]])
+ vim.opt.completeslash = 'slash'
+end
+
+return {
+ setup = setup
+}