From 8e1d6b1aaeb6e0f93e8d8c60bbad497809c6ca47 Mon Sep 17 00:00:00 2001 From: spinach <19keegandeppe@gmail.com> Date: Mon, 17 Apr 2023 15:52:34 -0400 Subject: [PATCH] changing file structure and adding harpoon --- config/init.lua | 106 +++++++------------------------------ config/lua/autobuf.lua | 12 +++++ config/lua/calcurse.lua | 7 --- config/lua/fuzzy.lua | 11 ---- config/lua/go.lua | 6 --- config/lua/i3conf.lua | 6 --- config/lua/keymap.lua | 38 ++++++++----- config/lua/lsp.lua | 83 +++++++++++++++++++++++++++++ config/lua/plugins.lua | 57 ++++++++++++++++---- config/lua/spellcheck.lua | 9 ++++ config/lua/transparent.lua | 5 +- config/lua/tree.lua | 40 -------------- 12 files changed, 199 insertions(+), 181 deletions(-) create mode 100644 config/lua/autobuf.lua delete mode 100644 config/lua/calcurse.lua delete mode 100644 config/lua/fuzzy.lua delete mode 100644 config/lua/go.lua delete mode 100644 config/lua/i3conf.lua create mode 100644 config/lua/lsp.lua create mode 100644 config/lua/spellcheck.lua delete mode 100644 config/lua/tree.lua diff --git a/config/init.lua b/config/init.lua index a74bed5..575602b 100644 --- a/config/init.lua +++ b/config/init.lua @@ -1,8 +1,6 @@ require('keymap') require('plugins') -require('calcurse') -require('i3conf') -require('go') +require('autobuf') -- prevent cursor override vim.cmd('set guicursor=') @@ -12,8 +10,6 @@ vim.cmd('set ts=4 sts=4 sw=4 expandtab') -- clipboard vim.cmd('set clipboard+=unnamedplus') -vim.keymap.set('n', 'Y', '"+y') -vim.keymap.set('n', 'P', '"+p') -- hybrid numbering vim.opt.relativenumber = true @@ -52,86 +48,20 @@ vim.cmd([[ \ 'syntax': 'markdown', 'ext':'.md'}] ]]) --- language server setup -local lspconfig = require('lspconfig') - --- Go -lspconfig.gopls.setup{ - cmd = {"gopls", "serve"}, - filetypes = {"go", "gomod"}, - settings = { - gopls = { - analyses = { - unusedparams = true, - }, - staticcheck = true, - }, - }, -} - --- C/C++ -lspconfig.clangd.setup{} - --- Lua -lspconfig.lua_ls.setup{ - settings = { - Lua = { - diagnostics = {globals = {'vim', 'opts'}}, - }, - telemetry = { - enable = false, - }, - }, -} - --- Rust -lspconfig.rust_analyzer.setup{} - --- Python -lspconfig.pylsp.setup{} - --- TypeScript -lspconfig.tsserver.setup{} - --- Fix virtual text going off screen -vim.diagnostic.config({ - virtual_text = false, - signs = true, - underline = true, - update_in_insert = false, - severity_sort = false, -}) - - -vim.api.nvim_create_autocmd('LspAttach', { - callback = function(ev) - -- custom colors - vim.cmd('hi DiagnosticUnderlineError cterm=undercurl guisp=Red') - -- key mappings - local opts = { buffer = ev.buf,} - -- error viewing - vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) - vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) - vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) - -- def viewing/rename - vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) - vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) - vim.keymap.set('n', 'H', vim.lsp.buf.hover, opts) - -- auto hover for error viewing - vim.api.nvim_create_autocmd("CursorHold", { - callback = function() - opts = { - buffer = ev.buf, - focusable = false, - border = 'rounded', - source = 'always', - prefix = ' ', - scope = 'cursor', - close_events = { "BufLeave","CursorMoved","InsertEnter","FocusLost" }, - } - vim.diagnostic.open_float(nil, opts) - end - }) - end, -}) +-- go file settings +vim.g.go_hightlight_types = 1 +vim.g.go_hightlight_fields = 1 +vim.g.go_hightlight_functions = 1 +vim.g.go_hightlight_function_calls = 1 +vim.g.go_hightlight_operators = 1 +vim.g.go_hightlight_extra_types = 1 + +-- airline settings +if vim.g.airline_symbols == nil then + vim.g.airline_symbols = vim.empty_dict() +end + +vim.g.airline_powerline_fonts = 1 +vim.g.airline_symbols.linenr = '' +vim.g.airline_symbols.maxlinenr = '' +vim.g.airline_symbols.dirty = '' diff --git a/config/lua/autobuf.lua b/config/lua/autobuf.lua new file mode 100644 index 0000000..3408b08 --- /dev/null +++ b/config/lua/autobuf.lua @@ -0,0 +1,12 @@ +-- sets autocommands for bufenters etc + +-- recognize i3 files as such +vim.api.nvim_create_autocmd({"BufRead","BufNewFile"}, { + pattern = {"*/i3/*.conf"}, + command = "set filetype=i3config", +}) +-- calcurse -> markdown +vim.api.nvim_create_autocmd({"BufRead","BufNewFile"}, { + pattern = {"/tmp/calcurse*","~/.local/share/calcurse/notes/*"}, + command = "set filetype=markdown", +}) diff --git a/config/lua/calcurse.lua b/config/lua/calcurse.lua deleted file mode 100644 index c27546d..0000000 --- a/config/lua/calcurse.lua +++ /dev/null @@ -1,7 +0,0 @@ --- calcurse -> markdown -vim.api.nvim_create_autocmd({"BufRead","BufNewFile"}, { - pattern = {"/tmp/calcurse*","~/.local/share/calcurse/notes/*"}, - command = "set filetype=markdown", -}) - - diff --git a/config/lua/fuzzy.lua b/config/lua/fuzzy.lua deleted file mode 100644 index c9e5477..0000000 --- a/config/lua/fuzzy.lua +++ /dev/null @@ -1,11 +0,0 @@ -require('telescope').setup({ - defaults = { - layout_config = { - horizontal = { width = 0.5 } - }, - }, -}) - -local builtin = require('telescope.builtin') -vim.keymap.set('n','f', builtin.find_files, {}) -vim.keymap.set('n','s', builtin.spell_suggest, {}) diff --git a/config/lua/go.lua b/config/lua/go.lua deleted file mode 100644 index 7165a05..0000000 --- a/config/lua/go.lua +++ /dev/null @@ -1,6 +0,0 @@ -vim.g.go_hightlight_types = 1 -vim.g.go_hightlight_fields = 1 -vim.g.go_hightlight_functions = 1 -vim.g.go_hightlight_function_calls = 1 -vim.g.go_hightlight_operators = 1 -vim.g.go_hightlight_extra_types = 1 diff --git a/config/lua/i3conf.lua b/config/lua/i3conf.lua deleted file mode 100644 index dd69d68..0000000 --- a/config/lua/i3conf.lua +++ /dev/null @@ -1,6 +0,0 @@ --- recognize i3 config from dotfiles --- -vim.api.nvim_create_autocmd({"BufRead","BufNewFile"}, { - pattern = {"*/i3/*.conf"}, - command = "set filetype=i3config", -}) diff --git a/config/lua/keymap.lua b/config/lua/keymap.lua index b90458b..9a4174e 100644 --- a/config/lua/keymap.lua +++ b/config/lua/keymap.lua @@ -1,5 +1,3 @@ -require("transparent") - vim.g.mapleader = " " vim.keymap.set("n", "b", ":lua ToggleTransparent()") @@ -10,15 +8,6 @@ vim.keymap.set("n", "t", ":NvimTreeToggle") vim.keymap.set("n", "a", ":lua SpellToggle()") --- toggle spell check -function SpellToggle() - if vim.o.spell == nil or vim.o.spell then - vim.o.spell = false - else - vim.o.spell = true - end -end - -- markdown preview vim.keymap.set("n", "p", ":MarkdownPreviewToggle") @@ -35,4 +24,29 @@ vim.g.mkdp_browserfunc = 'OpenMarkdownPreview' -- git actions vim.keymap.set("n", "ga", ":Git add .") vim.keymap.set("n", "gm", ":Git commit") - + +-- fuzzy finder keybindings +local telescope = require('telescope.builtin') +vim.keymap.set('n','f', telescope.find_files, {}) +vim.keymap.set('n','s', telescope.spell_suggest, {}) + +-- global copy/paste +vim.keymap.set('n', 'yg', '"+y') +vim.keymap.set('n', 'pg', '"+p') + +-- toggle dotfiles visibility +vim.keymap.set("n", "d", ":lua require('nvim-tree.api').tree.toggle_hidden_filter()") + +-- harpoon bindings +local harpoon = require('harpoon.ui') + +vim.keymap.set("n", "hh", ":Telescope harpoon marks") +vim.keymap.set("n", "ha", harpoon.add_file, {}) +vim.keymap.set("n", "hn", harpoon.nav_next, {}) +vim.keymap.set("n", "hp", harpoon.nav_prev, {}) +-- jumping to specific files +vim.keymap.set("n", "h1", harpoon.nav_file, {1}) +vim.keymap.set("n", "h2", harpoon.nav_file, {2}) +vim.keymap.set("n", "h3", harpoon.nav_file, {3}) +vim.keymap.set("n", "h4", harpoon.nav_file, {4}) +vim.keymap.set("n", "h5", harpoon.nav_file, {5}) diff --git a/config/lua/lsp.lua b/config/lua/lsp.lua new file mode 100644 index 0000000..c504d18 --- /dev/null +++ b/config/lua/lsp.lua @@ -0,0 +1,83 @@ +-- language server setup +local lspconfig = require('lspconfig') + +-- Go +lspconfig.gopls.setup{ + cmd = {"gopls", "serve"}, + filetypes = {"go", "gomod"}, + settings = { + gopls = { + analyses = { + unusedparams = true, + }, + staticcheck = true, + }, + }, +} + +-- C/C++ +lspconfig.clangd.setup{} + +-- Lua +lspconfig.lua_ls.setup{ + settings = { + Lua = { + diagnostics = {globals = {'vim', 'opts'}}, + }, + telemetry = { + enable = false, + }, + }, +} + +-- Rust +lspconfig.rust_analyzer.setup{} + +-- Python +lspconfig.pylsp.setup{} + +-- TypeScript +lspconfig.tsserver.setup{} + +-- Fix virtual text going off screen +vim.diagnostic.config({ + virtual_text = false, + signs = true, + underline = true, + update_in_insert = false, + severity_sort = false, +}) + + +vim.api.nvim_create_autocmd('LspAttach', { + callback = function(ev) + -- custom colors + --vim.cmd('hi DiagnosticUnderlineError cterm=undercurl guisp=Red') + -- key mappings + local opts = { buffer = ev.buf,} + -- error viewing + vim.keymap.set('n', 'e', vim.diagnostic.open_float, opts) + vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) + vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts) + -- def viewing/rename + vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts) + vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, opts) + vim.keymap.set('n', 'H', vim.lsp.buf.hover, opts) + -- auto hover for error viewing + vim.api.nvim_create_autocmd("CursorHold", { + callback = function() + opts = { + buffer = ev.buf, + focusable = false, + border = 'rounded', + source = 'always', + prefix = ' ', + scope = 'cursor', + close_events = { "BufLeave","CursorMoved","InsertEnter","FocusLost" }, + } + vim.diagnostic.open_float(nil, opts) + end + }) + end, +}) diff --git a/config/lua/plugins.lua b/config/lua/plugins.lua index f093942..288d698 100644 --- a/config/lua/plugins.lua +++ b/config/lua/plugins.lua @@ -1,13 +1,52 @@ -require('tree') -require('fuzzy') +require('lsp') +require('transparent') +require('spellcheck') --- airline settings -if vim.g.airline_symbols == nil then - vim.g.airline_symbols = vim.empty_dict() +-- nvim tree setup +require('nvim-tree').setup({ + open_on_tab = false, + filters = { + dotfiles = true, + }, + actions = { + open_file = { + quit_on_open = true, + }, + }, +}) + +showHiddenFiles = false + +local function open_nvim_tree(data) + + -- buffer is a directory + local directory = vim.fn.isdirectory(data.file) == 1 + + local empty_file = data.file == "" + + if not directory and not empty_file then + return + end + + if directory then + vim.cmd.cd(data.file) + end + vim.cmd.enew() + vim.cmd.bw(data.buf) + -- change to directory and open + require("nvim-tree.api").tree.open() end -vim.g.airline_powerline_fonts = 1 -vim.g.airline_symbols.linenr = '' -vim.g.airline_symbols.maxlinenr = '' -vim.g.airline_symbols.dirty = '' +-- nvim-tree open at startup +vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree, }) + +-- fuzzy finder setup +require('telescope').setup({ + defaults = { + layout_config = { + horizontal = { width = 0.5 } + }, + }, +}) +require.('telescope).load_extension('harpoon') diff --git a/config/lua/spellcheck.lua b/config/lua/spellcheck.lua new file mode 100644 index 0000000..481a0d1 --- /dev/null +++ b/config/lua/spellcheck.lua @@ -0,0 +1,9 @@ +-- simple spell check toggle + +function SpellToggle() + if vim.o.spell == nil or vim.o.spell then + vim.o.spell = false + else + vim.o.spell = true + end +end diff --git a/config/lua/transparent.lua b/config/lua/transparent.lua index 0c8991a..3cb9246 100644 --- a/config/lua/transparent.lua +++ b/config/lua/transparent.lua @@ -1,9 +1,10 @@ +-- allows for toggling of background function ToggleTransparent() Transparent = not Transparent if Transparent then vim.cmd("hi Normal ctermbg=NONE") else - vim.cmd("set background=dark") - vim.cmd("syntax enable") + -- 234 is hybrid dark bg color + vim.cmd("hi Normal ctermbg=234") end end diff --git a/config/lua/tree.lua b/config/lua/tree.lua deleted file mode 100644 index 85e6479..0000000 --- a/config/lua/tree.lua +++ /dev/null @@ -1,40 +0,0 @@ -require('nvim-tree').setup({ - open_on_tab = false, - filters = { - dotfiles = true, - }, - actions = { - open_file = { - quit_on_open = true, - }, - }, -}) - -showHiddenFiles = false - -local function open_nvim_tree(data) - - -- buffer is a directory - local directory = vim.fn.isdirectory(data.file) == 1 - - local empty_file = data.file == "" - - if not directory and not empty_file then - return - end - - if directory then - vim.cmd.cd(data.file) - end - vim.cmd.enew() - vim.cmd.bw(data.buf) - -- change to directory and open - require("nvim-tree.api").tree.open() -end - --- toggle dotfiles visibility -vim.keymap.set("n", "d", ":lua require('nvim-tree.api').tree.toggle_hidden_filter()") - --- nvim-tree open at startup -vim.api.nvim_create_autocmd({ "VimEnter" }, { callback = open_nvim_tree, }) -