From 7221b8a04b3bc666ac6d987f88b61e88ed34688b Mon Sep 17 00:00:00 2001 From: Daniil Tsivinsky Date: Tue, 29 Aug 2023 00:42:44 +0300 Subject: [PATCH] neovim: rewrite config --- .../.config/nvim/after/ftplugin/fugitive.lua | 1 - .../.config/nvim/after/ftplugin/gitcommit.lua | 2 - neovim/.config/nvim/after/ftplugin/go.lua | 3 - neovim/.config/nvim/after/ftplugin/make.lua | 3 - .../.config/nvim/after/ftplugin/markdown.lua | 1 - neovim/.config/nvim/after/ftplugin/sh.lua | 3 - .../after/plugin/{aus.lua => autocmds.lua} | 8 -- neovim/.config/nvim/after/plugin/cmds.lua | 15 --- neovim/.config/nvim/after/plugin/commands.lua | 3 + .../.config/nvim/after/plugin/file-tree.lua | 100 -------------- neovim/.config/nvim/after/plugin/git.lua | 22 +++ neovim/.config/nvim/after/plugin/lsp.lua | 106 ++++----------- neovim/.config/nvim/after/plugin/lualine.lua | 127 ------------------ neovim/.config/nvim/after/plugin/options.lua | 79 +++++------ neovim/.config/nvim/after/plugin/remaps.lua | 115 +--------------- neovim/.config/nvim/after/plugin/snippets.lua | 22 --- .../.config/nvim/after/plugin/telescope.lua | 24 +--- neovim/.config/nvim/after/plugin/theme.lua | 8 -- .../.config/nvim/after/plugin/treesitter.lua | 3 - neovim/.config/nvim/init.lua | 72 ++-------- neovim/.config/nvim/lua/daniil/git.lua | 55 -------- neovim/.config/nvim/lua/daniil/init.lua | 1 + .../nvim/lua/daniil/plugins/comment.lua | 25 ---- .../nvim/lua/daniil/plugins/gitsigns.lua | 43 ------ neovim/.config/nvim/lua/daniil/tabs.lua | 34 ----- neovim/.config/nvim/lua/daniil/utils.lua | 103 -------------- 26 files changed, 106 insertions(+), 872 deletions(-) delete mode 100644 neovim/.config/nvim/after/ftplugin/fugitive.lua delete mode 100644 neovim/.config/nvim/after/ftplugin/gitcommit.lua delete mode 100644 neovim/.config/nvim/after/ftplugin/go.lua delete mode 100644 neovim/.config/nvim/after/ftplugin/make.lua delete mode 100644 neovim/.config/nvim/after/ftplugin/markdown.lua delete mode 100644 neovim/.config/nvim/after/ftplugin/sh.lua rename neovim/.config/nvim/after/plugin/{aus.lua => autocmds.lua} (62%) delete mode 100644 neovim/.config/nvim/after/plugin/cmds.lua create mode 100644 neovim/.config/nvim/after/plugin/commands.lua delete mode 100644 neovim/.config/nvim/after/plugin/file-tree.lua create mode 100644 neovim/.config/nvim/after/plugin/git.lua delete mode 100644 neovim/.config/nvim/after/plugin/lualine.lua delete mode 100644 neovim/.config/nvim/after/plugin/snippets.lua delete mode 100644 neovim/.config/nvim/after/plugin/theme.lua delete mode 100644 neovim/.config/nvim/lua/daniil/git.lua create mode 100644 neovim/.config/nvim/lua/daniil/init.lua delete mode 100644 neovim/.config/nvim/lua/daniil/plugins/comment.lua delete mode 100644 neovim/.config/nvim/lua/daniil/plugins/gitsigns.lua delete mode 100644 neovim/.config/nvim/lua/daniil/tabs.lua delete mode 100644 neovim/.config/nvim/lua/daniil/utils.lua diff --git a/neovim/.config/nvim/after/ftplugin/fugitive.lua b/neovim/.config/nvim/after/ftplugin/fugitive.lua deleted file mode 100644 index 7ad793b..0000000 --- a/neovim/.config/nvim/after/ftplugin/fugitive.lua +++ /dev/null @@ -1 +0,0 @@ -vim.wo.colorcolumn = "" diff --git a/neovim/.config/nvim/after/ftplugin/gitcommit.lua b/neovim/.config/nvim/after/ftplugin/gitcommit.lua deleted file mode 100644 index afc83c6..0000000 --- a/neovim/.config/nvim/after/ftplugin/gitcommit.lua +++ /dev/null @@ -1,2 +0,0 @@ -vim.wo.colorcolumn = "50" -vim.cmd("setlocal spell") diff --git a/neovim/.config/nvim/after/ftplugin/go.lua b/neovim/.config/nvim/after/ftplugin/go.lua deleted file mode 100644 index a8b1de8..0000000 --- a/neovim/.config/nvim/after/ftplugin/go.lua +++ /dev/null @@ -1,3 +0,0 @@ -vim.bo.tabstop = 4 -vim.bo.shiftwidth = 4 -vim.bo.expandtab = false diff --git a/neovim/.config/nvim/after/ftplugin/make.lua b/neovim/.config/nvim/after/ftplugin/make.lua deleted file mode 100644 index 1bafe32..0000000 --- a/neovim/.config/nvim/after/ftplugin/make.lua +++ /dev/null @@ -1,3 +0,0 @@ -vim.bo.tabstop = 2 -vim.bo.shiftwidth = 2 -vim.bo.expandtab = false diff --git a/neovim/.config/nvim/after/ftplugin/markdown.lua b/neovim/.config/nvim/after/ftplugin/markdown.lua deleted file mode 100644 index e6374df..0000000 --- a/neovim/.config/nvim/after/ftplugin/markdown.lua +++ /dev/null @@ -1 +0,0 @@ -vim.cmd("setlocal spell") diff --git a/neovim/.config/nvim/after/ftplugin/sh.lua b/neovim/.config/nvim/after/ftplugin/sh.lua deleted file mode 100644 index 1bafe32..0000000 --- a/neovim/.config/nvim/after/ftplugin/sh.lua +++ /dev/null @@ -1,3 +0,0 @@ -vim.bo.tabstop = 2 -vim.bo.shiftwidth = 2 -vim.bo.expandtab = false diff --git a/neovim/.config/nvim/after/plugin/aus.lua b/neovim/.config/nvim/after/plugin/autocmds.lua similarity index 62% rename from neovim/.config/nvim/after/plugin/aus.lua rename to neovim/.config/nvim/after/plugin/autocmds.lua index b20bdab..cc4244d 100644 --- a/neovim/.config/nvim/after/plugin/aus.lua +++ b/neovim/.config/nvim/after/plugin/autocmds.lua @@ -7,11 +7,3 @@ vim.api.nvim_create_autocmd("TextYankPost", { vim.highlight.on_yank({ timeout = 200 }) end, }) - -vim.api.nvim_create_autocmd("BufEnter", { - pattern = "*", - group = group, - callback = function() - vim.cmd(":checktime") - end, -}) diff --git a/neovim/.config/nvim/after/plugin/cmds.lua b/neovim/.config/nvim/after/plugin/cmds.lua deleted file mode 100644 index 7467652..0000000 --- a/neovim/.config/nvim/after/plugin/cmds.lua +++ /dev/null @@ -1,15 +0,0 @@ -local git = require("daniil.git") - -vim.api.nvim_create_user_command("GitShowCommit", function() - local commit = git.get_commit_hash_for_current_line() - - vim.cmd(":Git show " .. commit) -end, {}) - -vim.api.nvim_create_user_command("OpenUnsavedBuffers", function() - require("daniil.utils").open_unsaved_buffers() -end, {}) - -vim.api.nvim_create_user_command("ClearQuickfixList", function() - vim.fn.setqflist({}) -end, {}) diff --git a/neovim/.config/nvim/after/plugin/commands.lua b/neovim/.config/nvim/after/plugin/commands.lua new file mode 100644 index 0000000..f024c93 --- /dev/null +++ b/neovim/.config/nvim/after/plugin/commands.lua @@ -0,0 +1,3 @@ +vim.api.nvim_create_user_command("ClearQuickfixList", function() + vim.fn.setqflist({}) +end, {}) diff --git a/neovim/.config/nvim/after/plugin/file-tree.lua b/neovim/.config/nvim/after/plugin/file-tree.lua deleted file mode 100644 index 37213b4..0000000 --- a/neovim/.config/nvim/after/plugin/file-tree.lua +++ /dev/null @@ -1,100 +0,0 @@ -local function on_attach(bufnr) - local api = require("nvim-tree.api") - - local function opts(desc) - return { - desc = "nvim-tree: " .. desc, - buffer = bufnr, - noremap = true, - silent = true, - nowait = true, - } - end - - vim.keymap.set("n", "tn", api.node.open.tab, opts("tabnew")) - vim.keymap.set("n", "l", api.node.open.edit, opts("edit")) - vim.keymap.set("n", "", api.node.open.edit, opts("edit ENTER")) - vim.keymap.set("n", "@", api.tree.change_root_to_node, opts("change root")) - vim.keymap.set("n", "", api.node.open.vertical, opts("vertical split")) - vim.keymap.set("n", "", api.node.open.horizontal, opts("horizontal split")) - vim.keymap.set("n", "a", api.fs.create, opts("create file")) - vim.keymap.set("n", "d", api.fs.remove, opts("remove file")) - vim.keymap.set("n", "r", api.fs.rename, opts("rename file")) - vim.keymap.set("n", "R", api.tree.reload, opts("reload")) - vim.keymap.set("n", "x", api.fs.cut, opts("cut")) - vim.keymap.set("n", "y", api.fs.copy.filename, opts("copy filename")) - vim.keymap.set("n", "Y", api.fs.copy.relative_path, opts("copy relative path file")) - vim.keymap.set("n", "W", api.tree.collapse_all, opts("collapse all")) - vim.keymap.set("n", "I", api.tree.toggle_gitignore_filter, opts("toggle git ignored files")) - vim.keymap.set("n", "H", api.tree.toggle_hidden_filter, opts("toggle hidden files")) - vim.keymap.set("n", "", api.node.open.preview, opts("preview node")) - vim.keymap.set("n", "F", api.live_filter.clear, opts("clear filter")) - vim.keymap.set("n", "f", api.live_filter.start, opts("filter")) - vim.keymap.set("n", "q", api.tree.close, opts("quit")) - vim.keymap.set("n", "p", api.fs.paste, opts("paste")) -end - -require("nvim-tree").setup({ - disable_netrw = true, - hijack_netrw = true, - hijack_cursor = true, - open_on_tab = false, - update_cwd = true, - auto_reload_on_write = true, - reload_on_bufenter = true, - update_focused_file = { - enable = true, - }, - view = { - width = 30, - adaptive_size = false, - side = "left", - preserve_window_proportions = true, - centralize_selection = true, - }, - renderer = { - add_trailing = true, - group_empty = false, - highlight_git = true, - indent_markers = { - enable = true, - }, - icons = { - show = { - git = true, - file = true, - folder = true, - }, - glyphs = { - default = "", - symlink = "", - git = { - unstaged = "U", - staged = "S", - unmerged = "M", - renamed = "R", - untracked = "N", - deleted = "D", - }, - }, - }, - }, - filters = { - custom = { "^.git$" }, - }, - actions = { - open_file = { - resize_window = true, - quit_on_open = true, - }, - }, - git = { - ignore = true, - }, - diagnostics = { - enable = true, - show_on_dirs = true, - icons = { hint = "", info = "", warning = "", error = "" }, - }, - on_attach = on_attach, -}) diff --git a/neovim/.config/nvim/after/plugin/git.lua b/neovim/.config/nvim/after/plugin/git.lua new file mode 100644 index 0000000..55703e6 --- /dev/null +++ b/neovim/.config/nvim/after/plugin/git.lua @@ -0,0 +1,22 @@ +local actions = require("gitsigns.actions") + +require("gitsigns").setup({ + signcolumn = true, + attach_to_untracked = false, + current_line_blame = true, + current_line_blame_opts = { + delay = 1000, + }, + current_line_blame_formatter_opts = { + relative_time = true, + }, + on_attach = function(bufnr) + vim.keymap.set("n", "gn", actions.next_hunk) + vim.keymap.set("n", "gN", actions.prev_hunk) + vim.keymap.set("n", "gr", actions.reset_hunk) + end, +}) + +vim.keymap.set("n", "gg", ":Git") +vim.keymap.set("n", "gh", ":diffget //2") +vim.keymap.set("n", "gl", ":diffget //3") diff --git a/neovim/.config/nvim/after/plugin/lsp.lua b/neovim/.config/nvim/after/plugin/lsp.lua index fee7f4b..8158e3a 100644 --- a/neovim/.config/nvim/after/plugin/lsp.lua +++ b/neovim/.config/nvim/after/plugin/lsp.lua @@ -2,32 +2,12 @@ local mason = require("mason") local lsp_installer = require("mason-lspconfig") local lspconfig = require("lspconfig") local null_ls = require("null-ls") -local util = require("lspconfig").util -local u = require("daniil.utils") +local util = lspconfig.util local formatting = null_ls.builtins.formatting -local diagnostics = null_ls.builtins.diagnostics mason.setup() - -lsp_installer.setup({ - ensure_installed = { - "bashls", - "cssmodules_ls", - "dockerls", - "tailwindcss", - "tsserver", - "vimls", - "cssls", - "html", - "jsonls", - "svelte", - "emmet_ls", - "eslint", - "gopls", - }, - automatic_installation = true, -}) +lsp_installer.setup() null_ls.setup({ sources = { @@ -43,41 +23,38 @@ null_ls.setup({ pattern = "*", group = group, callback = function() - u.lsp_format() + vim.lsp.buf.format() end, }) end, }) --- Other formats that work weird with null_ls -local group = vim.api.nvim_create_augroup("OtherLspFormatting", { clear = true }) -vim.api.nvim_create_autocmd("BufWritePre", { - pattern = { "*.svelte" }, - group = group, - callback = function() - vim.lsp.buf.format() - end, -}) +local function on_attach(client, bufnr) + local opts = { buffer = bufnr, remap = false } + + vim.keymap.set("n", "gd", ts.lsp_definitions, opts) + vim.keymap.set("n", "gr", ts.lsp_references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "", vim.lsp.buf.rename, opts) + vim.keymap.set("n", ".", vim.lsp.buf.code_action, opts) + vim.keymap.set("v", ".", vim.lsp.buf.range_code_action, opts) + vim.keymap.set({ "i", "n" }, "", vim.lsp.buf.signature_help, opts) + + vim.keymap.set("n", "ee", function() + vim.diagnostic.open_float(nil, { focus = false, scope = "line" }) + end, opts) + vim.keymap.set("n", "en", function() + vim.diagnostic.goto_next({ float = false }) + end) + vim.keymap.set("n", "eN", function() + vim.diagnostic.goto_prev({ float = false }) + end) +end local capabilities = require("cmp_nvim_lsp").default_capabilities(vim.lsp.protocol.make_client_capabilities()) capabilities.textDocument.completion.completionItem.snippetSupport = true -local lsps_with_disabled_formatting = { "tsserver", "gopls", "jsonls", "html", "sumneko_lua" } - -local on_attach = function(client, bufnr) - if vim.tbl_contains(lsps_with_disabled_formatting, client.name) then - client.server_capabilities.document_formatting = false - client.server_capabilities.document_range_formatting = false - client.server_capabilities.documentFormattingProvider = false - end - - if client.name == "tailwindcss" then - require("tailwindcss-colors").buf_attach(bufnr) - end -end - local servers = lsp_installer.get_installed_servers() - for _, server in ipairs(servers) do local opts = { capabilities = capabilities, @@ -89,41 +66,6 @@ for _, server in ipairs(servers) do opts.filetypes = { "html", "css", "scss", "javascripreact", "typescriptreact", "astro" } end - if server == "jsonls" then - opts.filetypes = { "json", "jsonc", "yaml" } - opts.settings = { - json = { - format = { - enable = false, - }, - schemas = require("schemastore").json.schemas({ - select = { - ".eslintrc", - "package.json", - "tsconfig.json", - "prettierrc.json", - "babelrc.json", - "Vercel", - "cypress.json", - "GitHub Action", - "GitHub Workflow", - "lerna.json", - "openapi.json", - ".postcssrc", - "prisma.yml", - "Swagger API 2.0", - "huskyrc", - "jsdoc", - ".commitlintrc", - "docker-compose.yml", - ".yarnrc.yml", - "swcrc", - }, - }), - }, - } - end - if server == "tsserver" then opts.settings = { tsserver = { diff --git a/neovim/.config/nvim/after/plugin/lualine.lua b/neovim/.config/nvim/after/plugin/lualine.lua deleted file mode 100644 index bc9021f..0000000 --- a/neovim/.config/nvim/after/plugin/lualine.lua +++ /dev/null @@ -1,127 +0,0 @@ -local lualine = require("lualine") -local devicons = require("nvim-web-devicons") - -local mode = { - "mode", -} - -local branch = { - "branch", - icons_enabled = true, - icon = "", -} - -local diagnostics = { - "diagnostics", - sections = { "error", "warn", "info", "hint" }, - always_visible = true, -} - -local relative_filename = { - "filename", - path = 1, -} - -local filetype = { - function() - local filetype = vim.bo.filetype - local filename = vim.fn.expand("%:t") - local fileext = vim.fn.expand("%:e") - local icon = devicons.get_icon(filename, fileext) - - if filetype == "fugitive" then - icon = devicons.get_icons().git.icon - end - - if not icon then - return filetype - end - - return icon .. " " .. filetype - end, -} - -local filename = { - function() - local filetype = vim.bo.filetype - local filename = vim.fn.expand("%:t") - local fileext = vim.fn.expand("%:e") - local icon = devicons.get_icon(filename, fileext) - local modified = vim.bo.modified - - if filetype == "fugitive" then - icon = devicons.get_icons().git.icon - end - - if not icon then - return filename - end - - if modified then - return icon .. " " .. filename .. " " .. "[+]" - end - - return icon .. " " .. filename - end, -} - -local fileformat = { - function() - return "[" .. vim.bo.fileformat .. "]" - end, -} - -local tabstop = { - function() - local tabstop = vim.bo.tabstop - local expandtab = vim.bo.expandtab - - local method = expandtab == true and "spaces" or "tabs" - local format = tabstop .. " " .. method - - return format - end, -} - -local location = { - function() - local line = vim.fn.line(".") - local total_lines = vim.api.nvim_buf_line_count(0) - - local percent = math.floor(line / total_lines * 100) - - return line .. "/" .. total_lines .. " (" .. percent .. "%%)" - end, -} - -local diff = { - "diff", -} - -lualine.setup({ - options = { - component_separators = "", - section_separators = "", - globalstatus = true, - disabled_filetypes = { - winbar = { - "NvimTree", - }, - }, - }, - winbar = { - lualine_a = { filename }, - }, - inactive_winbar = { - lualine_a = { filename }, - }, - sections = { - lualine_a = { mode }, - lualine_b = { branch }, - lualine_c = { diagnostics, relative_filename }, - lualine_x = { diff, location, tabstop, fileformat }, - lualine_y = { filetype }, - lualine_z = {}, - }, - extensions = { "nvim-tree", "fugitive", "quickfix" }, -}) diff --git a/neovim/.config/nvim/after/plugin/options.lua b/neovim/.config/nvim/after/plugin/options.lua index 95cbace..911c578 100644 --- a/neovim/.config/nvim/after/plugin/options.lua +++ b/neovim/.config/nvim/after/plugin/options.lua @@ -1,49 +1,40 @@ -local opt = vim.opt +vim.opt.tabstop = 2 +vim.opt.softtabstop = 2 +vim.opt.shiftwidth = 2 +vim.opt.expandtab = true +vim.opt.autoindent = true --- 2 tabs converted to spaces + autoindentation -opt.tabstop = 2 -opt.shiftwidth = 2 -opt.expandtab = true -opt.autoindent = true +vim.opt.guicursor = "a:blinkoff0" +vim.opt.mouse = "" +vim.opt.number = true +vim.opt.relativenumber = true +vim.opt.splitbelow = true +vim.opt.splitright = true +vim.opt.signcolumn = "yes" +vim.opt.laststatus = 3 +vim.opt.cmdheight = 0 +vim.opt.showcmd = false +vim.opt.cursorline = true +vim.opt.clipboard = "unnamedplus" +vim.opt.autoread = true +vim.opt.colorcolumn = "80" +vim.opt.showtabline = 2 +vim.opt.wrap = true +vim.opt.encoding = "utf-8" +vim.opt.updatetime = 300 +vim.opt.fillchars:append({ eob = " " }) +vim.opt.scrolloff = 5 +vim.opt.redrawtime = 4000 +vim.opt.showmode = false +vim.opt.hidden = true --- What the **** is this -opt.shortmess = "filnxtToOFc" +vim.opt.swapfile = false +vim.opt.writebackup = false --- Create splits like a normal human being -opt.splitbelow = true -opt.splitright = true +vim.opt.smartcase = true +vim.opt.ignorecase = true --- Other settings -opt.termguicolors = true -opt.number = true -opt.relativenumber = true -opt.wrap = true -opt.swapfile = false -opt.hidden = true -opt.writebackup = false -opt.encoding = "utf-8" -opt.updatetime = 300 -opt.mouse = "" -opt.cursorline = true -opt.clipboard = "unnamedplus" -opt.signcolumn = "yes" -opt.fillchars:append({ eob = " " }) -opt.showtabline = 2 -opt.showcmd = false -opt.guicursor = "a:blinkoff0" -opt.fileformat = "unix" -opt.fileformats = { "unix", "dos", "mac" } -opt.laststatus = 3 -opt.cmdheight = 0 -opt.smartcase = true -opt.ignorecase = true -opt.scrolloff = 5 -opt.colorcolumn = "120" -opt.autoread = true -opt.showmode = false -opt.redrawtime = 4000 -opt.list = true -opt.listchars = { multispace = "·", tab = ">~" } +vim.opt.list = true +vim.opt.listchars = { multispace = "·", tab = ">~" } -opt.undodir = os.getenv("HOME") .. "/.vim/undodir" -opt.undofile = true +vim.cmd("colorscheme gruvbox-material") diff --git a/neovim/.config/nvim/after/plugin/remaps.lua b/neovim/.config/nvim/after/plugin/remaps.lua index 5a8f500..a5b0342 100644 --- a/neovim/.config/nvim/after/plugin/remaps.lua +++ b/neovim/.config/nvim/after/plugin/remaps.lua @@ -1,32 +1,11 @@ -local ts = require("telescope.builtin") -local u = require("daniil.utils") -local git = require("daniil.git") -local ls = require("luasnip") - --- General keymaps -vim.keymap.set("n", "", ":nohl") - --- Quickfix and location list remaps -vim.keymap.set("n", "", u.toggle_qflist) -vim.keymap.set("n", "q", u.toggle_locationlist) - -- Disable different keys and commands vim.keymap.set({ "n", "i", "v" }, "", "") vim.keymap.set({ "n", "i", "v" }, "", "") vim.keymap.set({ "n", "i", "v" }, "", "") vim.keymap.set("n", "q:", "") --- Move focus between splits -vim.keymap.set("n", "h", "h") -vim.keymap.set("n", "l", "l") -vim.keymap.set("n", "j", "j") -vim.keymap.set("n", "k", "k") - --- Resize splits -vim.keymap.set("n", "", ":vert :res -10") -vim.keymap.set("n", "", ":vert :res +10") -vim.keymap.set("n", "", ":res -5") -vim.keymap.set("n", "", ":res +5") +vim.keymap.set("n", "", vim.cmd.Ex) +vim.keymap.set("n", "", vim.cmd.nohl) -- Move lines easily vim.keymap.set("v", "K", ":m '<-2gv=gv") @@ -41,93 +20,7 @@ vim.keymap.set("n", "Th", ":split | :term") vim.keymap.set("n", "Tv", ":vs | :term") -- Tabs -vim.keymap.set("n", "H", ":tabprev") -vim.keymap.set("n", "L", ":tabnext") vim.keymap.set("n", "tn", ":tabnew") vim.keymap.set("n", "tN", ":-tabnew") -vim.keymap.set("n", "tf", function() - require("daniil.tabs").find_tab() -end) -vim.keymap.set("n", "", ":-tabmove") -vim.keymap.set("n", "", ":+tabmove") - --- Nvim Tree -vim.keymap.set("n", "", ":NvimTreeToggle") - --- Telescope -vim.keymap.set("n", "f", function() - ts.find_files({ hidden = true }) -end) -vim.keymap.set("n", "p", function() - ts.builtin() -end) -vim.keymap.set("n", "b", function() - ts.buffers() -end) - --- LSP -vim.keymap.set("n", "gd", function() - ts.lsp_definitions() -end) -vim.keymap.set("n", "gr", function() - ts.lsp_references() -end) -vim.keymap.set("n", "K", function() - vim.lsp.buf.hover() -end) -vim.keymap.set("n", "", function() - vim.lsp.buf.rename() -end) -vim.keymap.set("n", ".", function() - vim.lsp.buf.code_action() -end) -vim.keymap.set("v", ".", function() - vim.lsp.buf.range_code_action() -end) -vim.keymap.set({ "i", "n" }, "", vim.lsp.buf.signature_help) - --- Diagnostics -vim.keymap.set("n", "ee", function() - vim.diagnostic.open_float(nil, { focus = false, scope = "line" }) -end) -vim.keymap.set("n", "ey", function() - u.copy_diagnostic_message() -end) -vim.keymap.set("n", "en", function() - vim.diagnostic.goto_next({ float = false }) -end) -vim.keymap.set("n", "eN", function() - vim.diagnostic.goto_prev({ float = false }) -end) - --- Git -vim.keymap.set("n", "gg", ":G") -vim.keymap.set("n", "go", function() - git.open_commit_on_github() -end) -vim.keymap.set("n", "gh", ":diffget //2") -vim.keymap.set("n", "gl", ":diffget //3") - --- Luasnip -local function next_choice() - if ls.jumpable(1) then - ls.jump(1) - end -end -local function prev_choice() - if ls.jumpable(-1) then - ls.jump(-1) - end -end -vim.keymap.set("i", "", next_choice, { noremap = true, silent = true }) -vim.keymap.set("s", "", next_choice, { noremap = true, silent = true }) -vim.keymap.set("i", "", prev_choice, { noremap = true, silent = true }) -vim.keymap.set("s", "", prev_choice, { noremap = true, silent = true }) - --- Undotree -vim.keymap.set("n", "u", function() - vim.cmd([[ - UndotreeToggle - UndotreeFocus - ]]) -end) +vim.keymap.set("n", "H", ":tabprev") +vim.keymap.set("n", "L", ":tabnext") diff --git a/neovim/.config/nvim/after/plugin/snippets.lua b/neovim/.config/nvim/after/plugin/snippets.lua deleted file mode 100644 index a41ecc7..0000000 --- a/neovim/.config/nvim/after/plugin/snippets.lua +++ /dev/null @@ -1,22 +0,0 @@ -local ls = require("luasnip") -local s, i = ls.s, ls.insert_node -local fmt = require("luasnip.extras.fmt").fmt - --- NOTE: this is not working right now, i need to RTFM -ls.filetype_extend("javascript", { "javascriptreact", "javascript.jsx" }) -ls.filetype_extend("typescript", { "typescriptreact", "typescript.jsx" }) - -local clg = s( - "clg", - fmt([[console.log({});]], { - i(0), - }) -) - -ls.add_snippets("javascript", { clg }) -ls.add_snippets("typescript", { clg }) -ls.add_snippets("svelte", { clg }) - -require("luasnip.loaders.from_vscode").lazy_load({ - include = { "go" }, -}) diff --git a/neovim/.config/nvim/after/plugin/telescope.lua b/neovim/.config/nvim/after/plugin/telescope.lua index 3e54663..903db36 100644 --- a/neovim/.config/nvim/after/plugin/telescope.lua +++ b/neovim/.config/nvim/after/plugin/telescope.lua @@ -1,6 +1,7 @@ local telescope = require("telescope") local actions = require("telescope.actions") local layout_actions = require("telescope.actions.layout") +local builtin = require("telescope.builtin") telescope.setup({ defaults = { @@ -14,9 +15,6 @@ telescope.setup({ [""] = layout_actions.toggle_preview, }, n = { - [""] = function(prompt_bufnr) - actions.delete_buffer(prompt_bufnr) - end, [""] = layout_actions.toggle_preview, }, }, @@ -28,19 +26,9 @@ telescope.setup({ lsp_definitions = { initial_mode = "normal", }, - buffers = { - mappings = { - i = { - [""] = function(prompt_bufnr) - actions.delete_buffer(prompt_bufnr) - end, - }, - n = { - [""] = function(prompt_bufnr) - actions.delete_buffer(prompt_bufnr) - end, - }, - }, + find_files = { + hidden = true, + no_ignore = true, }, }, extensions = { @@ -53,4 +41,6 @@ telescope.setup({ }, }) -require("telescope").load_extension("fzf") +telescope.load_extension("fzf") + +vim.keymap.set("n", "f", builtin.find_files) diff --git a/neovim/.config/nvim/after/plugin/theme.lua b/neovim/.config/nvim/after/plugin/theme.lua deleted file mode 100644 index 1154ef6..0000000 --- a/neovim/.config/nvim/after/plugin/theme.lua +++ /dev/null @@ -1,8 +0,0 @@ -vim.api.nvim_set_hl(0, "SpellBad", { - fg = "red", -}) - -vim.cmd([[ -colorscheme gruvbox-material -hi clear SignColumn -]]) diff --git a/neovim/.config/nvim/after/plugin/treesitter.lua b/neovim/.config/nvim/after/plugin/treesitter.lua index 7bcb100..0b87334 100644 --- a/neovim/.config/nvim/after/plugin/treesitter.lua +++ b/neovim/.config/nvim/after/plugin/treesitter.lua @@ -35,7 +35,4 @@ require("nvim-treesitter.configs").setup({ context_commentstring = { enable = true, }, - autotag = { - enable = true, - }, }) diff --git a/neovim/.config/nvim/init.lua b/neovim/.config/nvim/init.lua index e2d44a0..9d10a83 100644 --- a/neovim/.config/nvim/init.lua +++ b/neovim/.config/nvim/init.lua @@ -13,63 +13,22 @@ end require("packer").startup(function(use) use({ "wbthomason/packer.nvim" }) - use({ "nvim-lua/plenary.nvim" }) - -- Colorschemes go here use({ "sainnhe/gruvbox-material" }) - -- Make commenting code great + use({ "nvim-treesitter/nvim-treesitter" }) + use({ "JoosepAlviste/nvim-ts-context-commentstring" }) + use({ - "numToStr/Comment.nvim", - event = "BufRead", - config = function() - require("daniil.plugins.comment") - end, + "nvim-telescope/telescope.nvim", + branch = "0.1.x", + { "nvim-telescope/telescope-fzf-native.nvim", run = "make" } }) - -- Icons used by many plugins - use({ "kyazdani42/nvim-web-devicons" }) - - -- Auto pairs plugin that automatically closes brackets and quotes - use({ - "windwp/nvim-autopairs", - event = "BufRead", - config = function() - require("nvim-autopairs").setup({}) - end, - }) - - -- File tree - use({ "kyazdani42/nvim-tree.lua" }) - - -- Treesitter for better syntax highlighting - use({ - "nvim-treesitter/nvim-treesitter", - run = ":TSUpdate", - { - { "JoosepAlviste/nvim-ts-context-commentstring" }, - { "windwp/nvim-ts-autotag" }, - }, - }) - - -- Git things - use({ - "lewis6991/gitsigns.nvim", - event = "BufRead", - config = function() - require("daniil.plugins.gitsigns") - end, - }) use({ "tpope/vim-fugitive" }) + use({ "lewis6991/gitsigns.nvim" }) - -- LSP stuff - use({ "neovim/nvim-lspconfig" }) - use({ "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim" }) - use({ "jose-elias-alvarez/null-ls.nvim" }) - use({ "b0o/SchemaStore.nvim" }) - - -- Completion, snippets, etc use({ "hrsh7th/nvim-cmp", { @@ -83,21 +42,10 @@ require("packer").startup(function(use) use({ "L3MON4D3/LuaSnip", { "saadparwaiz1/cmp_luasnip", } }) - use({ "rafamadriz/friendly-snippets" }) - use({ - "nvim-telescope/telescope.nvim", - branch = "0.1.x", - { - "nvim-telescope/telescope-fzf-native.nvim", - run = "make", - }, - }) - - -- Statusline - use({ "nvim-lualine/lualine.nvim" }) - - use({ "mbbill/undotree" }) + use({ "neovim/nvim-lspconfig" }) + use({ "williamboman/mason.nvim", "williamboman/mason-lspconfig.nvim" }) + use({ "jose-elias-alvarez/null-ls.nvim" }) if PACKER_BOOTSTRAP then require("packer").sync() diff --git a/neovim/.config/nvim/lua/daniil/git.lua b/neovim/.config/nvim/lua/daniil/git.lua deleted file mode 100644 index af78a66..0000000 --- a/neovim/.config/nvim/lua/daniil/git.lua +++ /dev/null @@ -1,55 +0,0 @@ -local u = require("daniil.utils") - -local git = {} - ---- @return string commit_hash -function git.get_commit_hash_for_current_line() - local fullpath = vim.api.nvim_buf_get_name(0) - local cwd = vim.loop.cwd() - local relative_path = string.gsub(fullpath, cwd .. "/", "") - - local line = unpack(vim.api.nvim_win_get_cursor(0)) - - local f = io.popen("git blame -L " .. line .. ",+1 " .. relative_path, "r") - local data = f:read("*a") - f:close() - - local commit_hash = vim.split(data, " ")[1] - - return commit_hash -end - ---- @return string git_remote_url -function git.get_remote_url() - local f = io.popen("git remote get-url origin", "r") - local remote_url = f:read("*l") - f:close() - - if string.sub(remote_url, 0, 4) == "git@" then - remote_url = string.gsub(remote_url, "git@", "") - remote_url = string.gsub(remote_url, ".git", "") - remote_url = string.gsub(remote_url, ":", "/") - end - - if string.sub(remote_url, 0, 5) ~= "https" then - remote_url = "https://" .. remote_url - end - - return remote_url -end - -function git.open_commit_on_github() - local commit_hash = git.get_commit_hash_for_current_line() - local remote_url = git.get_remote_url() - - if commit_hash == "00000000" then - print("Not committed yet") - return - end - - local commit_url = remote_url .. "/commit/" .. commit_hash - - u.open_url_in_browser(commit_url) -end - -return git diff --git a/neovim/.config/nvim/lua/daniil/init.lua b/neovim/.config/nvim/lua/daniil/init.lua new file mode 100644 index 0000000..75e4873 --- /dev/null +++ b/neovim/.config/nvim/lua/daniil/init.lua @@ -0,0 +1 @@ +print "fuck" diff --git a/neovim/.config/nvim/lua/daniil/plugins/comment.lua b/neovim/.config/nvim/lua/daniil/plugins/comment.lua deleted file mode 100644 index edc4899..0000000 --- a/neovim/.config/nvim/lua/daniil/plugins/comment.lua +++ /dev/null @@ -1,25 +0,0 @@ -require("Comment").setup({ - pre_hook = function(ctx) - -- Only calculate commentstring for tsx filetypes - if vim.bo.filetype == "typescriptreact" or vim.bo.filetype == "javascriptreact" then - local U = require("Comment.utils") - - -- Detemine whether to use linewise or blockwise commentstring - -- local type = ctx.ctype == U.ctype.line and "__default" or "__multiline" - local type = "__default" - - -- Determine the location where to calculate commentstring from - 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 = type, - location = location, - }) - end - end, -}) diff --git a/neovim/.config/nvim/lua/daniil/plugins/gitsigns.lua b/neovim/.config/nvim/lua/daniil/plugins/gitsigns.lua deleted file mode 100644 index a98f5e9..0000000 --- a/neovim/.config/nvim/lua/daniil/plugins/gitsigns.lua +++ /dev/null @@ -1,43 +0,0 @@ -local a = require("gitsigns.actions") - -require("gitsigns").setup({ - signcolumn = true, - attach_to_untracked = false, - current_line_blame = true, - current_line_blame_opts = { - delay = 1000, - }, - current_line_blame_formatter_opts = { - relative_time = true, - }, - on_attach = function(bufnr) - vim.keymap.set("n", "gs", function() - a.stage_hunk() - end) - vim.keymap.set("n", "gu", function() - a.undo_stage_hunk() - end) - vim.keymap.set("n", "gr", function() - a.reset_hunk() - end) - vim.keymap.set("n", "gp", function() - a.preview_hunk() - end) - vim.keymap.set("n", "gn", function() - a.next_hunk() - end) - vim.keymap.set("n", "gN", function() - a.prev_hunk() - end) - - vim.keymap.set("v", "gs", function() - a.stage_hunk() - end) - vim.keymap.set("v", "gu", function() - a.undo_stage_hunk() - end) - vim.keymap.set("v", "gr", function() - a.reset_hunk() - end) - end, -}) diff --git a/neovim/.config/nvim/lua/daniil/tabs.lua b/neovim/.config/nvim/lua/daniil/tabs.lua deleted file mode 100644 index 72640d5..0000000 --- a/neovim/.config/nvim/lua/daniil/tabs.lua +++ /dev/null @@ -1,34 +0,0 @@ -local M = {} - -M.find_tab = function() - local tabpages = vim.api.nvim_list_tabpages() - local tabs = {} - for _, tabnr in ipairs(tabpages) do - local winnr = vim.api.nvim_tabpage_get_win(tabnr) - local bufnr = vim.api.nvim_win_get_buf(winnr) - - local bufname = vim.api.nvim_buf_get_name(bufnr) - local root = vim.loop.cwd() - local relative_path = string.gsub(bufname, root .. "/", "") - - table.insert(tabs, { - bufname = relative_path, - tabnr = tabnr, - }) - end - - vim.ui.select(tabs, { - prompt = "Choose a tab: ", - format_item = function(item) - return item.tabnr .. " - " .. item.bufname - end, - }, function(item) - if not item then - return - end - - vim.api.nvim_set_current_tabpage(item.tabnr) - end) -end - -return M diff --git a/neovim/.config/nvim/lua/daniil/utils.lua b/neovim/.config/nvim/lua/daniil/utils.lua deleted file mode 100644 index 53d0ca6..0000000 --- a/neovim/.config/nvim/lua/daniil/utils.lua +++ /dev/null @@ -1,103 +0,0 @@ -local M = {} - -M.yank = function(message) - vim.cmd(":!echo -n '" .. message .. "' | wl-copy") -end - ---- @param diagnostics list ---- @param prompt string ---- @return string -M.select_diagnostic = function(diagnostics, prompt) - if #diagnostics == 0 then - return "" - end - - local message = "" - - if #diagnostics == 1 then - message = diagnostics[1].message - else - local d = {} - for _, diagnostic in ipairs(diagnostics) do - table.insert(d, diagnostic.message) - end - - vim.ui.select(d, { prompt = prompt }, function(item) - message = item - end) - end - - return message -end - -M.copy_diagnostic_message = function() - local diagnostics = vim.lsp.diagnostic.get_line_diagnostics() - - local message = M.select_diagnostic(diagnostics, "Pick a diagnostic to yank") - - M.yank(message) - - print("Diagnostic message was yanked") -end - -M.open_url_in_browser = function(url) - local _url = string.format('"%s"', url) - - vim.cmd(":!exec xdg-open " .. _url) -end - -function M.lsp_format(bufnr) - bufnr = bufnr or 0 - - vim.lsp.buf.format({ - filter = function(client) - if client.name == "tsserver" then - return false - end - - return true - end, - bufnr = bufnr, - }) -end - -function M.open_unsaved_buffers() - local buffers = vim.api.nvim_list_bufs() - local unsaved_buffers = {} - - local og_bufnr = vim.api.nvim_get_current_buf() - - for _, bufnr in ipairs(buffers) do - local is_saved = vim.api.nvim_buf_get_option(bufnr, "modified") - - if is_saved and bufnr ~= og_bufnr then - local bufname = vim.api.nvim_buf_get_name(bufnr) - - table.insert(unsaved_buffers, bufnr) - - vim.cmd("tabnew " .. bufname) - end - end - - if #unsaved_buffers > 0 then - vim.notify("Opened " .. #unsaved_buffers .. " unsaved buffers") - end -end - -function M.toggle_qflist() - if vim.bo.ft == "qf" then - vim.cmd(":cclose") - else - vim.cmd(":copen") - end -end - -function M.toggle_locationlist() - if vim.bo.ft == "qf" then - vim.cmd(":lclose") - else - vim.cmd(":lopen") - end -end - -return M