From 540268d618627079c9b958a955b586e1888b46a8 Mon Sep 17 00:00:00 2001 From: Gustaf Rydholm Date: Tue, 10 Aug 2021 23:15:04 +0200 Subject: Major refactor of nvim --- .config/nvim/lua/extra/colorizer.lua | 22 +++++ .config/nvim/lua/extra/hop.lua | 15 ++++ .config/nvim/lua/extra/json_schemas.lua | 99 +++++++++++++++++++++ .config/nvim/lua/extra/lir.lua | 96 +++++++++++++++++++++ .config/nvim/lua/extra/lsp_signature.lua | 14 +++ .config/nvim/lua/extra/neoscroll.lua | 25 ++++++ .config/nvim/lua/extra/numb.lua | 17 ++++ .config/nvim/lua/extra/octo.lua | 139 +++++++++++++++++++++++++++++ .config/nvim/lua/extra/quickscope.lua | 3 + .config/nvim/lua/extra/spectre.lua | 144 +++++++++++++++++++++++++++++++ .config/nvim/lua/extra/twilight.lua | 30 +++++++ .config/nvim/lua/extra/zen.lua | 48 +++++++++++ 12 files changed, 652 insertions(+) create mode 100644 .config/nvim/lua/extra/colorizer.lua create mode 100644 .config/nvim/lua/extra/hop.lua create mode 100644 .config/nvim/lua/extra/json_schemas.lua create mode 100644 .config/nvim/lua/extra/lir.lua create mode 100644 .config/nvim/lua/extra/lsp_signature.lua create mode 100644 .config/nvim/lua/extra/neoscroll.lua create mode 100644 .config/nvim/lua/extra/numb.lua create mode 100644 .config/nvim/lua/extra/octo.lua create mode 100644 .config/nvim/lua/extra/quickscope.lua create mode 100644 .config/nvim/lua/extra/spectre.lua create mode 100644 .config/nvim/lua/extra/twilight.lua create mode 100644 .config/nvim/lua/extra/zen.lua (limited to '.config/nvim/lua/extra') diff --git a/.config/nvim/lua/extra/colorizer.lua b/.config/nvim/lua/extra/colorizer.lua new file mode 100644 index 0000000..04b7367 --- /dev/null +++ b/.config/nvim/lua/extra/colorizer.lua @@ -0,0 +1,22 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, colorizer = pcall(require, "colorizer") + if not status_ok then + Log:get_default().error "Failed to load colorizer" + return + end + + colorizer.setup({ "*" }, { + RGB = true, -- #RGB hex codes + RRGGBB = true, -- #RRGGBB hex codes + RRGGBBAA = true, -- #RRGGBBAA hex codes + rgb_fn = true, -- CSS rgb() and rgba() functions + hsl_fn = true, -- CSS hsl() and hsla() functions + css = true, -- Enable all CSS features: rgb_fn, hsl_fn, names, RGB, RRGGBB + css_fn = true, -- Enable all CSS *functions*: rgb_fn, hsl_fn + }) +end + +return M diff --git a/.config/nvim/lua/extra/hop.lua b/.config/nvim/lua/extra/hop.lua new file mode 100644 index 0000000..834f97a --- /dev/null +++ b/.config/nvim/lua/extra/hop.lua @@ -0,0 +1,15 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, hop = pcall(require, "hop") + if not status_ok then + Log:get_default().error "Failed to load hop" + return + end + hop.setup() + vim.api.nvim_set_keymap("n", "s", ":HopChar2", { silent = true }) + vim.api.nvim_set_keymap("n", "S", ":HopWord", { silent = true }) +end + +return M diff --git a/.config/nvim/lua/extra/json_schemas.lua b/.config/nvim/lua/extra/json_schemas.lua new file mode 100644 index 0000000..590547b --- /dev/null +++ b/.config/nvim/lua/extra/json_schemas.lua @@ -0,0 +1,99 @@ +-- https://www.schemastore.org/json/ +local M = {} + +M.setup = function() + local schemas = { + { + description = "Package JSON file", + fileMatch = { "package.json" }, + url = "https://json.schemastore.org/package.json", + }, + { + description = "TypeScript compiler configuration file", + fileMatch = { "tsconfig.json", "tsconfig.*.json" }, + url = "http://json.schemastore.org/tsconfig", + }, + { + description = "Lerna config", + fileMatch = { "lerna.json" }, + url = "http://json.schemastore.org/lerna", + }, + { + description = "Babel configuration", + fileMatch = { ".babelrc.json", ".babelrc", "babel.config.json" }, + url = "http://json.schemastore.org/lerna", + }, + { + description = "ESLint config", + fileMatch = { ".eslintrc.json", ".eslintrc" }, + url = "http://json.schemastore.org/eslintrc", + }, + { + description = "Bucklescript config", + fileMatch = { "bsconfig.json" }, + url = "https://bucklescript.github.io/bucklescript/docson/build-schema.json", + }, + { + description = "Prettier config", + fileMatch = { ".prettierrc", ".prettierrc.json", "prettier.config.json" }, + url = "http://json.schemastore.org/prettierrc", + }, + { + description = "Vercel Now config", + fileMatch = { "now.json" }, + url = "http://json.schemastore.org/now", + }, + { + description = "Stylelint config", + fileMatch = { ".stylelintrc", ".stylelintrc.json", "stylelint.config.json" }, + url = "http://json.schemastore.org/stylelintrc", + }, + { + name = "Helm Chart.yaml", + description = "The Chart.lock file locks dependencies from Chart.yaml", + fileMatch = { "Chart.lock" }, + url = "https://json.schemastore.org/chart-lock.json" + }, + { + name = "CircleCI config.yml", + description = "Schema for CircleCI 2.0 config files", + fileMatch = { ".circleci/config.yml" }, + url = "https://json.schemastore.org/circleciconfig.json" + }, + { + name = "yamllint", + description = "yamllint uses a set of rules to check source files for problems", + fileMatch = { "**/.yamllint", "**/.yamllint.yaml", "**/.yamllint.yml" }, + url = "https://json.schemastore.org/yamllint.json" + }, + { + name = "Hadolint", + description = "A smarter Dockerfile linter that helps you build best practice Docker images.", + fileMatch = { ".hadolint.yaml", "hadolint.yaml", ".hadolint.yml", "hadolint.yml" }, + url = "https://raw.githubusercontent.com/hadolint/hadolint/master/contrib/hadolint.json" + }, + { + name = "kustomization.yaml", + description = "Kubernetes native configuration management", + fileMatch = { "kustomization.yaml", "kustomization.yml" }, + url = "https://json.schemastore.org/kustomization.json" + }, + } + + local function extend(tab1, tab2) + for _, value in ipairs(tab2) do + table.insert(tab1, value) + end + return tab1 + end + + local extended_schemas = extend(schemas, require("nlspsettings.jsonls").get_default_schemas()) + + options.lang.json.lsp.setup.settings = { + json = { + schemas = extended_schemas, + }, + } +end + +return M diff --git a/.config/nvim/lua/extra/lir.lua b/.config/nvim/lua/extra/lir.lua new file mode 100644 index 0000000..271afb1 --- /dev/null +++ b/.config/nvim/lua/extra/lir.lua @@ -0,0 +1,96 @@ +local status_ok, lir = pcall(require, "lir") +if not status_ok then + return +end +local actions = require "lir.actions" +local mark_actions = require "lir.mark.actions" +local clipboard_actions = require "lir.clipboard.actions" + +lir.setup { + show_hidden_files = false, + devicons_enable = true, + mappings = { + ["l"] = actions.edit, + [""] = actions.edit, + [""] = actions.split, + ["v"] = actions.vsplit, + [""] = actions.tabedit, + + ["h"] = actions.up, + ["q"] = actions.quit, + + ["A"] = actions.mkdir, + ["a"] = actions.newfile, + ["r"] = actions.rename, + ["@"] = actions.cd, + ["Y"] = actions.yank_path, + ["."] = actions.toggle_show_hidden, + ["D"] = actions.delete, + + ["J"] = function() + mark_actions.toggle_mark() + vim.cmd "normal! j" + end, + ["C"] = clipboard_actions.copy, + ["X"] = clipboard_actions.cut, + ["P"] = clipboard_actions.paste, + }, + float = { + winblend = 0, + + -- -- You can define a function that returns a table to be passed as the third + -- -- argument of nvim_open_win(). + win_opts = function() + -- local width = math.floor(vim.o.columns * 0.8) + -- local height = math.floor(vim.o.lines * 0.8) + return { + border = "single", + -- border = require("lir.float.helper").make_border_opts({ + -- "+", + -- "─", + -- "+", + -- "│", + -- "+", + -- "─", + -- "+", + -- "│", + -- }, "Normal"), + -- width = width, + -- height = height, + -- row = 1, + -- col = math.floor((vim.o.columns - width) / 2), + } + end, + }, + hide_cursor = false, +} + +-- custom folder icon +require("nvim-web-devicons").setup { + override = { + lir_folder_icon = { + icon = "", + color = "#569CD6", + name = "LirFolderNode", + }, + }, +} + +-- use visual mode +function _G.LirSettings() + vim.api.nvim_buf_set_keymap( + 0, + "x", + "J", + ':lua require"lir.mark.actions".toggle_mark("v")', + { noremap = true, silent = true } + ) + + -- echo cwd + vim.api.nvim_echo({ { vim.fn.expand "%:p", "Normal" } }, false, {}) +end + +vim.cmd [[augroup lir-settings]] +vim.cmd [[ autocmd!]] +vim.cmd [[ autocmd Filetype lir :lua LirSettings()]] +vim.cmd [[augroup END]] diff --git a/.config/nvim/lua/extra/lsp_signature.lua b/.config/nvim/lua/extra/lsp_signature.lua new file mode 100644 index 0000000..7e67a4d --- /dev/null +++ b/.config/nvim/lua/extra/lsp_signature.lua @@ -0,0 +1,14 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, lsp_signature = pcall(require, "lsp_signature") + if not status_ok then + Log:get_default().error "Failed to load lsp_signature" + return + end + + lsp_signature.on_attach() +end + +return M diff --git a/.config/nvim/lua/extra/neoscroll.lua b/.config/nvim/lua/extra/neoscroll.lua new file mode 100644 index 0000000..65f486b --- /dev/null +++ b/.config/nvim/lua/extra/neoscroll.lua @@ -0,0 +1,25 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, neoscroll = pcall(require, "neoscroll") + if not status_ok then + Log:get_default().error "Failed to load hop" + return + end + + neoscroll.setup { + -- All these keys will be mapped to their corresponding default scrolling animation + mappings = { "", "", "", "", "", "", "zt", "zz", "zb" }, + hide_cursor = true, -- Hide cursor while scrolling + stop_eof = true, -- Stop at when scrolling downwards + use_local_scrolloff = false, -- Use the local scope of scrolloff instead of the global scope + respect_scrolloff = false, -- Stop scrolling when the cursor reaches the scrolloff margin of the file + cursor_scrolls_alone = true, -- The cursor will keep on scrolling even if the window cannot scroll further + easing_function = nil, -- Default easing function + pre_hook = nil, -- Function to run before the scrolling animation starts + post_hook = nil, -- Function to run after the scrolling animation ends + } +end + +return M diff --git a/.config/nvim/lua/extra/numb.lua b/.config/nvim/lua/extra/numb.lua new file mode 100644 index 0000000..17d9f6b --- /dev/null +++ b/.config/nvim/lua/extra/numb.lua @@ -0,0 +1,17 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, numb = pcall(require, "numb") + if not status_ok then + Log:get_default().error "Failed to load numb" + return + end + + numb.setup { + show_numbers = true, -- Enable 'number' for the window while peeking + show_cursorline = true, -- Enable 'cursorline' for the window while peeking + } +end + +return M diff --git a/.config/nvim/lua/extra/octo.lua b/.config/nvim/lua/extra/octo.lua new file mode 100644 index 0000000..5a110df --- /dev/null +++ b/.config/nvim/lua/extra/octo.lua @@ -0,0 +1,139 @@ +local M = {} + +local Log = require "core.log" + +M.config = function() + local status_ok, octo = pcall(require, "octo") + if not status_ok then + Log:get_default().error "Failed to load octo" + return + end + + octo.setup { + default_remote = { "upstream", "origin" }, -- order to try remotes + reaction_viewer_hint_icon = "", -- marker for user reactions + user_icon = " ", -- user icon + timeline_marker = "", -- timeline marker + timeline_indent = "2", -- timeline indentation + right_bubble_delimiter = "", -- Bubble delimiter + left_bubble_delimiter = "", -- Bubble delimiter + github_hostname = "", -- GitHub Enterprise host + snippet_context_lines = 4, -- number or lines around commented lines + file_panel = { + size = 10, -- changed files panel rows + use_icons = true, -- use web-devicons in file panel + }, + mappings = { + issue = { + close_issue = "ic", -- close issue + reopen_issue = "io", -- reopen issue + list_issues = "il", -- list open issues on same repo + reload = "", -- reload issue + open_in_browser = "", -- open issue in browser + copy_url = "", -- copy url to system clipboard + add_assignee = "aa", -- add assignee + remove_assignee = "ad", -- remove assignee + create_label = "lc", -- create label + add_label = "la", -- add label + remove_label = "ld", -- remove label + goto_issue = "gi", -- navigate to a local repo issue + add_comment = "ca", -- add comment + delete_comment = "cd", -- delete comment + next_comment = "]c", -- go to next comment + prev_comment = "[c", -- go to previous comment + react_hooray = "rp", -- add/remove 🎉 reaction + react_heart = "rh", -- add/remove ❤️ reaction + react_eyes = "re", -- add/remove 👀 reaction + react_thumbs_up = "r+", -- add/remove 👍 reaction + react_thumbs_down = "r-", -- add/remove 👎 reaction + react_rocket = "rr", -- add/remove 🚀 reaction + react_laugh = "rl", -- add/remove 😄 reaction + react_confused = "rc", -- add/remove 😕 reaction + }, + pull_request = { + checkout_pr = "po", -- checkout PR + merge_pr = "pm", -- merge PR + list_commits = "pc", -- list PR commits + list_changed_files = "pf", -- list PR changed files + show_pr_diff = "pd", -- show PR diff + add_reviewer = "va", -- add reviewer + remove_reviewer = "vd", -- remove reviewer request + close_issue = "ic", -- close PR + reopen_issue = "io", -- reopen PR + list_issues = "il", -- list open issues on same repo + reload = "", -- reload PR + open_in_browser = "", -- open PR in browser + copy_url = "", -- copy url to system clipboard + add_assignee = "aa", -- add assignee + remove_assignee = "ad", -- remove assignee + create_label = "lc", -- create label + add_label = "la", -- add label + remove_label = "ld", -- remove label + goto_issue = "gi", -- navigate to a local repo issue + add_comment = "ca", -- add comment + delete_comment = "cd", -- delete comment + next_comment = "]c", -- go to next comment + prev_comment = "[c", -- go to previous comment + react_hooray = "rp", -- add/remove 🎉 reaction + react_heart = "rh", -- add/remove ❤️ reaction + react_eyes = "re", -- add/remove 👀 reaction + react_thumbs_up = "r+", -- add/remove 👍 reaction + react_thumbs_down = "r-", -- add/remove 👎 reaction + react_rocket = "rr", -- add/remove 🚀 reaction + react_laugh = "rl", -- add/remove 😄 reaction + react_confused = "rc", -- add/remove 😕 reaction + }, + review_thread = { + goto_issue = "gi", -- navigate to a local repo issue + add_comment = "ca", -- add comment + add_suggestion = "sa", -- add suggestion + delete_comment = "cd", -- delete comment + next_comment = "]c", -- go to next comment + prev_comment = "[c", -- go to previous comment + select_next_entry = "]q", -- move to previous changed file + select_prev_entry = "[q", -- move to next changed file + close_review_tab = "", -- close review tab + react_hooray = "rp", -- add/remove 🎉 reaction + react_heart = "rh", -- add/remove ❤️ reaction + react_eyes = "re", -- add/remove 👀 reaction + react_thumbs_up = "r+", -- add/remove 👍 reaction + react_thumbs_down = "r-", -- add/remove 👎 reaction + react_rocket = "rr", -- add/remove 🚀 reaction + react_laugh = "rl", -- add/remove 😄 reaction + react_confused = "rc", -- add/remove 😕 reaction + }, + submit_win = { + approve_review = "", -- approve review + comment_review = "", -- comment review + request_changes = "", -- request changes review + close_review_tab = "", -- close review tab + }, + review_diff = { + add_review_comment = "ca", -- add a new review comment + add_review_suggestion = "sa", -- add a new review suggestion + focus_files = "e", -- move focus to changed file panel + toggle_files = "b", -- hide/show changed files panel + next_thread = "]t", -- move to next thread + prev_thread = "[t", -- move to previous thread + select_next_entry = "]q", -- move to previous changed file + select_prev_entry = "[q", -- move to next changed file + close_review_tab = "", -- close review tab + toggle_viewed = "", -- toggle viewer viewed state + }, + file_panel = { + next_entry = "j", -- move to next changed file + prev_entry = "k", -- move to previous changed file + select_entry = "", -- show selected changed file diffs + refresh_files = "R", -- refresh changed files panel + focus_files = "e", -- move focus to changed file panel + toggle_files = "b", -- hide/show changed files panel + select_next_entry = "]q", -- move to previous changed file + select_prev_entry = "[q", -- move to next changed file + close_review_tab = "", -- close review tab + toggle_viewed = "", -- toggle viewer viewed state + }, + }, + } +end + +return M diff --git a/.config/nvim/lua/extra/quickscope.lua b/.config/nvim/lua/extra/quickscope.lua new file mode 100644 index 0000000..99b4196 --- /dev/null +++ b/.config/nvim/lua/extra/quickscope.lua @@ -0,0 +1,3 @@ +vim.cmd [[ + let g:qs_highlight_on_keys = ['f', 'F', 't', 'T'] + ]] diff --git a/.config/nvim/lua/extra/spectre.lua b/.config/nvim/lua/extra/spectre.lua new file mode 100644 index 0000000..12133d8 --- /dev/null +++ b/.config/nvim/lua/extra/spectre.lua @@ -0,0 +1,144 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, spectre = pcall(require, "spectre") + if not status_ok then + Log:get_default().error "Failed to load hop" + return + end + + spectre.setup { + + color_devicons = true, + highlight = { + ui = "String", + search = "DiffChange", + replace = "DiffDelete", + }, + mapping = { + ["toggle_line"] = { + map = "t", + cmd = "lua require('spectre').toggle_line()", + desc = "toggle current item", + }, + ["enter_file"] = { + map = "", + cmd = "lua require('spectre.actions').select_entry()", + desc = "goto current file", + }, + ["send_to_qf"] = { + map = "Q", + cmd = "lua require('spectre.actions').send_to_qf()", + desc = "send all item to quickfix", + }, + ["replace_cmd"] = { + map = "c", + cmd = "lua require('spectre.actions').replace_cmd()", + desc = "input replace vim command", + }, + ["show_option_menu"] = { + map = "o", + cmd = "lua require('spectre').show_options()", + desc = "show option", + }, + ["run_replace"] = { + map = "R", + cmd = "lua require('spectre.actions').run_replace()", + desc = "replace all", + }, + ["change_view_mode"] = { + map = "m", + cmd = "lua require('spectre').change_view()", + desc = "change result view mode", + }, + ["toggle_ignore_case"] = { + map = "I", + cmd = "lua require('spectre').change_options('ignore-case')", + desc = "toggle ignore case", + }, + ["toggle_ignore_hidden"] = { + map = "H", + cmd = "lua require('spectre').change_options('hidden')", + desc = "toggle search hidden", + }, + -- you can put your mapping here it only use normal mode + }, + find_engine = { + -- rg is map with finder_cmd + ["rg"] = { + cmd = "rg", + -- default args + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + options = { + ["ignore-case"] = { + value = "--ignore-case", + icon = "[I]", + desc = "ignore case", + }, + ["hidden"] = { + value = "--hidden", + desc = "hidden file", + icon = "[H]", + }, + -- you can put any option you want here it can toggle with + -- show_option function + }, + }, + ["ag"] = { + cmd = "ag", + args = { + "--vimgrep", + "-s", + }, + options = { + ["ignore-case"] = { + value = "-i", + icon = "[I]", + desc = "ignore case", + }, + ["hidden"] = { + value = "--hidden", + desc = "hidden file", + icon = "[H]", + }, + }, + }, + }, + replace_engine = { + ["sed"] = { + cmd = "sed", + args = nil, + }, + options = { + ["ignore-case"] = { + value = "--ignore-case", + icon = "[I]", + desc = "ignore case", + }, + }, + }, + default = { + find = { + --pick one of item in find_engine + cmd = "rg", + options = { "ignore-case" }, + }, + replace = { + --pick one of item in replace_engine + cmd = "sed", + }, + }, + replace_vim_cmd = "cdo", + is_open_target_win = true, --open file on opener window + is_insert_mode = false, -- start open panel on is_insert_mode + } +end + +return M diff --git a/.config/nvim/lua/extra/twilight.lua b/.config/nvim/lua/extra/twilight.lua new file mode 100644 index 0000000..b76563a --- /dev/null +++ b/.config/nvim/lua/extra/twilight.lua @@ -0,0 +1,30 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, twilight = pcall(require, "twilight") + if not status_ok then + Log:get_default().error "Failed to load twilight" + return + end + + twilight.setup { + dimming = { + alpha = 0.25, -- amount of dimming + -- we try to get the foreground from the highlight groups or fallback color + color = { "Normal", "#ffffff" }, + }, + context = 15, -- amount of lines we will try to show around the current line + -- treesitter is used to automatically expand the visible text, + -- but you can further control the types of nodes that should always be fully expanded + expand = { + "function", + "method", + "table", + "if_statement", + }, + exclude = {}, -- exclude these filetypes + } +end + +return M diff --git a/.config/nvim/lua/extra/zen.lua b/.config/nvim/lua/extra/zen.lua new file mode 100644 index 0000000..9bfaf1a --- /dev/null +++ b/.config/nvim/lua/extra/zen.lua @@ -0,0 +1,48 @@ +local M = {} +local Log = require "core.log" + +M.config = function() + local status_ok, zen_mode = pcall(require, "zen-mode") + if not status_ok then + Log:get_default().error "Failed to load zen-mode" + return + end + + zen_mode.setup { + window = { + backdrop = 1, + height = 0.9, -- height of the Zen window + width = 0.65, + options = { + signcolumn = "no", -- disable signcolumn + number = false, -- disable number column + relativenumber = false, -- disable relative numbers + -- cursorline = false, -- disable cursorline + -- cursorcolumn = false, -- disable cursor column + -- foldcolumn = "0", -- disable fold column + -- list = false, -- disable whitespace characters + }, + }, + plugins = { + gitsigns = { enabled = false }, -- disables git signs + tmux = { enabled = true }, + twilight = { enabled = true }, + }, + -- on_open = function() + -- vim.lsp.diagnostic.disable() + -- vim.cmd [[ + -- set foldlevel=10 + -- IndentBlanklineDisable + -- ]] + -- end, + -- on_close = function() + -- vim.lsp.diagnostic.enable() + -- vim.cmd [[ + -- set foldlevel=5 + -- IndentBlanklineEnable + -- ]] + -- end, + } +end + +return M -- cgit v1.2.3-70-g09d2