From 8df1114f709aceeec12cef6020720c5128f20c5d Mon Sep 17 00:00:00 2001 From: Daryl Ronningen Date: Sat, 9 Jul 2022 13:10:31 +0000 Subject: [PATCH] move neovim config here --- .gitignore | 1 + LICENSE | 11 ++ README.md | 7 ++ init.lua | 27 +++++ lua/user/alpha.lua | 36 ++++++ lua/user/autocommands.lua | 46 ++++++++ lua/user/autopairs.lua | 17 +++ lua/user/bufferline.lua | 34 ++++++ lua/user/cmp.lua | 152 ++++++++++++++++++++++++ lua/user/colorizer.lua | 17 +++ lua/user/colorscheme.lua | 5 + lua/user/comment.lua | 22 ++++ lua/user/copilot.lua | 6 + lua/user/dap.lua | 12 ++ lua/user/discord.lua | 6 + lua/user/gitsigns.lua | 52 +++++++++ lua/user/illuminate.lua | 3 + lua/user/impatient.lua | 6 + lua/user/indentline.lua | 16 +++ lua/user/keymaps.lua | 125 ++++++++++++++++++++ lua/user/lsp/handlers.lua | 91 +++++++++++++++ lua/user/lsp/init.lua | 4 + lua/user/lsp/mason.lua | 20 ++++ lua/user/lsp/nullls.lua | 28 +++++ lua/user/lsp/settings/jsonls.lua | 18 +++ lua/user/lsp/settings/sumneko_lua.lua | 11 ++ lua/user/lsp/settings/tsserver.lua | 6 + lua/user/lsp/signature.lua | 11 ++ lua/user/lualine.lua | 38 ++++++ lua/user/notify.lua | 16 +++ lua/user/nvimtree.lua | 102 ++++++++++++++++ lua/user/options.lua | 43 +++++++ lua/user/plugins.lua | 160 ++++++++++++++++++++++++++ lua/user/spectre.lua | 9 ++ lua/user/telescope.lua | 76 ++++++++++++ lua/user/toggleterm.lua | 27 +++++ lua/user/treesitter.lua | 22 ++++ lua/user/trouble.lua | 6 + lua/user/whichkey.lua | 6 + lua/user/whitespace.lua | 15 +++ lua/user/winbar.lua | 64 +++++++++++ 41 files changed, 1374 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 init.lua create mode 100644 lua/user/alpha.lua create mode 100644 lua/user/autocommands.lua create mode 100644 lua/user/autopairs.lua create mode 100644 lua/user/bufferline.lua create mode 100644 lua/user/cmp.lua create mode 100644 lua/user/colorizer.lua create mode 100644 lua/user/colorscheme.lua create mode 100644 lua/user/comment.lua create mode 100644 lua/user/copilot.lua create mode 100644 lua/user/dap.lua create mode 100644 lua/user/discord.lua create mode 100644 lua/user/gitsigns.lua create mode 100644 lua/user/illuminate.lua create mode 100644 lua/user/impatient.lua create mode 100644 lua/user/indentline.lua create mode 100644 lua/user/keymaps.lua create mode 100644 lua/user/lsp/handlers.lua create mode 100644 lua/user/lsp/init.lua create mode 100644 lua/user/lsp/mason.lua create mode 100644 lua/user/lsp/nullls.lua create mode 100644 lua/user/lsp/settings/jsonls.lua create mode 100644 lua/user/lsp/settings/sumneko_lua.lua create mode 100644 lua/user/lsp/settings/tsserver.lua create mode 100644 lua/user/lsp/signature.lua create mode 100644 lua/user/lualine.lua create mode 100644 lua/user/notify.lua create mode 100644 lua/user/nvimtree.lua create mode 100644 lua/user/options.lua create mode 100644 lua/user/plugins.lua create mode 100644 lua/user/spectre.lua create mode 100644 lua/user/telescope.lua create mode 100644 lua/user/toggleterm.lua create mode 100644 lua/user/treesitter.lua create mode 100644 lua/user/trouble.lua create mode 100644 lua/user/whichkey.lua create mode 100644 lua/user/whitespace.lua create mode 100644 lua/user/winbar.lua diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8cb205e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +plugin diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..7a3094a --- /dev/null +++ b/LICENSE @@ -0,0 +1,11 @@ +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +Version 2, December 2004 + +Copyright (C) 2004 Sam Hocevar + +Everyone is permitted to copy and distribute verbatim or modified copies of this license document, and changing it is allowed as long as the name is changed. + +DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE +TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..67ec0dc --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Neovim Config +To use this neovim config, run `git clone https://code.relms.dev/Relms/neovim-config ~/.config/nvim` to clone the config to your .config folder. + +When you open the config for the first time, you will get a packer.nvim window to open which will open all the required plugins. After that, close Neovim again and reopen it. It will then proceed to install a bunch of treesitter parsers. That is normal. + +## Using GitHub copilot + - TODO diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..1677fb0 --- /dev/null +++ b/init.lua @@ -0,0 +1,27 @@ +require("user.options") +require("user.keymaps") +require("user.plugins") +require("user.notify") +require("user.cmp") +require("user.lsp") +require("user.colorscheme") +require("user.telescope") +require("user.treesitter") +require("user.autopairs") +require("user.comment") +require("user.gitsigns") +require("user.nvimtree") +require("user.bufferline") +require("user.whitespace") +require("user.lualine") +require("user.toggleterm") +require("user.impatient") +require("user.indentline") +require("user.alpha") +require("user.whichkey") +require("user.trouble") +require("user.colorizer") +require("user.discord") +require("user.spectre") +require("user.dap") +require("user.copilot") diff --git a/lua/user/alpha.lua b/lua/user/alpha.lua new file mode 100644 index 0000000..44ecdd0 --- /dev/null +++ b/lua/user/alpha.lua @@ -0,0 +1,36 @@ +local status_ok, alpha = pcall(require, "alpha") +if not status_ok then + return +end + +local dashboard = require("alpha.themes.dashboard") +dashboard.section.header.val = { + " ▟▙", + " ▝▘", + "██▃▅▇█▆▖ ▗▟████▙▖ ▄████▄ ██▄ ▄██ ██ ▗▟█▆▄▄▆█▙▖", + "██▛▔ ▝██ ██▄▄▄▄██ ██▛▔▔▜██ ▝██ ██▘ ██ ██▛▜██▛▜██", + "██ ██ ██▀▀▀▀▀▘ ██▖ ▗██ ▜█▙▟█▛ ██ ██ ██ ██", + "██ ██ ▜█▙▄▄▄▟▊ ▀██▙▟██▀ ▝████▘ ██ ██ ██ ██", + "▀▀ ▀▀ ▝▀▀▀▀▀ ▀▀▀▀ ▀▀ ▀▀ ▀▀ ▀▀ ▀▀", +} +dashboard.section.buttons.val = { + dashboard.button("f", " Find file", ":Telescope find_files "), + dashboard.button("e", " New file", ":ene startinsert "), + dashboard.button("r", " Recently used files", ":Telescope oldfiles "), + dashboard.button("t", " Find text", ":Telescope live_grep "), + dashboard.button("c", " Configuration", ":e ~/.config/nvim/init.lua "), + dashboard.button("q", " Quit Neovim", ":qa"), +} + +local function footer() + return "I use Arch BTW" +end + +dashboard.section.footer.val = footer() + +dashboard.section.footer.opts.hl = "Type" +dashboard.section.header.opts.hl = "Include" +dashboard.section.buttons.opts.hl = "Keyword" + +dashboard.opts.opts.noautocmd = true +alpha.setup(dashboard.opts) diff --git a/lua/user/autocommands.lua b/lua/user/autocommands.lua new file mode 100644 index 0000000..d31bf83 --- /dev/null +++ b/lua/user/autocommands.lua @@ -0,0 +1,46 @@ +-- Use 'q' to quit from common plugins +vim.api.nvim_create_autocmd({ "FileType" }, { + pattern = { "qf", "help", "man", "lspinfo", "spectre_panel", "lir" }, + callback = function() + vim.cmd([[ + nnoremap q :close + set nobuflisted + ]]) + end, +}) + +-- Remove statusline and tabline when in Alpha +vim.api.nvim_create_autocmd({ "User" }, { + pattern = { "AlphaReady" }, + callback = function() + vim.cmd([[ + set showtabline=0 | autocmd BufUnload set showtabline=2 + set laststatus=0 | autocmd BufUnload set laststatus=3 + ]]) + end, +}) + +-- Set wrap and spell in markdown and gitcommit +vim.api.nvim_create_autocmd({ "FileType" }, { + pattern = { "gitcommit", "markdown" }, + callback = function() + vim.opt_local.wrap = true + vim.opt_local.spell = true + end, +}) + +vim.cmd("autocmd BufEnter * ++nested if winnr('$') == 1 && bufname() == 'NvimTree_' . tabpagenr() | quit | endif") + +-- Fixes Autocomment +vim.api.nvim_create_autocmd({ "BufWinEnter" }, { + callback = function() + vim.cmd("set formatoptions-=cro") + end, +}) + +-- Highlight Yanked Text +vim.api.nvim_create_autocmd({ "TextYankPost" }, { + callback = function() + vim.highlight.on_yank({ higroup = "Visual", timeout = 200 }) + end, +}) diff --git a/lua/user/autopairs.lua b/lua/user/autopairs.lua new file mode 100644 index 0000000..2cf6873 --- /dev/null +++ b/lua/user/autopairs.lua @@ -0,0 +1,17 @@ +-- Setup nvim-cmp. +local status_ok, npairs = pcall(require, "nvim-autopairs") +if not status_ok then + return +end + +npairs.setup({ + check_ts = true, -- treesitter integration + disable_filetype = { "TelescopePrompt" }, +}) + +local cmp_autopairs = require("nvim-autopairs.completion.cmp") +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end +cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done({})) diff --git a/lua/user/bufferline.lua b/lua/user/bufferline.lua new file mode 100644 index 0000000..777afa3 --- /dev/null +++ b/lua/user/bufferline.lua @@ -0,0 +1,34 @@ +local status_ok, bufferline = pcall(require, "bufferline") +if not status_ok then + return +end + +bufferline.setup({ + options = { + numbers = "ordinal", + close_command = "Bdelete! %d", + right_mouse_command = "Bdelete! %d", + left_mouse_command = "buffer %d", + middle_mouse_command = nil, + indicator_icon = "▎", + buffer_close_icon = "", + modified_icon = "●", + close_icon = "", + left_trunc_marker = "", + right_trunc_marker = "", + max_name_length = 30, + max_prefix_length = 30, + tab_size = 21, + diagnostics = "nvim_lsp", + diagnostics_update_in_insert = true, + offsets = { { filetype = "NvimTree", text = "", padding = 1 } }, + show_buffer_icons = true, + show_buffer_close_icons = true, + show_close_icon = true, + show_tab_indicators = true, + persist_buffer_sort = true, + separator_style = "thin", + enforce_regular_tabs = true, + always_show_bufferline = true, + }, +}) diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 0000000..27565ea --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,152 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local npm_status_ok, npm = pcall(require, "cmp-npm") +if not npm_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col(".") - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") +end + +npm.setup({}) + +local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} + +cmp.setup({ + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + [""] = cmp.mapping.confirm({ select = true }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }, + formatting = { + fields = { "abbr", "kind", "menu" }, + format = function(entry, vim_item) + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + vim_item.menu = ({ + nvim_lsp = "[LSP]", + copilot = "[COPILOT]", + npm = "[NPM]", + nvim_lua = "[NVIM_LUA]", + luasnip = "[SNIPPET]", + buffer = "[BUFFER]", + path = "[PATH6]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "copilot" }, + { name = "nvim_lsp" }, + { name = "npm" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = { + border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" }, + }, + }, + experimental = { + ghost_text = true, + native_menu = false, + }, +}) + +cmp.setup.cmdline("/", { + sources = { + { name = "buffer" }, + }, +}) + +cmp.setup.cmdline(":", { + sources = cmp.config.sources({ + { name = "path" }, + }, { + { name = "cmdline" }, + }), +}) diff --git a/lua/user/colorizer.lua b/lua/user/colorizer.lua new file mode 100644 index 0000000..875aa13 --- /dev/null +++ b/lua/user/colorizer.lua @@ -0,0 +1,17 @@ +local status_ok, colorizer = pcall(require, "colorizer") +if not status_ok then + return +end + +colorizer.setup({ "*" }, { + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes + names = false, -- "Name" codes like Blue oe blue + RRGGBBAA = true, -- #RRGGBBAA hex codes + rgb_fn = true, -- CSS rgb() and rgba() functions + hsl_fn = true, -- 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, virtualtext + mode = "background", -- Set the display mode.) +}) diff --git a/lua/user/colorscheme.lua b/lua/user/colorscheme.lua new file mode 100644 index 0000000..f42924d --- /dev/null +++ b/lua/user/colorscheme.lua @@ -0,0 +1,5 @@ +vim.g.nord_italic = false +vim.g.nord_contrast = true +vim.g.nord_borders = true +require("nord").set() +require("lsp-colors").setup() diff --git a/lua/user/comment.lua b/lua/user/comment.lua new file mode 100644 index 0000000..07c1a2a --- /dev/null +++ b/lua/user/comment.lua @@ -0,0 +1,22 @@ +local status_ok, comment = pcall(require, "Comment") +if not status_ok then + return +end + +comment.setup({ + pre_hook = function(ctx) + local U = require("Comment.utils") + + local location = nil + if ctx.ctype == U.ctype.block then + location = require("ts_context_commentstring.utils").get_cursor_location() + elseif ctx.cmotion == U.cmotion.v or ctx.cmotion == U.cmotion.V then + location = require("ts_context_commentstring.utils").get_visual_start_location() + end + + return require("ts_context_commentstring.internal").calculate_commentstring({ + key = ctx.ctype == U.ctype.line and "__default" or "__multiline", + location = location, + }) + end, +}) diff --git a/lua/user/copilot.lua b/lua/user/copilot.lua new file mode 100644 index 0000000..47d7e89 --- /dev/null +++ b/lua/user/copilot.lua @@ -0,0 +1,6 @@ +local status_ok, copilot = pcall(require, "copilot") +if not status_ok then + return +end + +copilot.setup({}) diff --git a/lua/user/dap.lua b/lua/user/dap.lua new file mode 100644 index 0000000..b4cbd4c --- /dev/null +++ b/lua/user/dap.lua @@ -0,0 +1,12 @@ +local dapui_status_ok, dapui = pcall(require, "dapui") +if not dapui_status_ok then + return +end + +local vtest_status_ok, vtest = pcall(require, "nvim-dap-virtual-text") +if not vtest_status_ok then + return +end + +dapui.setup() +vtest.setup() diff --git a/lua/user/discord.lua b/lua/user/discord.lua new file mode 100644 index 0000000..4c0d982 --- /dev/null +++ b/lua/user/discord.lua @@ -0,0 +1,6 @@ +local status_ok, discord = pcall(require, "presence") +if not status_ok then + return +end + +discord:setup({}) diff --git a/lua/user/gitsigns.lua b/lua/user/gitsigns.lua new file mode 100644 index 0000000..62320ca --- /dev/null +++ b/lua/user/gitsigns.lua @@ -0,0 +1,52 @@ +local status_ok, gitsigns = pcall(require, "gitsigns") +if not status_ok then + return +end + +gitsigns.setup({ + signs = { + add = { hl = "GitSignsAdd", text = "▎", numhl = "GitSignsAddNr", linehl = "GitSignsAddLn" }, + change = { hl = "GitSignsChange", text = "▎", numhl = "GitSignsChangeNr", linehl = "GitSignsChangeLn" }, + delete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + topdelete = { hl = "GitSignsDelete", text = "契", numhl = "GitSignsDeleteNr", linehl = "GitSignsDeleteLn" }, + changedelete = { + hl = "GitSignsChange", + text = "▎", + numhl = "GitSignsChangeNr", + linehl = "GitSignsChangeLn", + }, + }, + signcolumn = true, + numhl = false, + linehl = false, + word_diff = false, + watch_gitdir = { + interval = 1000, + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = true, + current_line_blame_opts = { + virt_text = true, + virt_text_pos = "eol", + delay = 1000, + ignore_whitespace = false, + }, + current_line_blame_formatter_opts = { + relative_time = false, + }, + sign_priority = 6, + update_debounce = 100, + status_formatter = nil, + max_file_length = 40000, + preview_config = { + border = "single", + style = "minimal", + relative = "cursor", + row = 0, + col = 1, + }, + yadm = { + enable = false, + }, +}) diff --git a/lua/user/illuminate.lua b/lua/user/illuminate.lua new file mode 100644 index 0000000..862843e --- /dev/null +++ b/lua/user/illuminate.lua @@ -0,0 +1,3 @@ +vim.g.Illuminate_ftblacklist = {'alpha', 'NvimTree'} +vim.api.nvim_set_keymap('n', '', 'lua require"illuminate".next_reference{wrap=true}', {noremap=true}) +vim.api.nvim_set_keymap('n', '', 'lua require"illuminate".next_reference{reverse=true,wrap=true}', {noremap=true}) diff --git a/lua/user/impatient.lua b/lua/user/impatient.lua new file mode 100644 index 0000000..fa64f00 --- /dev/null +++ b/lua/user/impatient.lua @@ -0,0 +1,6 @@ +local status_ok, impatient = pcall(require, "impatient") +if not status_ok then + return +end + +impatient.enable_profile() diff --git a/lua/user/indentline.lua b/lua/user/indentline.lua new file mode 100644 index 0000000..6ebf918 --- /dev/null +++ b/lua/user/indentline.lua @@ -0,0 +1,16 @@ +local status_ok, indent_blankline = pcall(require, "indent_blankline") +if not status_ok then + return +end + +vim.g.indent_blankline_filetype_exclude = { + "help", + "packer", + "NvimTree", + "Trouble", + "alpha", +} + +indent_blankline.setup({ + show_current_context = true, +}) diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua new file mode 100644 index 0000000..e357c5a --- /dev/null +++ b/lua/user/keymaps.lua @@ -0,0 +1,125 @@ +local opts = { noremap = true, silent = true } + +local term_opts = { silent = true } + +-- Shorten function name +local keymap = vim.api.nvim_set_keymap + +--Remap space as leader key +keymap("", "", "", opts) +vim.g.mapleader = " " +vim.g.maplocalleader = " " + +-- Modes +-- normal_mode = "n", +-- insert_mode = "i", +-- visual_mode = "v", +-- visual_block_mode = "x", +-- term_mode = "t", +-- command_mode = "c", + +-- Normal -- +-- Better window navigation +keymap("n", "", "h", opts) +keymap("n", "", "j", opts) +keymap("n", "", "k", opts) +keymap("n", "", "l", opts) + +-- Resize with arrows +keymap("n", "", ":resize +2", opts) +keymap("n", "", ":resize -2", opts) +keymap("n", "", ":vertical resize -2", opts) +keymap("n", "", ":vertical resize +2", opts) + +-- Navigate buffers +keymap("n", "", ":bnext", opts) +keymap("n", "", ":bprevious", opts) + +-- Telescope +keymap("n", "ff", ":Telescope frecency", opts) +keymap("n", "fg", ":Telescope live_grep", opts) +keymap("n", "fb", ":Telescope buffers", opts) +keymap("n", "fe", ":Telescope emoji", opts) +keymap("n", "fp", ":Telescope project", opts) +keymap("n", "fd", ":Telescope dap commands", opts) + +-- Comment +keymap("n", "/", ":lua require('Comment').toggle()", opts) + +-- Nvim-Tree +keymap("n", "e", ":NvimTreeToggle", opts) + +-- Trouble +keymap("n", "xx", ":Trouble", opts) +keymap("n", "xw", ":Trouble workspace_diagnostics", opts) +keymap("n", "xd", ":Trouble document_diagnostics", opts) +keymap("n", "xl", ":Trouble loclist", opts) +keymap("n", "xq", ":Trouble quickfix", opts) + +-- DAP +keymap("n", "", ":lua require('dapui').toggle()", opts) +keymap("n", "", ":lua require('dap').toggle_breakpoint()", opts) +keymap("n", "", ":lua require('dap').continue()", opts) +keymap("n", "", ":lua require('dap').step_over()", opts) +keymap("n", "", ":lua require('dap').step_into()", opts) +keymap("n", "", ":lua require('dap').step_out()", opts) +keymap("n", "dsc", ":lua require('dap').continue()", opts) +keymap("n", "dsv", ":lua require('dap').step_over()", opts) +keymap("n", "dsi", ":lua require('dap').step_into()", opts) +keymap("n", "dso", ":lua require('dap').step_out()", opts) +keymap("n", "dhh", ":lua require('dap.ui.variables').hover()", opts) +keymap("v", "dhv", ":lua require('dap.ui.variables').visual_hover()", opts) +keymap("n", "duh", ":lua require('dap.ui.widgets').hover()", opts) +keymap( + "n", + "duf", + ":lua local widgets=require('dap.ui.widgets');widgets.centered_float(widgets.scopes)", + opts +) +keymap("n", "dro", ":lua require('dap').repl.open()", opts) +keymap("n", "drl", ":lua require('dap').repl.run_last()", opts) +keymap("n", "dbc", ":lua require('dap').set_breakpoint(vim.fn.input('Breakpoint condition: '))", opts) +keymap( + "n", + "dbm", + ":lua require('dap').set_breakpoint({ nil, nil, vim.fn.input('Log point message: ') })", + opts +) +keymap("n", "dbt", ":lua require('dap').toggle_breakpoint()", opts) +keymap("n", "dc", ":lua require('dap.ui.variables').scopes()", opts) +keymap("n", "di", ":lua require('dapui').toggle()", opts) + +-- Spectre +keymap("n", "S", ":lua require('spectre').open()", opts) +keymap("n", "sw", ":lua require('spectre').open_visual({select_word=true})", opts) +keymap("n", "s", ":lua require('spectre').open_visual()", opts) +keymap("n", "sp", ":lua require('spectre').open_file_search()", opts) + +-- Insert -- + +-- Visual -- +-- Stay in indent mode +keymap("v", "<", "", ">gv", opts) + +-- Move text up and down +keymap("v", "", ":m .+1==", opts) +keymap("v", "", ":m .-2==", opts) +keymap("v", "p", '"_dP', opts) + +-- Comment +keymap("v", "/", ':lua require("Comment.api").gc(vim.fn.visualmode())', opts) + +-- Visual Block -- +-- Move text up and down +keymap("x", "J", ":move '>+1gv-gv", opts) +keymap("x", "K", ":move '<-2gv-gv", opts) +keymap("x", "", ":move '>+1gv-gv", opts) +keymap("x", "", ":move '<-2gv-gv", opts) + +-- Terminal -- +-- Better terminal navigation +keymap("t", "", "h", term_opts) +keymap("t", "", "j", term_opts) +keymap("t", "", "k", term_opts) +keymap("t", "", "l", term_opts) diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua new file mode 100644 index 0000000..af72d1a --- /dev/null +++ b/lua/user/lsp/handlers.lua @@ -0,0 +1,91 @@ +local M = {} + +M.setup = function() + local signs = { + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + virtual_text = false, + signs = { + active = signs, + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = false, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) +end + +local function lsp_highlight_document(client) + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + illuminate.on_attach(client) +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + + vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", ":lua vim.lsp.buf.declaration()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gd", ":lua vim.lsp.buf.definition()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "K", ":lua vim.lsp.buf.hover()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", ":lua vim.lsp.buf.implementation()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "", ":lua vim.lsp.buf.signature_help()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "grn", ":lua vim.lsp.buf.rename()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", ":lua vim.lsp.buf.references()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gca", ":lua vim.lsp.buf.code_action()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "gl", ":lua vim.diagnostic.open_float()", opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "[d", ':lua vim.diagnostic.goto_prev({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "]d", ':lua vim.diagnostic.goto_next({ border = "rounded" })', opts) + vim.api.nvim_buf_set_keymap(bufnr, "n", "q", "lua vim.diagnostic.setloclist()", opts) + vim.cmd([[ command! Format execute 'lua vim.lsp.buf.formatting()' ]]) +end + +M.on_attach = function(client, bufnr) + lsp_keymaps(bufnr) + lsp_highlight_document(client) + + if client.server_capabilities.documentSymbolProvider then + local navic = require("nvim-navic") + navic.attach(client, bufnr) + end +end + +local capabilities = vim.lsp.protocol.make_client_capabilities() +capabilities.textDocument.completion.completionItem.snippetSupport = true + +local status_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") + +if not status_ok then + return +end + +M.capabilities = cmp_nvim_lsp.update_capabilities(capabilities) + +return M diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua new file mode 100644 index 0000000..16fd3d1 --- /dev/null +++ b/lua/user/lsp/init.lua @@ -0,0 +1,4 @@ +require("user.lsp.handlers").setup() +require("user.lsp.mason") +require("user.lsp.nullls") +require("user.lsp.signature") diff --git a/lua/user/lsp/mason.lua b/lua/user/lsp/mason.lua new file mode 100644 index 0000000..ecf332c --- /dev/null +++ b/lua/user/lsp/mason.lua @@ -0,0 +1,20 @@ +local status_ok, mason = pcall(require, "mason") +if not status_ok then + return +end + +local lspconfig = require("lspconfig") + +mason.setup() +require("mason-lspconfig").setup({ + automatic_installation = true, +}) + +lspconfig.util.default_config = vim.tbl_extend("force", lspconfig.util.default_config, { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, +}) + +require("user.lsp.settings.sumneko_lua") +require("user.lsp.settings.jsonls") +require("user.lsp.settings.tsserver") diff --git a/lua/user/lsp/nullls.lua b/lua/user/lsp/nullls.lua new file mode 100644 index 0000000..2d08457 --- /dev/null +++ b/lua/user/lsp/nullls.lua @@ -0,0 +1,28 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +local formatting = null_ls.builtins.formatting +local code_actions = null_ls.builtins.code_actions +local diagnostics = null_ls.builtins.diagnostics + +null_ls.setup({ + debug = false, + sources = { + formatting.stylua, + code_actions.eslint_d, + diagnostics.eslint_d, + formatting.eslint_d, + }, + on_attach = function(client) + if client.server_capabilities.documentFormattingProvider then + vim.cmd([[ + augroup LspFormatting + autocmd! * + autocmd BufWritePre lua vim.lsp.buf.format() + augroup END + ]]) + end + end, +}) diff --git a/lua/user/lsp/settings/jsonls.lua b/lua/user/lsp/settings/jsonls.lua new file mode 100644 index 0000000..29140f4 --- /dev/null +++ b/lua/user/lsp/settings/jsonls.lua @@ -0,0 +1,18 @@ +local status_ok, lspconfig = pcall(require, "lspconfig") +if not status_ok then + return +end + +local schemastore_status_ok, schemastore = pcall(require, "schemastore") +if not schemastore_status_ok then + return +end + +lspconfig.jsonls.setup({ + settings = { + json = { + schemas = schemastore.json.schemas(), + validate = { enable = true }, + }, + }, +}) diff --git a/lua/user/lsp/settings/sumneko_lua.lua b/lua/user/lsp/settings/sumneko_lua.lua new file mode 100644 index 0000000..67eccf6 --- /dev/null +++ b/lua/user/lsp/settings/sumneko_lua.lua @@ -0,0 +1,11 @@ +local lspconfig = require("lspconfig") + +lspconfig.sumneko_lua.setup({ + settings = { + Lua = { + diagnostics = { + globals = { "vim" }, + }, + }, + }, +}) diff --git a/lua/user/lsp/settings/tsserver.lua b/lua/user/lsp/settings/tsserver.lua new file mode 100644 index 0000000..c9b7428 --- /dev/null +++ b/lua/user/lsp/settings/tsserver.lua @@ -0,0 +1,6 @@ +local status_ok, lspconfig = pcall(require, "lspconfig") +if not status_ok then + return +end + +lspconfig.tsserver.setup({}) diff --git a/lua/user/lsp/signature.lua b/lua/user/lsp/signature.lua new file mode 100644 index 0000000..fc01c76 --- /dev/null +++ b/lua/user/lsp/signature.lua @@ -0,0 +1,11 @@ +local status_ok, signature = pcall(require, "lsp_signature") +if not status_ok then + return +end + +local cfg = { + floating_window = false, -- show hint in a floating window, set to false for virtual text only mode +} + +signature.setup(cfg) -- no need to specify bufnr if you don't use toggle_key +signature.on_attach(cfg) -- no need to specify bufnr if you don't use toggle_key diff --git a/lua/user/lualine.lua b/lua/user/lualine.lua new file mode 100644 index 0000000..84d2335 --- /dev/null +++ b/lua/user/lualine.lua @@ -0,0 +1,38 @@ +local status_ok, lualine = pcall(require, "lualine") +if not status_ok then + return +end + +lualine.setup({ + options = { + icons_enabled = true, + theme = "auto", + component_separators = { left = "", right = "" }, + section_separators = { left = "", right = "" }, + disabled_filetypes = { "alpha", "NvimTree" }, + always_divide_middle = true, + }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch", "diff", "diagnostics" }, + lualine_c = { "filename", "filesize" }, + lualine_x = { "encoding", "fileformat", "filetype" }, + lualine_y = { "progress" }, + lualine_z = { "location" }, + }, + inactive_sections = { + lualine_a = {}, + lualine_b = {}, + lualine_c = { "filename" }, + lualine_x = { "location" }, + lualine_y = {}, + lualine_z = {}, + }, + tabline = {}, + extensions = { + "nvim-tree", + "toggleterm", + "fzf", + "quickfix", + }, +}) diff --git a/lua/user/notify.lua b/lua/user/notify.lua new file mode 100644 index 0000000..15eec94 --- /dev/null +++ b/lua/user/notify.lua @@ -0,0 +1,16 @@ +local status_ok, notify = pcall(require, "notify") +if not status_ok then + return +end + +notify.setup({ + stages = "fade_in_slide_out", + on_open = nil, + on_close = nil, + render = "default", + timeout = 175, + background_colour = "Normal", + minimum_width = 10, +}) + +vim.notify = notify diff --git a/lua/user/nvimtree.lua b/lua/user/nvimtree.lua new file mode 100644 index 0000000..a1f9fae --- /dev/null +++ b/lua/user/nvimtree.lua @@ -0,0 +1,102 @@ +local status_ok, nvim_tree = pcall(require, "nvim-tree") +if not status_ok then + return +end + +local config_status_ok, nvim_tree_config = pcall(require, "nvim-tree.config") +if not config_status_ok then + return +end + +local tree_cb = nvim_tree_config.nvim_tree_callback +vim.api.nvim_create_autocmd("BufEnter", { + nested = true, + callback = function() + if #vim.api.nvim_list_wins() == 1 and vim.api.nvim_buf_get_name(0):match("NvimTree_") ~= nil then + vim.cmd("quit") + end + end, +}) + +nvim_tree.setup({ + disable_netrw = true, + hijack_netrw = true, + open_on_setup = false, + ignore_ft_on_setup = { + "alpha", + }, + open_on_tab = true, + hijack_cursor = true, + update_cwd = true, + diagnostics = { + enable = true, + icons = { + hint = "", + info = "", + warning = "", + error = "", + }, + }, + update_focused_file = { + enable = true, + update_cwd = true, + ignore_list = {}, + }, + git = { + enable = true, + ignore = true, + timeout = 500, + }, + view = { + width = 30, + height = 30, + hide_root_folder = false, + side = "left", + mappings = { + custom_only = false, + list = { + { key = { "l", "", "o" }, cb = tree_cb("edit") }, + { key = "h", cb = tree_cb("close_node") }, + { key = "v", cb = tree_cb("vsplit") }, + }, + }, + number = false, + relativenumber = false, + }, + actions = { + open_file = { + quit_on_open = false, + window_picker = { + enable = false, + }, + }, + }, + renderer = { + icons = { + glyphs = { + default = "", + symlink = "", + git = { + unstaged = "", + staged = "S", + unmerged = "", + renamed = "➜", + deleted = "", + untracked = "U", + ignored = "◌", + }, + folder = { + default = "", + open = "", + empty = "", + empty_open = "", + symlink = "", + }, + }, + }, + }, + filesystem_watchers = { + enable = true, + interval = 100, + }, +}) diff --git a/lua/user/options.lua b/lua/user/options.lua new file mode 100644 index 0000000..a6eae2f --- /dev/null +++ b/lua/user/options.lua @@ -0,0 +1,43 @@ +vim.opt.backup = false +vim.opt.clipboard = "unnamedplus" +vim.opt.cmdheight = 2 +vim.opt.completeopt = { "menuone", "noselect" } +vim.opt.conceallevel = 0 +vim.opt.fileencoding = "utf-8" +vim.opt.hlsearch = true +vim.opt.ignorecase = true +vim.opt.mouse = "a" +vim.opt.pumheight = 10 +vim.opt.showmode = false +vim.opt.showtabline = 2 +vim.opt.smartcase = true +vim.opt.smartindent = true +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.opt.swapfile = false +vim.opt.termguicolors = true +vim.opt.timeoutlen = 500 +vim.opt.undofile = true +vim.opt.updatetime = 50 +vim.opt.writebackup = false +vim.opt.expandtab = false +vim.opt.shiftwidth = 2 +vim.opt.tabstop = 2 +vim.opt.number = true +vim.opt.relativenumber = false +vim.opt.numberwidth = 4 +vim.opt.signcolumn = "yes" +vim.opt.wrap = false +vim.opt.scrolloff = 8 +vim.opt.sidescrolloff = 8 +vim.opt.shortmess:append("c") +vim.opt.guicursor = "" +vim.opt.incsearch = true +vim.opt.colorcolumn = "120" +vim.opt.list = true +vim.opt.listchars:append("lead:.") +vim.opt.winbar = "%{%v:lua.require'user.winbar'.get_winbar()%}" + +vim.cmd("set whichwrap+=<,>,[,],h,l") +vim.cmd([[set iskeyword+=-]]) +vim.cmd([[set formatoptions-=cro]]) diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua new file mode 100644 index 0000000..18b1b45 --- /dev/null +++ b/lua/user/plugins.lua @@ -0,0 +1,160 @@ +local fn = vim.fn + +local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" +if fn.empty(fn.glob(install_path)) > 0 then + PACKER_BOOTSTRAP = fn.system({ + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + }) + print("Installing packer close and reopen Neovim...") + vim.cmd([[packadd packer.nvim]]) +end + +vim.cmd([[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]]) + +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +packer.init({ + display = { + open_fn = function() + return require("packer.util").float({ border = "rounded" }) + end, + }, +}) + +return packer.startup(function(use) + use("wbthomason/packer.nvim") + + -- Plugin Deps + use("nvim-lua/popup.nvim") + use("nvim-lua/plenary.nvim") + use("kyazdani42/nvim-web-devicons") + + -- Themes + use("shaunsingh/nord.nvim") + use("folke/lsp-colors.nvim") + + -- Completion + use("hrsh7th/nvim-cmp") + use("hrsh7th/cmp-buffer") + use("hrsh7th/cmp-path") + use("hrsh7th/cmp-cmdline") + use("saadparwaiz1/cmp_luasnip") + use("hrsh7th/cmp-nvim-lsp") + use("hrsh7th/cmp-nvim-lua") + use("David-Kunz/cmp-npm") + use("zbirenbaum/copilot-cmp") + + -- Snippets + use("L3MON4D3/LuaSnip") + use("rafamadriz/friendly-snippets") + + -- LSP + use("neovim/nvim-lspconfig") + use("williamboman/mason.nvim") + use("jose-elias-alvarez/null-ls.nvim") + use("b0o/SchemaStore.nvim") + use("ray-x/lsp_signature.nvim") + -- use("github/copilot.vim") -- ENABLE ON FIRST TIME ONLY! + use("zbirenbaum/copilot.lua") + + -- Trouble + use("folke/trouble.nvim") + + -- Telescope + use("nvim-telescope/telescope.nvim") + use({ "nvim-telescope/telescope-fzf-native.nvim", run = "make" }) + use("nvim-telescope/telescope-dap.nvim") + + -- Treesitter + use({ "nvim-treesitter/nvim-treesitter", run = ":TSUpdate" }) + use("p00f/nvim-ts-rainbow") + use("JoosepAlviste/nvim-ts-context-commentstring") + + -- Autopairs + use("windwp/nvim-autopairs") + + -- Comments + use("numToStr/Comment.nvim") + + -- Git + use("lewis6991/gitsigns.nvim") + + -- Nvim-Tree + use("kyazdani42/nvim-tree.lua") + + -- Bufferline + use("akinsho/bufferline.nvim") + use("moll/vim-bbye") + + -- Whitespace + use("ntpeters/vim-better-whitespace") + + -- Lualine + use("nvim-lualine/lualine.nvim") + + -- Toggleterm + use("akinsho/toggleterm.nvim") + + -- Impatient + use("lewis6991/impatient.nvim") + + -- Indent Line + use("lukas-reineke/indent-blankline.nvim") + + -- Alpha + use("goolord/alpha-nvim") + + -- WhichKey + use("folke/which-key.nvim") + + -- Illuminate + use("RRethy/vim-illuminate") + + -- Colorizer + use("norcalli/nvim-colorizer.lua") + + -- Navic + use("SmiteshP/nvim-navic") + + -- Wakatime + use("wakatime/vim-wakatime") + + -- Discord + use("andweeb/presence.nvim") + + -- DAP + use("mfussenegger/nvim-dap") + use("rcarriga/nvim-dap-ui") + use("theHamsta/nvim-dap-virtual-text") + + -- Spectre + use("windwp/nvim-spectre") + + -- Notify + use("rcarriga/nvim-notify") + + -- Markdown Preview + use({ + "iamcco/markdown-preview.nvim", + run = function() + vim.fn["mkdp#util#install"]() + end, + }) + + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/lua/user/spectre.lua b/lua/user/spectre.lua new file mode 100644 index 0000000..4e5f59d --- /dev/null +++ b/lua/user/spectre.lua @@ -0,0 +1,9 @@ +local status_ok, spectre = pcall(require, "spectre") +if not status_ok then + return +end + +spectre.setup({ + live_update = true, + is_insert_mode = true, +}) diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua new file mode 100644 index 0000000..1cce2b9 --- /dev/null +++ b/lua/user/telescope.lua @@ -0,0 +1,76 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end + +telescope.load_extension("fzf") +telescope.load_extension("dap") + +local actions = require("telescope.actions") + +telescope.setup({ + defaults = { + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.close, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.complete_tag, + [""] = actions.which_key, + }, + n = { + [""] = actions.close, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + ["?"] = actions.which_key, + }, + }, + }, + pickers = {}, + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "ignore_case", + }, + }, +}) diff --git a/lua/user/toggleterm.lua b/lua/user/toggleterm.lua new file mode 100644 index 0000000..a12e361 --- /dev/null +++ b/lua/user/toggleterm.lua @@ -0,0 +1,27 @@ +local status_ok, toggleterm = pcall(require, "toggleterm") +if not status_ok then + return +end + +toggleterm.setup({ + size = 20, + open_mapping = [[]], + hide_numbers = true, + shade_filetypes = {}, + shade_terminals = true, + shading_factor = 2, + start_in_insert = true, + insert_mappings = true, + persist_size = true, + direction = "float", + close_on_exit = true, + shell = vim.o.shell, + float_opts = { + border = "curved", + winblend = 0, + highlights = { + border = "Normal", + background = "Normal", + }, + }, +}) diff --git a/lua/user/treesitter.lua b/lua/user/treesitter.lua new file mode 100644 index 0000000..68e1021 --- /dev/null +++ b/lua/user/treesitter.lua @@ -0,0 +1,22 @@ +local configs = require("nvim-treesitter.configs") +configs.setup({ + ensure_installed = "all", + sync_install = false, + ignore_install = { "" }, + highlight = { + enable = true, + disable = { "" }, + additional_vim_regex_highlighting = true, + }, + rainbow = { + enable = true, + }, + autopairs = { + enable = true, + }, + context_commentstring = { + enable = true, + enable_autocmd = false, + }, + indent = { enable = true, disable = { "yaml" } }, +}) diff --git a/lua/user/trouble.lua b/lua/user/trouble.lua new file mode 100644 index 0000000..f92d2cc --- /dev/null +++ b/lua/user/trouble.lua @@ -0,0 +1,6 @@ +local status_ok, trouble = pcall(require, "trouble") +if not status_ok then + return +end + +trouble.setup({}) diff --git a/lua/user/whichkey.lua b/lua/user/whichkey.lua new file mode 100644 index 0000000..d63b00b --- /dev/null +++ b/lua/user/whichkey.lua @@ -0,0 +1,6 @@ +local status_ok, which_key = pcall(require, "which-key") +if not status_ok then + return +end + +which_key.setup({}) diff --git a/lua/user/whitespace.lua b/lua/user/whitespace.lua new file mode 100644 index 0000000..d9d2c5a --- /dev/null +++ b/lua/user/whitespace.lua @@ -0,0 +1,15 @@ +vim.g.better_whitespace_enabled = 1 +vim.g.strip_whitespace_on_save = 1 +vim.g.show_spaces_that_precede_tabs = 1 +vim.g.strip_whitelines_at_eof = 1 +vim.g.better_whitespace_filetypes_blacklist = { + "diff", + "git", + "gitcommit", + "unite", + "qf", + "help", + "markdown", + "fugitive", + "toggleterm", +} diff --git a/lua/user/winbar.lua b/lua/user/winbar.lua new file mode 100644 index 0000000..43ae000 --- /dev/null +++ b/lua/user/winbar.lua @@ -0,0 +1,64 @@ +local M = {} + +local navic = require("nvim-navic") + +local function get_buf_option(opt) + local status_ok, buf_option = pcall(vim.api.nvim_buf_get_option, 0, opt) + if not status_ok then + return nil + else + return buf_option + end +end + +local function is_empty(s) + return s == nil or s == "" +end + +M.winbar_filetype_exclude = { + "help", + "startify", + "dashboard", + "packer", + "neogitstatus", + "NvimTree", + "Trouble", + "alpha", + "lir", + "Outline", + "spectre_panel", + "toggleterm", +} + +local excludes = function() + if vim.tbl_contains(M.winbar_filetype_exclude, vim.bo.filetype) then + vim.opt_local.winbar = nil + return true + end + return false +end + +local function get_filename() + return "%#WinBarFilename#" .. "%t" .. "%*" +end + +local function get_location() + local location = navic.get_location() + if not is_empty(location) then + return "%#WinBarContext#" .. " " .. ">" .. " " .. location .. "%*" + end + return "" +end + +function M.get_winbar() + if excludes() then + return "" + end + if navic.is_available() then + return get_filename() .. get_location() + else + return get_filename() + end +end + +return M