From 83a6862734024b61088b5bd20747e352241e921e Mon Sep 17 00:00:00 2001 From: Devin Lumley <2636402+devinwl@users.noreply.github.com> Date: Tue, 22 Nov 2022 18:25:35 -0800 Subject: [PATCH] Update nvim config. --- nvim/init.lua | 6 +- nvim/lua/dwl/init.lua | 2 +- nvim/lua/dwl/lsp_config.lua | 10 ++- nvim/lua/dwl/mappings.lua | 12 ++- nvim/lua/dwl/plugin-conf/completion.lua | 11 +-- nvim/lua/dwl/plugin-conf/lualine.lua | 98 +++++++++++++++++++++++++ nvim/lua/dwl/plugin-conf/telescope.lua | 21 ++++++ nvim/lua/dwl/plugins.lua | 22 +++++- 8 files changed, 171 insertions(+), 11 deletions(-) create mode 100644 nvim/lua/dwl/plugin-conf/lualine.lua create mode 100644 nvim/lua/dwl/plugin-conf/telescope.lua diff --git a/nvim/init.lua b/nvim/init.lua index 71d9257..082685e 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -64,4 +64,8 @@ vim.opt.cursorline = true -- hightlight line cursor is on vim.opt.ignorecase = true -- case insensitive search... vim.opt.smartcase = true -- unless I use caps vim.opt.hlsearch = true -- highlight matching text -vim.opt.incsearch = true -- update results while I type \ No newline at end of file +vim.opt.incsearch = true -- update results while I type + +-- Better Netrw +vim.g.netrw_banner = 0 -- Hide banner +vim.g.netrw_list_hide = (vim.fn["netrw_gitignore#Hide"]()) .. [[,\(^\|\s\s\)\zs\.\S\+]] -- use .gitignore diff --git a/nvim/lua/dwl/init.lua b/nvim/lua/dwl/init.lua index beecf67..8f8299c 100644 --- a/nvim/lua/dwl/init.lua +++ b/nvim/lua/dwl/init.lua @@ -3,4 +3,4 @@ local no_plugins = require("dwl.plugins") -- plugins require("dwl.mappings") -- keymaps if no_plugins then return end require("dwl.lsp_config") -- LSP configs -require("dwl.treesitter") -- treesitter configs \ No newline at end of file +require("dwl.treesitter") -- treesitter configs diff --git a/nvim/lua/dwl/lsp_config.lua b/nvim/lua/dwl/lsp_config.lua index c18a367..2601d19 100644 --- a/nvim/lua/dwl/lsp_config.lua +++ b/nvim/lua/dwl/lsp_config.lua @@ -12,6 +12,8 @@ local lsp_filetypes = { -- "lua", } +local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } + -- Give floating windows borders vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "rounded" }) @@ -23,7 +25,8 @@ vim.diagnostic.config({ -- Prepend with diagnostic source if there is more than one attached to the buffer -- (e.g. (eslint) Error: blah blah blah) source = "if_many", - signs = false, + spacing = 4, + prefix = "●", }, float = { severity_sort = true, @@ -281,6 +284,11 @@ lspconfig.yamlls.setup({ -- on_attach = custom_attach, -- }) +for type, icon in pairs(signs) do + local hl = "DiagnosticSign" .. type + vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = "" }) +end + return { lsp_filetypes = lsp_filetypes, } diff --git a/nvim/lua/dwl/mappings.lua b/nvim/lua/dwl/mappings.lua index bc80365..3793ed9 100644 --- a/nvim/lua/dwl/mappings.lua +++ b/nvim/lua/dwl/mappings.lua @@ -11,6 +11,16 @@ mapper("n", "gd", ":vs | lua vim.lsp.buf.definition()") -- open defn in a ne if no_plugins then return end +-- Telescope integration local telescope_builtin = require("telescope.builtin") -mapper("n", "", telescope_builtin.find_files) -- search all files, respecting .gitignore if one exists \ No newline at end of file +mapper("n", "ff", telescope_builtin.find_files) -- search all files, respecting .gitignore if one exists +mapper("n", "fb", telescope_builtin.buffers) -- search open buffers +mapper("n", "fl", telescope_builtin.current_buffer_fuzzy_find) -- search lines in current buffer +mapper("n", "gg", telescope_builtin.live_grep) -- search all lines in project +mapper("n", "fr", telescope_builtin.lsp_references) -- search references to symbol under cursor +mapper("n", "gc", telescope_builtin.git_branches) -- checkout different branches + +-- Git things +mapper("n", "gs", ":vs Git") -- `git status` in a new tab to save screen real estate +mapper("n", "gd", "Gdiffsplit") -- open a split diffing the current file diff --git a/nvim/lua/dwl/plugin-conf/completion.lua b/nvim/lua/dwl/plugin-conf/completion.lua index 06b5b9f..6d38aef 100644 --- a/nvim/lua/dwl/plugin-conf/completion.lua +++ b/nvim/lua/dwl/plugin-conf/completion.lua @@ -3,6 +3,7 @@ local cmp_autopairs = require('nvim-autopairs.completion.cmp') if not cmp then return end cmp.setup({ + preselect = true, snippet = { expand = function(args) vim.fn["vsnip#anonymous"](args.body) end, }, @@ -18,13 +19,13 @@ cmp.setup({ [""] = cmp.mapping.scroll_docs(-4), [""] = cmp.mapping.scroll_docs(4), [""] = cmp.mapping.complete({ reason = cmp.ContextReason.Manual }), - [""] = cmp.mapping.close(), - [""] = cmp.mapping.confirm({ + [""] = cmp.mapping.close(), + [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = true, -- use first result if none explicitly selected }), - -- [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), - -- [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }), + [""] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }), }), preselect = cmp.PreselectMode.None, formatting = { @@ -45,4 +46,4 @@ cmp.setup({ native_menu = false, ghost_text = true, }, -}) \ No newline at end of file +}) diff --git a/nvim/lua/dwl/plugin-conf/lualine.lua b/nvim/lua/dwl/plugin-conf/lualine.lua new file mode 100644 index 0000000..2bb0a41 --- /dev/null +++ b/nvim/lua/dwl/plugin-conf/lualine.lua @@ -0,0 +1,98 @@ +local lualine = require("lualine") + +local IS_WIDE = function() return vim.o.columns > 150 end + +lualine.setup({ + sections = { + --+-------------------------------------------------+-- + --| A | B | C X | Y | Z |-- + --+-------------------------------------------------+-- + lualine_a = { + { + "mode", + fmt = function(m) return IS_WIDE() and m or m:sub(1, 1) end, + }, + }, + lualine_b = { "branch" }, + lualine_c = { + { + "diff", + symbols = { + modified = "~", + removed = "-", + added = "+", + }, + }, + -- A hack to change the path type if the window gets too short. Lualine doesn't accept a function for the + -- `path` option, so just swap out the entire component + { + "filename", + path = 1, -- full file path + color = { fg = "#ffffff", gui = "bold" }, + shorting_target = 30, + cond = IS_WIDE, + }, + { + "filename", + path = 0, -- just the filename + color = { fg = "#ffffff", gui = "bold" }, + shorting_target = 30, + cond = function() return not IS_WIDE() end, + }, + }, + lualine_x = { + { + function() + local msg = "No Active Lsp" + local buf_ft = vim.api.nvim_buf_get_option(0, "filetype") + local clients = vim.lsp.get_active_clients() + if next(clients) == nil then return msg end + + local client_names = {} + local active_client = false + for _, client in ipairs(clients) do + local filetypes = client.config.filetypes + if filetypes and vim.fn.index(filetypes, buf_ft) ~= -1 then + active_client = true + if not client_names[client.name] then client_names[client.name] = 1 end + end + end + + if active_client then + local names = {} + for name, _ in pairs(client_names) do + table.insert(names, name) + end + return table.concat(names, ", ") + end + + return "No Active Lsp" + end, + icon = " LSP:", + color = { gui = "bold" }, + cond = IS_WIDE, + }, + { + "diagnostics", + sources = { "nvim_diagnostic" }, + }, + }, + lualine_y = { "filetype" }, + lualine_z = { "location" }, + }, + tabline = {}, + options = { + section_separators = { left = "", right = "" }, + component_separators = { left = "", right = "" }, + theme = "tokyonight", + disabled_filetypes = { "aerial" }, + globalstatus = true, + }, + extensions = { + "aerial", + "fugitive", + "nvim-dap-ui", + "nvim-tree", + "quickfix", + }, +}) diff --git a/nvim/lua/dwl/plugin-conf/telescope.lua b/nvim/lua/dwl/plugin-conf/telescope.lua new file mode 100644 index 0000000..7c4b386 --- /dev/null +++ b/nvim/lua/dwl/plugin-conf/telescope.lua @@ -0,0 +1,21 @@ +local telescope = require("telescope") + +telescope.setup({ + defaults = { + file_ignore_patterns = { + "%.png", + "^index.%", + }, + prompt_prefix = "» ", + selection_caret = " ", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + path_display = { "smart" }, + dynamic_preview_title = true, + layout_config = { + prompt_position = "top", + height = 0.8, + }, + }, +}) diff --git a/nvim/lua/dwl/plugins.lua b/nvim/lua/dwl/plugins.lua index 3085d46..25a8756 100644 --- a/nvim/lua/dwl/plugins.lua +++ b/nvim/lua/dwl/plugins.lua @@ -23,7 +23,7 @@ packer.startup(function(use) -- Essentials use({ "nvim-telescope/telescope.nvim", -- fuzzy find ALL the things - -- config = function() require("dwl.plugin-conf.telescope") end, + config = function() require("dwl.plugin-conf.telescope") end, }) use({ "windwp/nvim-ts-autotag", -- auto close html tags @@ -47,6 +47,24 @@ packer.startup(function(use) }) use("lukas-reineke/indent-blankline.nvim") + -- Look and feel + use({ + "nvim-lualine/lualine.nvim", -- statusline in lua + requires = { + "kyazdani42/nvim-web-devicons", + opt = true, + }, + config = function() require("dwl.plugin-conf.lualine") end, + }) + -- use({ + -- "nvim-tree/nvim-web-devicons", + -- config = function() require('nvim-web-devicons').setup() end, + -- }) + use({ + "petertriho/nvim-scrollbar", + config = function() require("scrollbar").setup() end, + }) + -- LSP & Treesitter use("neovim/nvim-lspconfig") -- basic configurations for LSP client use("jose-elias-alvarez/null-ls.nvim") -- bridge between LSP client and external formatters/linters, not full fledged language servers @@ -91,4 +109,4 @@ packer.startup(function(use) if packer_bootstrap then packer.sync() end end) -return packer_bootstrap \ No newline at end of file +return packer_bootstrap