From cf9f11f294db8c9e4761a2d54b4e49fdf5d06112 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Sat, 10 Dec 2022 16:34:30 -0800 Subject: [PATCH] split up to functions by file --- .config/nvim/after/plugin/teej.lua | 1 - .config/nvim/init.lua | 255 ++++------------------------- 2 files changed, 31 insertions(+), 225 deletions(-) delete mode 100644 .config/nvim/after/plugin/teej.lua diff --git a/.config/nvim/after/plugin/teej.lua b/.config/nvim/after/plugin/teej.lua deleted file mode 100644 index 4e02f12..0000000 --- a/.config/nvim/after/plugin/teej.lua +++ /dev/null @@ -1 +0,0 @@ -TJ = true diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 4ab5453..3841838 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,25 +1,35 @@ -vim.o.ma = true -vim.o.mouse = a -vim.o.cursorline = true -vim.o.tabstop = 4 -vim.o.shiftwidth = 4 -vim.o.softtabstop = 4 -vim.o.expandtab = true -vim.o.autoread = true -vim.o.nu = true -vim.o.foldlevelstart = 99 -vim.o.scrolloff = 7 -vim.o.backup = false -vim.o.writebackup = false -vim.o.swapfile = false --- use y and p with the system clipboard -vim.opt.clipboard = "unnamedplus" -vim.g.mapleader = " " +-- vim.g.mapleader = " " +-- vim.g.glow_binary_path = vim.env.HOME .. "/bin" +-- vim.g.glow_use_pager = true +-- vim.g.glow_border = "shadow" + + +local globals = { + mapleader = " ", + glow_binary_path = vim.env.HOME .. "/bin", + glow_use_pager = true, + glow_border = "shadow", +} + +for k, v in pairs(globals) do + vim.g[k] = v +end + +-- Aesthetic +-- pcall catches errors if the plugin doesn't load +local ok, catppuccin = pcall(require, "catppuccin") +if not ok then return end +vim.g.catppuccin_flavour = "macchiato" +catppuccin.setup() +vim.cmd[[colorscheme catppuccin]] + +require('me.options') +require('me.lualine') +require('me.lsp') +require('me.telescope') local keymap = function(tbl) - -- Some sane default options local opts = { noremap = true, silent = true } - -- Dont want these named fields on the options table local mode = tbl['mode'] tbl['mode'] = nil local bufnr = tbl['bufnr'] @@ -31,7 +41,6 @@ local keymap = function(tbl) end end - if bufnr ~= nil then vim.api.nvim_buf_set_keymap(bufnr, mode, tbl[1], tbl[2], opts) else @@ -39,33 +48,22 @@ local keymap = function(tbl) end end -local nmap = function(tbl) +nmap = function(tbl) tbl['mode'] = 'n' keymap(tbl) end -local imap = function(tbl) +imap = function(tbl) tbl['mode'] = 'i' keymap(tbl) end --- Aesthetic --- pcall catches errors if the plugin doesn't load -local ok, catppuccin = pcall(require, "catppuccin") -if not ok then return end -vim.g.catppuccin_flavour = "macchiato" -catppuccin.setup() -vim.cmd[[colorscheme catppuccin]] - local ok, treesitter = pcall(require, "nvim-treesitter.configs") if not ok then return end treesitter.setup { ensure_installed = "all", highlight = { enable = true } } -- keymaps -vim.g.glow_binary_path = vim.env.HOME .. "/bin" -vim.g.glow_use_pager = true -vim.g.glow_border = "shadow" vim.keymap.set("n", "p", "Glow") nmap{"", "Telescope current_buffer_fuzzy_find sorting_strategy=ascending prompt_position=top"} nmap{"lg", "Telescope live_grep"} @@ -74,195 +72,4 @@ nmap{"dl", "Telescope diagnostics"} -- navigation nmap{"L", "bnext"} nmap{"H", "bprevious"} -nmap{"J", "tabNext"} -nmap{"K", "tabPrevious"} nmap{"F", "HopPattern"} - --- Native LSP Setup --- Global setup. -local cmp = require'cmp' -cmp.setup({ -snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) -- For `luasnip` users. - end, -}, - mapping = { - [''] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }), - [''] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }), - [''] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - -- Accept currently selected item. If none selected, `select` first item. - -- Set `select` to `false` to only confirm explicitly selected items. - [''] = cmp.mapping.confirm({ select = true }), - }, - sources = cmp.config.sources({ - { name = 'nvim_lsp' }, - { name = 'luasnip' }, -- For luasnip users. - }, { - { name = 'buffer' }, - }) -}) - -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) - --- Use an on_attach function to only map the following keys --- after the language server attaches to the current buffer -local lsp_installer = require("nvim-lsp-installer") -lsp_installer.settings({ - ui = { - icons = { - server_installed = "✓", - server_pending = "➜", - server_uninstalled = "✗" - } - } -}) - -local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) -local on_attach = function(client, bufnr) - - local function buf_set_keymap(...) - vim.api.nvim_buf_set_keymap(bufnr, ...) - end - - -- Mappings. - local opts = { noremap = true, silent = true } - - -- See `:help vim.lsp.*` for documentation on any of the below functions - -- leaving only what I actually use... - buf_set_keymap("n", "gd", "Telescope lsp_definitions", opts) - buf_set_keymap("n", "gr", "Telescope lsp_references", opts) - - buf_set_keymap("n", "", "Telescope lsp_document_symbols", opts) - buf_set_keymap("n", "", "lua vim.lsp.buf.signature_help()", opts) - - buf_set_keymap("n", "gi", "Telescope lsp_implementations", opts) - buf_set_keymap("n", "K", "lua vim.lsp.buf.hover()", opts) - buf_set_keymap("n", "D", "Telescope lsp_type_definitions", opts) - buf_set_keymap("n", "rn", "lua vim.lsp.buf.rename()", opts) - buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) - buf_set_keymap("n", "gt", "lua vim.lsp.buf.type_definition()", opts) - buf_set_keymap("n", "gi", "lua vim.lsp.buf.implementation()", opts) - buf_set_keymap("n", "dj", "lua vim.diagnostic.goto_next()", opts) - buf_set_keymap("n", "dk", "lua vim.diagnostic.goto_prev()", opts) - buf_set_keymap("n", "r", "lua vim.lsp.buf.rename()", opts) - - vim.cmd([[ - augroup formatting - autocmd! * - autocmd BufWritePre lua vim.lsp.buf.formatting_seq_sync() - autocmd BufWritePre lua OrganizeImports(1000) - augroup END - ]]) - - -- Set autocommands conditional on server_capabilities - vim.cmd([[ - augroup lsp_document_highlight - autocmd! * - autocmd CursorHold lua vim.lsp.buf.document_highlight() - autocmd CursorMoved lua vim.lsp.buf.clear_references() - augroup END - ]]) -end - -lsp_installer.setup{} -local lspconfig = require('lspconfig') -lspconfig.gopls.setup { - capabilities = capabilities, - on_attach = on_attach, - settings = { - gopls = { - gofumpt = true, - }, - }, - flags = { - debounce_text_changes = 150, - }, -} - -lspconfig.golangci_lint_ls.setup { - capabilities = capabilities, - on_attach = on_attach, - settings = { - gopls = { - gofumpt = true, - }, - }, - flags = { - debounce_text_changes = 150, - }, -} - --- organize imports --- https://github.com/neovim/nvim-lspconfig/issues/115#issuecomment-902680058 -function OrganizeImports(timeoutms) - local params = vim.lsp.util.make_range_params() - params.context = { only = { "source.organizeImports" } } - local result = vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, timeoutms) - for _, res in pairs(result or {}) do - for _, r in pairs(res.result or {}) do - if r.edit then - vim.lsp.util.apply_workspace_edit(r.edit, "UTF-8") - else - vim.lsp.buf.execute_command(r.command) - end - end - end -end - --- lualine -require('lualine').setup{ - options = { - theme = 'auto', - }, - sections = { - lualine_a = {'mode'}, - lualine_b = {'branch', 'diff'}, - lualine_c = {'buffers'}, - lualine_x = {'tabs'}, - lualine_y = {'progress'}, - lualine_z = { - 'diagnostics', - sources = {'nvim_diagnostic', 'nvim_lsp'}, - sections = {'error', 'warn', 'info', 'hint'}, - diagnostics_color = { - -- Same values as the general color option can be used here. - error = 'DiagnosticError', -- Changes diagnostics' error color. - warn = 'DiagnosticWarn', -- Changes diagnostics' warn color. - info = 'DiagnosticInfo', -- Changes diagnostics' info color. - hint = 'DiagnosticHint', -- Changes diagnostics' hint color. - }, - symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}, - colored = true, -- Displays diagnostics status in color if set to true. - update_in_insert = false, -- Update diagnostics in insert mode. - always_visible = false, -- Show diagnostics even if there are none. - }, - } -} - --- Telescope Setup -local action_state = require('telescope.actions.state') -- runtime (Plugin) exists somewhere as lua/telescope/actions/state.lua -require('telescope').setup{ - defaults = { - prompt_prefix = "$ ", - mappings = { - i = { - [""] = function() print(vim.inspect(action_state.get_selected_entry())) end - } - } - } -} -require('telescope').load_extension('fzf') -require('telescope').load_extension('file_browser') - -local mappings = { -} -mappings.curr_buf = function() - local opt = require('telescope.themes').get_dropdown({height=10, previewer=false}) - require('telescope.builtin').current_buffer_fuzzy_find(opt) -end -return mappings