From ebb0a5aeed219a80b08cf4f10d6d957d85f5c634 Mon Sep 17 00:00:00 2001 From: Rahsheen Porter Date: Sun, 3 Mar 2024 11:26:12 -0500 Subject: [PATCH] recovering custom nvim configs --- after/plugin/defaults.lua | 2 + after/plugin/fugitive.lua | 21 ++++++++++ after/plugin/git-worktree.lua | 22 ++++++++++ after/plugin/lualine.lua | 13 ++++++ after/plugin/null-ls.lua | 75 +++++++++++++++++++++++++++++++++++ after/plugin/telescope.lua | 2 + lua/custom/plugins/init.lua | 73 +++++++++++++++++++++++++++++++--- lua/rahcodes/keymap.lua | 20 ++++++++++ lua/rahcodes/remap.lua | 69 ++++++++++++++++++++++++++++++++ lua/rahcodes/sets.lua | 26 ++++++++++++ lua/rahcodes/solargraph.lua | 22 ++++++++++ 11 files changed, 340 insertions(+), 5 deletions(-) create mode 100644 after/plugin/defaults.lua create mode 100644 after/plugin/fugitive.lua create mode 100644 after/plugin/git-worktree.lua create mode 100644 after/plugin/lualine.lua create mode 100644 after/plugin/null-ls.lua create mode 100644 after/plugin/telescope.lua create mode 100644 lua/rahcodes/keymap.lua create mode 100644 lua/rahcodes/remap.lua create mode 100644 lua/rahcodes/sets.lua create mode 100644 lua/rahcodes/solargraph.lua diff --git a/after/plugin/defaults.lua b/after/plugin/defaults.lua new file mode 100644 index 00000000..dd0ba5b2 --- /dev/null +++ b/after/plugin/defaults.lua @@ -0,0 +1,2 @@ +require("rahcodes.remap") +require("rahcodes.sets") diff --git a/after/plugin/fugitive.lua b/after/plugin/fugitive.lua new file mode 100644 index 00000000..e448b76e --- /dev/null +++ b/after/plugin/fugitive.lua @@ -0,0 +1,21 @@ +vim.keymap.set("n", "gs", ":G") +vim.keymap.set("n", "gh", ":diffget //3") +vim.keymap.set("n", "gu", ":diffget //2") +vim.keymap.set("n", "gc", ":GCheckout") +vim.keymap.set("n", "ga", ":G add %:p") +vim.keymap.set("n", "gc", ":G commit -v -q") +vim.keymap.set("n", "gt", ":G commit -v -q %:p") +vim.keymap.set("n", "gff", ":G ff") +vim.keymap.set("n", "gfo", ":G fetch origin") +vim.keymap.set("n", "gd", ":Gdiff") +vim.keymap.set("n", "ge", ":Gedit") +vim.keymap.set("n", "gr", ":Gread") +vim.keymap.set("n", "grb", ":G rebase -i") +vim.keymap.set("n", "gw", ":Gwrite") +vim.keymap.set("n", "gl", ":silent! Glog:bot copen") +vim.keymap.set("n", "gp", ":Ggrep") +vim.keymap.set("n", "gm", ":Gmove") +vim.keymap.set("n", "gbl", ":G blame") +vim.keymap.set("n", "go", ":G checkout") +vim.keymap.set("n", "gps", ":Dispatch! git push") +vim.keymap.set("n", "gpl", ":Dispatch! git pull") diff --git a/after/plugin/git-worktree.lua b/after/plugin/git-worktree.lua new file mode 100644 index 00000000..9e70aa36 --- /dev/null +++ b/after/plugin/git-worktree.lua @@ -0,0 +1,22 @@ +local Worktree = require("git-worktree") + +-- op = Operations.Switch, Operations.Create, Operations.Delete +-- metadata = table of useful values (structure dependent on op) +-- Switch +-- path = path you switched to +-- prev_path = previous worktree path +-- Create +-- path = path where worktree created +-- branch = branch name +-- upstream = upstream remote name +-- Delete +-- path = path where worktree deleted + +Worktree.on_tree_change(function(op, metadata) + if op == Worktree.Operations.Switch then + print("Switched from " .. metadata.prev_path .. " to " .. metadata.path) + end +end) + +vim.keymap.set("n", "bw", require("telescope").extensions.git_worktree.git_worktrees, { desc = "[B]rowse Git Worktrees" }) +vim.keymap.set("n", "cw", require("telescope").extensions.git_worktree.create_git_worktree, { desc = "[C]reate Git [W]orktree" }) diff --git a/after/plugin/lualine.lua b/after/plugin/lualine.lua new file mode 100644 index 00000000..1e3a426e --- /dev/null +++ b/after/plugin/lualine.lua @@ -0,0 +1,13 @@ +require("lualine").setup({ + options = { + theme = "tokyonight", + tabline = { + lualine_a = { "buffers" }, + lualine_b = { "branch" }, + lualine_c = { "filename" }, + lualine_x = {}, + lualine_y = {}, + lualine_z = { "tabs" }, + }, + }, +}) diff --git a/after/plugin/null-ls.lua b/after/plugin/null-ls.lua new file mode 100644 index 00000000..12d5b500 --- /dev/null +++ b/after/plugin/null-ls.lua @@ -0,0 +1,75 @@ +local setup, null_ls = pcall(require, "null-ls") +if not setup then + return +end + +local formatting = null_ls.builtins.formatting +local diagnostics = null_ls.builtins.diagnostics +local conditional = function(fn) + local utils = require("null-ls.utils").make_conditional_utils() + return fn(utils) +end + +local lsp_formatting = function(bufnr) + vim.lsp.buf.format({ + timeout_ms = 2000, + filter = function(client) + -- apply whatever logic you want (in this example, we'll only use null-ls) + return client.name ~= "tsserver" + end, + bufnr = bufnr, + }) +end + +local augroup = vim.api.nvim_create_augroup("LspFormatting", {}) + +-- local my_rubocop_formatter = require("rahcodes.null-ls.rubocop") +local rubocop = null_ls.builtins.formatting.rubocop + +null_ls.setup({ + debug = false, + sources = { + formatting.prettier, + -- formatting.stylua, + null_ls.builtins.code_actions.gitsigns, + -- setting eslint_d only if we have a ".eslintrc.js" file in the project + diagnostics.eslint_d.with({ + condition = function(utils) + return utils.root_has_file({ '.eslintrc.js' }) + end + }), + + -- Here we set a conditional to call the rubocop formatter. If we have a Gemfile in the project, we call "bundle exec rubocop", if not we only call "rubocop". + conditional(function(utils) + return utils.root_has_file("Gemfile") + and rubocop.with({ + command = "bundle", + args = vim.list_extend({ "exec", "rubocop" }, rubocop._opts.args), + }) + or rubocop + end), + + -- Same as above, but with diagnostics.rubocop to make sure we use the proper rubocop version for the project + conditional(function(utils) + return utils.root_has_file("Gemfile") + and null_ls.builtins.diagnostics.rubocop.with({ + command = "bundle", + args = vim.list_extend({ "exec", "rubocop" }, null_ls.builtins.diagnostics.rubocop._opts.args), + }) + or null_ls.builtins.diagnostics.rubocop + end), + }, + -- format on save + on_attach = function(client, bufnr) + if client.supports_method("textDocument/formatting") then + vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr }) + vim.api.nvim_create_autocmd("BufWritePre", { + group = augroup, + buffer = bufnr, + callback = function() + lsp_formatting(bufnr) + end, + }) + end + end, +}) diff --git a/after/plugin/telescope.lua b/after/plugin/telescope.lua new file mode 100644 index 00000000..e6613cf4 --- /dev/null +++ b/after/plugin/telescope.lua @@ -0,0 +1,2 @@ +pcall(require("telescope").load_extension, "ui-select") +pcall(require("telescope").load_extension, "live_grep_args") diff --git a/lua/custom/plugins/init.lua b/lua/custom/plugins/init.lua index be0eb9d8..257f9b3f 100644 --- a/lua/custom/plugins/init.lua +++ b/lua/custom/plugins/init.lua @@ -1,5 +1,68 @@ --- You can add your own plugins here or in other files in this directory! --- I promise not to create any merge conflicts in this directory :) --- --- See the kickstart.nvim README for more information -return {} +return { + { + "ThePrimeagen/refactoring.nvim", + requires = { + { "nvim-lua/plenary.nvim" }, + { "nvim-treesitter/nvim-treesitter" }, + }, + config = function() + require("refactoring").setup({}) + end, + }, + { + "ThePrimeagen/git-worktree.nvim", + }, + { + "folke/tokyonight.nvim", + lazy = false, -- make sure we load this during startup if it is your main colorscheme + priority = 1000, -- make sure to load this before all the other start plugins + config = function() + -- load the colorscheme here + vim.cmd([[colorscheme tokyonight]]) + end, + }, + -- formatting & linting + "jose-elias-alvarez/null-ls.nvim", + -- use("jayp0521/mason-null-ls.nvim") + { + "kylechui/nvim-surround", + version = "*", -- Use for stability; omit to use `main` branch for the latest features + event = "VeryLazy", + config = function() + require("nvim-surround").setup({ + -- Configuration here, or leave empty to use defaults + }) + end, + }, + { + "folke/trouble.nvim", + requires = "nvim-tree/nvim-web-devicons", + config = function() + require("trouble").setup({ + -- your configuration comes here + -- or leave it empty to use the default settings + -- refer to the configuration section below + }) + end, + }, + { + "rafamadriz/friendly-snippets", + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + end, + }, + { + "nvim-telescope/telescope.nvim", + dependencies = { + { + "nvim-telescope/telescope-live-grep-args.nvim", + -- This will not install any breaking changes. + -- For major updates, this must be adjusted manually. + version = "^1.0.0", + }, + }, + config = function() + require("telescope").load_extension("live_grep_args") + end + } +} diff --git a/lua/rahcodes/keymap.lua b/lua/rahcodes/keymap.lua new file mode 100644 index 00000000..463c1881 --- /dev/null +++ b/lua/rahcodes/keymap.lua @@ -0,0 +1,20 @@ +local M = {} + +local function bind(op, outer_opts) + outer_opts = outer_opts or {noremap = true} + return function(lhs, rhs, opts) + opts = vim.tbl_extend("force", + outer_opts, + opts or {} + ) + vim.keymap.set(op, lhs,rhs, opts) + end +end + +M.nmap = bind("n", {noremap = false}) +M.nnoremap = bind("n") +M.vnoremap = bind("v") +M.xnoremap = bind("x") +M.inoremap = bind("i") + +return M diff --git a/lua/rahcodes/remap.lua b/lua/rahcodes/remap.lua new file mode 100644 index 00000000..e315af27 --- /dev/null +++ b/lua/rahcodes/remap.lua @@ -0,0 +1,69 @@ +local Remap = require("rahcodes.keymap") +local nmap = Remap.nmap + +vim.keymap.set("n", "pv", vim.cmd.Ex) + +vim.keymap.set("v", "J", ":m '>+1gv=gv") +vim.keymap.set("v", "K", ":m '<-2gv=gv") + +vim.keymap.set("n", "", "zz") +vim.keymap.set("n", "", "zz") + +vim.keymap.set("n", "n", "nzzzv") +vim.keymap.set("n", "N", "Nzzzv") + +-- don't bork paste buffer when pasting +vim.keymap.set("x", "p", '"_dP') + +vim.keymap.set("i", "", "") + +-- vim.keymap.set("n", "/", "/\v") +-- vim.keymap.set("v", "/", "/\v") +vim.keymap.set("n", "`", ":noh") + +-- No Cheating +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("n", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") +vim.keymap.set("i", "", "") + +-- No weird line jumps +vim.keymap.set("n", "j", "gj") +vim.keymap.set("n", "k", "gk") + +-- Copy to system clipboard +vim.keymap.set("n", "y", '"*y') +vim.keymap.set("v", "y", '"*y') +vim.keymap.set("n", "yy", '"+y') +vim.keymap.set("v", "yy", '"+y') + +vim.keymap.set("n", "", "silent !tmux neww tmux-sessionizer") + +-- Move buffers +nmap("sp", ":bprev") +nmap("sn", ":bnext") + +-- Quickfix list navigation +vim.keymap.set("n", "", "cnextzz") +vim.keymap.set("n", "", "cprevzz") +vim.keymap.set("n", "k", "lnextzz") +vim.keymap.set("n", "j", "lprevzz") + +-- Save +nmap("", ":wa") + +-- See `:help telescope.builtin` +vim.keymap.set("n", "m", require("telescope.builtin").oldfiles, { desc = "[?] Find recently opened files" }) +vim.keymap.set("n", "/", require("telescope.builtin").find_files, { desc = "[S]earch [F]iles" }) + +-- Trouble bindings +vim.keymap.set("n", "xx", function() require("trouble").open() end) +vim.keymap.set("n", "xw", function() require("trouble").open("workspace_diagnostics") end) +vim.keymap.set("n", "xd", function() require("trouble").open("document_diagnostics") end) +vim.keymap.set("n", "xq", function() require("trouble").open("quickfix") end) +vim.keymap.set("n", "xl", function() require("trouble").open("loclist") end) +vim.keymap.set("n", "gR", function() require("trouble").open("lsp_references") end) diff --git a/lua/rahcodes/sets.lua b/lua/rahcodes/sets.lua new file mode 100644 index 00000000..2cf4c156 --- /dev/null +++ b/lua/rahcodes/sets.lua @@ -0,0 +1,26 @@ +vim.opt.guicursor = "" + +vim.opt.nu = true +vim.opt.relativenumber = true + +vim.opt.tabstop = 4 +vim.opt.softtabstop = 4 +vim.opt.shiftwidth = 4 +vim.opt.expandtab = true + +vim.opt.smartindent = true + +vim.opt.wrap = false + +vim.opt.swapfile = false +vim.opt.backup = false +vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir" + +vim.opt.incsearch = true + +vim.opt.scrolloff = 8 +vim.opt.isfname:append("@-@") + +vim.opt.colorcolumn = "80" + +vim.opt.mouse = "v" diff --git a/lua/rahcodes/solargraph.lua b/lua/rahcodes/solargraph.lua new file mode 100644 index 00000000..5dd7eb7c --- /dev/null +++ b/lua/rahcodes/solargraph.lua @@ -0,0 +1,22 @@ +local lsp = require 'lspconfig' +lsp.solargraph.setup { + cmd = { os.getenv("HOME") .. "/.asdf/shims/solargraph", '--stdio' }, + filetypes = { "ruby", "rakefile" }, + settings = { + solargraph = { + -- root_dir = nvim_lsp.util.root_pattern("Gemfile", ".git", "."), + -- root_dir = root_pattern("Gemfile", ".git"), + settings = { + solargraph = { + autoformat = true, + completion = true, + diagnostic = true, + folding = true, + references = true, + rename = true, + symbols = true + } + } + }, + } +}