commit 8762db974385fa2de392dec5053c0143f770d887 Author: Legrems Date: Thu Aug 15 13:59:25 2024 +0000 First commit: migration to new config diff --git a/.stylua.toml b/.stylua.toml new file mode 100644 index 0000000..ecb6dca --- /dev/null +++ b/.stylua.toml @@ -0,0 +1,6 @@ +column_width = 120 +line_endings = "Unix" +indent_type = "Spaces" +indent_width = 2 +quote_style = "AutoPreferDouble" +call_parentheses = "None" diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fdddb29 --- /dev/null +++ b/LICENSE @@ -0,0 +1,24 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR +OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. + +For more information, please refer to diff --git a/README.md b/README.md new file mode 100644 index 0000000..380610c --- /dev/null +++ b/README.md @@ -0,0 +1,104 @@ +## Plugins + - neovim: + - neovim/nvim-lspconfig + - LSP for neovim + - nvim-*: + - nvim-lua/plenary.nvim + - Lua module to interact with system processes + - nvim-telescope/telescope-dap.nvim + - Integration of nvim-dap with telescope + - nvim-telescope/telescope-fzf-native.nvim + - Fzf-native is a `c` port of `fzf` + - nvim-telescope/telescope-live-grep-args.nvim + - Enable passing arguments to the grep command `rg` + - nvim-telescope/telescope.nvim + - Really? You don't know telescope? + - nvim-tree/nvim-tree.lua + - File explorer tree + - nvim-tree/nvim-web-devicons + - Fork of vim-devicons, provides icons + - nvim-treesitter/nvim-treesitter + - Configurations and abstraction layer for Nvim tree-sitter + - nvim-treesitter/nvim-treesitter-textobjects + - Syntax aware text-objects, select, move, swap and peek support + - tpope: + - tpope/vim-fugitive + - *The* git wrapper + - tpope/vim-obsession + - Continuously updated session files + - tpope/vim-surround + - Delete/change/add parenthese/quote/much more with ease + - folke: + - folke/noice.nvim + - Replace the UI for messages, cmdline and the popupmenu + - folke/todo-comments.nvi + - Highlight, list and search todo comments + - folke/trouble.nvim + - A pretty diagnostics, references, telescope results, quickfix and location list to help you solve all the trouble your code is causing + - folke/which-key.nvim + - Create key bindings that stick. WhichKey helps you remember your Neovim keymaps, by showing available keybindings in a popup as you type + - mfussenegger: + - mfussenegger/nvim-dap + - Debug Adapter Protocol client implementation + - mfussenegger/nvim-dap-python + - Default config for DAP python + - sindrets: + - sindrets/diffview.nvim + - Single tabpage interface for diffs + - sindrets/winshift.nvim + - Rearrange your windows with ease + - stevearc: + - stevearc/conform.nvim + - Lightweight yet powerful formatter plugin + - stevearc/quicker.nvim + - Improved UI and workflow for the quickfix list + - Others: + - aaronhallaert/advanced-git-search.nvim + - Search your git history by commit message, content and author + - anuvyklack/hydra.nvim + - Create custom submodes and menus + - desdic/macrothis.nvim + - Save and load macros + - emaniacs/vim-rest-console + - REST console + - gioele/vim-autoswap + - Please Vim, stop with these swap file messages. Just switch to the correct window! + - hrsh7th/nvim-cmp + - A completion plugin + - iamcco/markdown-preview.nvim + - Markdown previewer + - kdheepak/lazygit.nvim + - Simple terminal UI for git commands + - L3MON4D3/LuaSnip + - Snippet Engine + - lewis6991/gitsigns.nvim + - Git integration for buffers + - ludovicchabant/vim-gutentags + - Manage your tag files + - lukas-reineke/indent-blankline.nvim + - Indent guides + - mangelozzi/rgflow.nvim + - Help you get in the flow with ripgrep + - natecraddock/workspaces.nvim + - Manage workspace directories + - numToStr/Comment.nvim + - Smart and powerful comment plugin. Support treesitter, dot reaper, left-right/up-down motions, hooks and more + - onsails/diaglist.nvim + - Live render workspace diagnostics in quickfix with current buf errors on top, buffer diagnostics in loclist + - preservim/tagbar + - Displays tags in a window, ordered by scope + - rbong/vim-flog + - A fast, beautiful, and powerful git branch viewer + - rcarriga/nvim-dap-ui + - UI for nvim-dap + - rebelot/kanagawa.nvim + - Dark colorscheme inspired by the colors of the famous painting by Katsushika Hokusai + - ThePrimeagen/harpoon + - Weissle/persistent-breakpoints.nvim + - Persistent breakpoints for DAP + - williamboman/mason.nvim + - Portable package manager for Neovim that runs everywhere Neovim runs. Easily install and manage LSP servers, DAP servers, linters, and formatters + - windwp/nvim-autopairs + - Autopairs that support multiple characters + - yorickpeterse/nvim-window + - Easily jump between windows diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..9400ef8 --- /dev/null +++ b/init.lua @@ -0,0 +1,37 @@ +vim.g.base46_cache = vim.fn.stdpath "data" .. "/nvchad/base46/" +vim.g.mapleader = " " + +-- bootstrap lazy and all plugins +local lazypath = vim.fn.stdpath "data" .. "/lazy/lazy.nvim" + +if not vim.uv.fs_stat(lazypath) then + local repo = "https://github.com/folke/lazy.nvim.git" + vim.fn.system { "git", "clone", "--filter=blob:none", repo, "--branch=stable", lazypath } +end + +vim.opt.rtp:prepend(lazypath) + +local lazy_config = require "configs.lazy" + +-- load plugins +require("lazy").setup({ + { + "NvChad/NvChad", + lazy = false, + branch = "v2.5", + import = "nvchad.plugins", + }, + + { import = "plugins" }, +}, lazy_config) + +-- load theme +dofile(vim.g.base46_cache .. "defaults") +dofile(vim.g.base46_cache .. "statusline") + +require "options" +require "nvchad.autocmds" + +vim.schedule(function() + require "mappings" +end) diff --git a/lua/chadrc.lua b/lua/chadrc.lua new file mode 100644 index 0000000..24d6d06 --- /dev/null +++ b/lua/chadrc.lua @@ -0,0 +1,58 @@ +-- This file needs to have same structure as nvconfig.lua +-- https://github.com/NvChad/ui/blob/v2.5/lua/nvconfig.lua + +---@type ChadrcConfig +local M = {} + +M.base46 = { + theme = "onedark", + transparency = true, + + hl_override = { + Comment = { italic = true }, + ["@comment"] = { italic = true }, + }, +} + +M.ui = { + theme = "onedark", + statusline = { + theme = "default", + separator_style = "arrow", + order = { + "macro", + "mode", + "relativepath", + "file", + "git", + "%=", + "lsp_msg", + "%=", + "diagnostics", + "lsp", + "cwd", + "cursor", + }, + modules = { + macro = function() + local noice = require "noice" + if noice.api.statusline.mode.has() then + return "%#St_CommandMode#" .. noice.api.statusline.mode.get() + end + return "" + end, + relativepath = function() + local stbufnr = vim.api.nvim_win_get_buf(vim.g.statusline_winid or 0) + local path = vim.api.nvim_buf_get_name(stbufnr) + + if path == "" then + return "" + end + + return "%#St_file# " .. vim.fn.expand "%:.:h" .. " /" + end, + }, + }, +} + +return M diff --git a/lua/configs/blankline.lua b/lua/configs/blankline.lua new file mode 100644 index 0000000..ab7a7b2 --- /dev/null +++ b/lua/configs/blankline.lua @@ -0,0 +1,21 @@ +return {} +-- return { +-- indentLine_enabled = 1, +-- filetype_exclude = { +-- "help", +-- "terminal", +-- "lazy", +-- "lspinfo", +-- "TelescopePrompt", +-- "TelescopeResults", +-- "mason", +-- "nvdash", +-- "nvcheatsheet", +-- "", +-- }, +-- buftype_exclude = { "terminal" }, +-- show_trailing_blankline_indent = false,; +-- show_first_indent_level = false, +-- show_current_context = true, +-- show_current_context_start = true, +-- } diff --git a/lua/configs/cmp.lua b/lua/configs/cmp.lua new file mode 100644 index 0000000..e69de29 diff --git a/lua/configs/conform.lua b/lua/configs/conform.lua new file mode 100644 index 0000000..4459375 --- /dev/null +++ b/lua/configs/conform.lua @@ -0,0 +1,15 @@ +local options = { + formatters_by_ft = { + lua = { "stylua" }, + -- css = { "prettier" }, + -- html = { "prettier" }, + }, + + format_on_save = { + -- These options will be passed to conform.format() + timeout_ms = 500, + lsp_fallback = true, + }, +} + +return options diff --git a/lua/configs/diffview.lua b/lua/configs/diffview.lua new file mode 100644 index 0000000..a564707 --- /dev/null +++ b/lua/configs/diffview.lua @@ -0,0 +1 @@ +return {} diff --git a/lua/configs/gitlab.lua b/lua/configs/gitlab.lua new file mode 100644 index 0000000..1e260e3 --- /dev/null +++ b/lua/configs/gitlab.lua @@ -0,0 +1,138 @@ +local M = { + port = nil, -- The port of the Go server, which runs in the background, if omitted or `nil` the port will be chosen automatically + log_path = vim.fn.stdpath "cache" .. "/gitlab.nvim.log", -- Log path for the Go server + config_path = nil, -- Custom path for `.gitlab.nvim` file, please read the "Connecting to Gitlab" section + debug = { + go_request = false, + go_response = false, + }, + attachment_dir = nil, -- The local directory for files (see the "summary" section) + reviewer_settings = { + diffview = { + imply_local = false, -- If true, will attempt to use --imply_local option when calling |:DiffviewOpen| + }, + }, + connection_settings = { + insecure = false, -- Like curl's --insecure option, ignore bad x509 certificates on connection + }, + help = "g?", -- Opens a help popup for local keymaps when a relevant view is focused (popup, discussion panel, etc) + popup = { -- The popup for comment creation, editing, and replying + keymaps = { + next_field = "", -- Cycle to the next field. Accepts count. + prev_field = "", -- Cycle to the previous field. Accepts count. + }, + perform_action = "s", -- Once in normal mode, does action (like saving comment or editing description, etc) + perform_linewise_action = "l", -- Once in normal mode, does the linewise action (see logs for this job, etc) + width = "50%", + height = "80%", + border = "rounded", -- One of " + opacity = 1.0, -- From 0.0 (fully transparent) to 1.0 (fully opaque) + comment = nil, -- Individual popup overrides, e.g. { width = "60%", height = "80%", border = "single", opacity = 0.85 }, + edit = nil, + note = nil, + pipeline = nil, + reply = nil, + squash_message = nil, + temp_registers = {}, -- List of registers for backing up popup content (see `:h gitlab.nvim.temp-registers`) + }, + discussion_tree = { -- The discussion tree that holds all comments + auto_open = true, -- Automatically open when the reviewer is opened + switch_view = "S", -- Toggles between the notes and discussions views + default_view = "discussions", -- Show "discussions" or "notes" by default + blacklist = {}, -- List of usernames to remove from tree (bots, CI, etc) + jump_to_file = "o", -- Jump to comment location in file + jump_to_reviewer = "m", -- Jump to the location in the reviewer window + edit_comment = "e", -- Edit comment + delete_comment = "dd", -- Delete comment + reply = "r", -- Reply to comment + toggle_node = "t", -- Opens or closes the discussion + add_emoji = "Ea", -- Add an emoji to the note/comment + -- add_emoji = "Ed", -- Remove an emoji from a note/comment + toggle_all_discussions = "T", -- Open or close separately both resolved and unresolved discussions + toggle_resolved_discussions = "R", -- Open or close all resolved discussions + toggle_unresolved_discussions = "U", -- Open or close all unresolved discussions + keep_current_open = false, -- If true, current discussion stays open even if it should otherwise be closed when toggling + publish_draft = "P", -- Publishes the currently focused note/comment + toggle_resolved = "p", -- Toggles the resolved status of the whole discussion + position = "left", -- "top", "right", "bottom" or "left" + open_in_browser = "b", -- Jump to the URL of the current note/discussion + copy_node_url = "u", -- Copy the URL of the current node to clipboard + size = "30%", -- Size of split + relative = "editor", -- Position of tree split relative to "editor" or "window" + resolved = "✓", -- Symbol to show next to resolved discussions + unresolved = "✗", -- Symbol to show next to unresolved discussions + tree_type = "by_file_name", -- Type of discussion tree - "simple" means just list of discussions, "by_file_name" means file tree with discussions under file + toggle_tree_type = "i", -- Toggle type of discussion tree - "simple", or "by_file_name" + draft_mode = false, -- Whether comments are posted as drafts as part of a review + toggle_draft_mode = "D", -- Toggle between draft mode (comments posted as drafts) and live mode (comments are posted immediately) + winbar = nil, -- Custom function to return winbar title, should return a string. Provided with WinbarTable (defined in annotations.lua) + -- If using lualine, please add "gitlab" to disabled file types, otherwise you will not see the winbar. + }, + choose_merge_request = { + open_reviewer = true, -- Open the reviewer window automatically after switching merge requests + }, + info = { -- Show additional fields in the summary view + enabled = true, + horizontal = false, -- Display metadata to the left of the summary rather than underneath + fields = { -- The fields listed here will be displayed, in whatever order you choose + "author", + "created_at", + "updated_at", + "merge_status", + "draft", + "conflicts", + "assignees", + "reviewers", + "pipeline", + "branch", + "target_branch", + "delete_branch", + "squash", + "labels", + }, + }, + discussion_signs = { + enabled = true, -- Show diagnostics for gitlab comments in the reviewer + skip_resolved_discussion = false, -- Show diagnostics for resolved discussions + severity = vim.diagnostic.severity.INFO, -- ERROR, WARN, INFO, or HINT + virtual_text = false, -- Whether to show the comment text inline as floating virtual text + priority = 100, -- Higher will override LSP warnings, etc + icons = { + comment = "→|", + range = " |", + }, + }, + pipeline = { + created = "", + pending = "", + preparing = "", + scheduled = "", + running = "", + canceled = "↪", + skipped = "↪", + success = "✓", + failed = "", + }, + create_mr = { + target = "master", -- Default branch to target when creating an MR + template_file = nil, -- Default MR template in .gitlab/merge_request_templates + delete_branch = false, -- Whether the source branch will be marked for deletion + squash = false, -- Whether the commits will be marked for squashing + title_input = { -- Default settings for MR title input window + width = 40, + border = "rounded", + }, + }, + colors = { + discussion_tree = { + username = "Keyword", + date = "Comment", + chevron = "DiffviewNonText", + directory = "Directory", + directory_icon = "DiffviewFolderSign", + file_name = "Normal", + }, + }, +} + +return M diff --git a/lua/configs/gitsigns.lua b/lua/configs/gitsigns.lua new file mode 100644 index 0000000..38505d0 --- /dev/null +++ b/lua/configs/gitsigns.lua @@ -0,0 +1,10 @@ +return { + signs = { + add = { text = "│" }, + change = { text = "│" }, + delete = { text = "󰍵" }, + topdelete = { text = "‾" }, + changedelete = { text = "~" }, + untracked = { text = "│" }, + }, +} diff --git a/lua/configs/hydra.lua b/lua/configs/hydra.lua new file mode 100644 index 0000000..e10e1f6 --- /dev/null +++ b/lua/configs/hydra.lua @@ -0,0 +1,35 @@ +local Hydra = require "hydra" + +Hydra { + name = "Change / Resize Window", + mode = { "n" }, + body = "t", + config = { + -- color = "pink", + }, + heads = { + -- move between windows + { "", "h", { desc = "Noot nooty" } }, + { "", "j" }, + { "", "k" }, + { "", "l" }, + + -- resizing window + { "H", "3<" }, + { "L", "3>" }, + { "K", "2+" }, + { "J", "2-" }, + + -- equalize window sizes + { "e", "=" }, + + -- close active window + { "Q", ":q" }, + { "", ":q" }, + + -- exit this Hydra + { "q", nil, { exit = true, nowait = true } }, + { ";", nil, { exit = true, nowait = true } }, + { "", nil, { exit = true, nowait = true } }, + }, +} diff --git a/lua/configs/lazy.lua b/lua/configs/lazy.lua new file mode 100644 index 0000000..cd170bd --- /dev/null +++ b/lua/configs/lazy.lua @@ -0,0 +1,47 @@ +return { + defaults = { lazy = true }, + install = { colorscheme = { "nvchad" } }, + + ui = { + icons = { + ft = "", + lazy = "󰂠 ", + loaded = "", + not_loaded = "", + }, + }, + + performance = { + rtp = { + disabled_plugins = { + "2html_plugin", + "tohtml", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", + "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", + }, + }, + }, +} diff --git a/lua/configs/lspconfig.lua b/lua/configs/lspconfig.lua new file mode 100644 index 0000000..935311d --- /dev/null +++ b/lua/configs/lspconfig.lua @@ -0,0 +1,24 @@ +-- load defaults i.e lua_lsp +require("nvchad.configs.lspconfig").defaults() + +local lspconfig = require "lspconfig" + +-- EXAMPLE +local servers = { "html", "cssls" } +local nvlsp = require "nvchad.configs.lspconfig" + +-- lsps with default config +for _, lsp in ipairs(servers) do + lspconfig[lsp].setup { + on_attach = nvlsp.on_attach, + on_init = nvlsp.on_init, + capabilities = nvlsp.capabilities, + } +end + +-- configuring single server, example: typescript +-- lspconfig.tsserver.setup { +-- on_attach = nvlsp.on_attach, +-- on_init = nvlsp.on_init, +-- capabilities = nvlsp.capabilities, +-- } diff --git a/lua/configs/luasnip.lua b/lua/configs/luasnip.lua new file mode 100644 index 0000000..9afc87c --- /dev/null +++ b/lua/configs/luasnip.lua @@ -0,0 +1,28 @@ +local luasnip = function(opts) + require("luasnip").config.set_config(opts) + + -- vscode format + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_vscode").lazy_load { paths = vim.g.vscode_snippets_path or "" } + + -- snipmate format + require("luasnip.loaders.from_snipmate").load() + require("luasnip.loaders.from_snipmate").lazy_load { paths = vim.g.snipmate_snippets_path or "" } + + -- lua format + require("luasnip.loaders.from_lua").load() + require("luasnip.loaders.from_lua").lazy_load { paths = vim.g.lua_snippets_path or "" } + + vim.api.nvim_create_autocmd("InsertLeave", { + callback = function() + if + require("luasnip").session.current_nodes[vim.api.nvim_get_current_buf()] + and not require("luasnip").session.jump_active + then + require("luasnip").unlink_current() + end + end, + }) +end + +return luasnip diff --git a/lua/configs/mason.lua b/lua/configs/mason.lua new file mode 100644 index 0000000..2850f72 --- /dev/null +++ b/lua/configs/mason.lua @@ -0,0 +1,28 @@ +local options = { + ensure_installed = { "lua-language-server" }, -- not an option from mason.nvim + + PATH = "prepand", + + ui = { + icons = { + package_pending = " ", + package_installed = "󰄳 ", + package_uninstalled = " 󰚌", + }, + + keymaps = { + toggle_server_expand = "", + install_server = "i", + update_server = "u", + check_server_version = "c", + update_all_servers = "U", + check_outdated_servers = "C", + uninstall_server = "X", + cancel_installation = "", + }, + }, + + max_concurrent_installers = 10, +} + +return options diff --git a/lua/configs/noice.lua b/lua/configs/noice.lua new file mode 100644 index 0000000..e1c23c4 --- /dev/null +++ b/lua/configs/noice.lua @@ -0,0 +1,46 @@ +local M = { + lsp = { + -- override markdown rendering so that **cmp** and other plugins use **Treesitter** + override = { + ["vim.lsp.util.convert_input_to_markdown_lines"] = true, + ["vim.lsp.util.stylize_markdown"] = true, + }, + }, + -- you can enable a preset for easier configuration + presets = { + bottom_search = true, -- use a classic bottom cmdline for search + command_palette = true, -- position the cmdline and popupmenu together + long_message_to_split = true, -- long messages will be sent to a split + inc_rename = false, -- enables an input dialog for inc-rename.nvim + lsp_doc_border = false, -- add a border to hover docs and signature help + }, + views = { + cmdline_popup = { + -- border = { + -- style = "none", + -- padding = { 2, 3 }, + -- }, + -- position = { + -- row = "85%", + -- col = "50%", + -- }, + size = { + width = 120, + height = "auto", + }, + }, + popupmenu = { + -- relative = "editor", + -- position = { + -- row = 25, + -- col = "50%", + -- }, + size = { + width = 120, + -- height = 10, + }, + }, + }, +} + +return M diff --git a/lua/configs/nvimtree.lua b/lua/configs/nvimtree.lua new file mode 100644 index 0000000..b4a8aee --- /dev/null +++ b/lua/configs/nvimtree.lua @@ -0,0 +1,77 @@ +local options = { + filters = { + dotfiles = false, + exclude = { vim.fn.stdpath "config" .. "/lua/custom" }, + }, + disable_netrw = true, + hijack_netrw = true, + hijack_cursor = true, + hijack_unnamed_buffer_when_opening = false, + sync_root_with_cwd = true, + update_focused_file = { + enable = true, + update_root = false, + }, + view = { + adaptive_size = false, + side = "left", + width = 30, + preserve_window_proportions = true, + }, + git = { + enable = false, + ignore = true, + }, + filesystem_watchers = { + enable = true, + }, + actions = { + open_file = { + resize_window = true, + }, + }, + renderer = { + root_folder_label = false, + highlight_git = false, + highlight_opened_files = "none", + + indent_markers = { + enable = false, + }, + + icons = { + show = { + file = true, + folder = true, + folder_arrow = true, + git = false, + }, + + glyphs = { + default = "󰈚", + symlink = "", + folder = { + default = "", + empty = "", + empty_open = "", + open = "", + symlink = "", + symlink_open = "", + arrow_open = "", + arrow_closed = "", + }, + git = { + unstaged = "✗", + staged = "✓", + unmerged = "", + renamed = "➜", + untracked = "★", + deleted = "", + ignored = "◌", + }, + }, + }, + }, +} + +return options diff --git a/lua/configs/ruff_lsp.lua b/lua/configs/ruff_lsp.lua new file mode 100644 index 0000000..09eadf5 --- /dev/null +++ b/lua/configs/ruff_lsp.lua @@ -0,0 +1,48 @@ +-- See: https://github.com/neovim/nvim-lspconfig/tree/54eb2a070a4f389b1be0f98070f81d23e2b1a715#suggested-configuration +local opts = { noremap = true, silent = true } +vim.keymap.set("n", "k", 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) +-- vim.keymap.set('n', 'q', vim.diagnostic.setloclist, opts) + +-- Use an on_attach function to only map the following keys +-- after the language server attaches to the current buffer +local on_attach = function(_, bufnr) + -- Enable completion triggered by + vim.api.nvim_buf_set_option(bufnr, "omnifunc", "v:lua.vim.lsp.omnifunc") + + -- Mappings. + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap = true, silent = true, buffer = bufnr } + -- vim.keymap.set("n", "gD", vim.lsp.buf.declaration, bufopts) + -- vim.keymap.set("n", "gd", vim.lsp.buf.definition, bufopts) + -- vim.keymap.set("n", "K", vim.lsp.buf.hover, bufopts) + -- vim.keymap.set("n", "gi", vim.lsp.buf.implementation, bufopts) + -- vim.keymap.set('n', '', vim.lsp.buf.signature_help, bufopts) + -- vim.keymap.set("n", "wa", vim.lsp.buf.add_workspace_folder, bufopts) + -- vim.keymap.set("n", "wr", vim.lsp.buf.remove_workspace_folder, bufopts) + -- vim.keymap.set("n", "wl", function() + -- print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + -- end, bufopts) + + -- vim.keymap.set("n", "D", vim.lsp.buf.type_definition, bufopts) + -- vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) + vim.keymap.set("n", "ca", vim.lsp.buf.code_action, bufopts) + -- vim.keymap.set("n", "gr", vim.lsp.buf.references, bufopts) + -- vim.keymap.set("n", "f", function() + -- vim.lsp.buf.format { async = true } + -- end, bufopts) +end + +-- Configure `ruff-lsp`. +-- See: https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#ruff_lsp +-- For the default config, along with instructions on how to customize the settings +require("lspconfig").ruff_lsp.setup { + on_attach = on_attach, + init_options = { + settings = { + -- Any extra CLI arguments for `ruff` go here. + args = { "--ignore", "E741" }, + }, + }, +} diff --git a/lua/configs/telescope/commands.lua b/lua/configs/telescope/commands.lua new file mode 100644 index 0000000..e86fc7e --- /dev/null +++ b/lua/configs/telescope/commands.lua @@ -0,0 +1,3 @@ +return { + { "Replace {{X}} with {{ X }} in jinja template", "%s/{{\\(.[^ ]*\\)}}/{{ \\1 }}/g" }, +} diff --git a/lua/configs/telescope/custom.lua b/lua/configs/telescope/custom.lua new file mode 100644 index 0000000..123f088 --- /dev/null +++ b/lua/configs/telescope/custom.lua @@ -0,0 +1,108 @@ +-- Implement delta as previewer for diffs + +local previewers = require "telescope.previewers" +local builtin = require "telescope.builtin" +local pickers = require "telescope.pickers" +local finders = require "telescope.finders" +local actions = require "telescope.actions" +local action_state = require "telescope.actions.state" +local conf = require("telescope.config").values + +local E = {} + +local delta = previewers.new_termopen_previewer { + get_command = function(entry) + -- this is for status + -- You can get the AM things in entry.status. So we are displaying file if entry.status == '??' or 'A ' + -- just do an if and return a different command + if entry.status == "??" or "A " then + return { "git", "-c", "core.pager=delta", "-c", "delta.side-by-side=false", "diff", entry.value } + end + + -- note we can't use pipes + -- this command is for git_commits and git_bcommits + return { "git", "-c", "core.pager=delta", "-c", "delta.side-by-side=false", "diff", entry.value .. "^!" } + end, +} + +E.my_git_commits = function(opts) + opts = opts or {} + opts.previewer = delta + + builtin.git_commits(opts) +end + +E.my_git_bcommits = function(opts) + opts = opts or {} + opts.previewer = delta + + builtin.git_bcommits(opts) +end + +E.my_git_status = function(opts) + opts = opts or {} + opts.previewer = delta + + builtin.git_status(opts) +end + +E.my_git_branches = function(opts) + opts = opts or {} + opts.previewer = delta + + builtin.git_branches(opts) +end + +E.project_files = function() + local opts = {} -- define here if you want to define something + vim.fn.system "git rev-parse --is-inside-work-tree" + if vim.v.shell_error == 0 then + require("telescope.builtin").git_files(opts) + else + require("telescope.builtin").find_files(opts) + end +end + +local custom_commands = require "configs.telescope.commands" + +E.cpickers = function(opts) + opts = opts or {} + pickers + .new(opts, { + prompt_title = "Commands", + + finder = finders.new_table { + results = custom_commands, + entry_maker = function(entry) + return { + value = entry, + display = entry[1], + ordinal = entry[2], + } + end, + }, + + previewer = previewers.new_buffer_previewer { + title = "Custom commands preview", + define_preview = function(self, entry, _) + vim.api.nvim_buf_set_lines(self.state.bufnr, 0, -1, false, { + entry["ordinal"], + }) + end, + }, + + attach_mappings = function(prompt_bufnr, _) + actions.select_default:replace(function() + actions.close(prompt_bufnr) + local selection = action_state.get_selected_entry() + vim.cmd(selection.ordinal) + end) + return true + end, + + sorter = conf.generic_sorter(opts), + }) + :find() +end + +return E diff --git a/lua/configs/telescope/init.lua b/lua/configs/telescope/init.lua new file mode 100644 index 0000000..1a5fbca --- /dev/null +++ b/lua/configs/telescope/init.lua @@ -0,0 +1,351 @@ +local custom_actions = {} +local actions = require "telescope.actions" +local lga_actions = require "telescope-live-grep-args.actions" +local action_state = require "telescope.actions.state" +local from_entry = require "telescope.from_entry" +local scan = require "plenary.scandir" +local pickers = require "telescope.pickers" +local finders = require "telescope.finders" +local make_entry = require "telescope.make_entry" +local action_set = require "telescope.actions.set" +local conf = require("telescope.config").values +local builtin = require "telescope.builtin" + +-- Usefull: +-- [[ +-- https://github.com/JoosepAlviste/dotfiles/blob/master/config/nvim/lua/j/telescope_custom_pickers.lua +-- ]] + +local entry_to_qf = function(entry) + local text = entry.text + + if not text then + if type(entry.value) == "table" then + text = entry.value.text + else + text = entry.value + end + end + + return { + bufnr = entry.bufnr, + filename = from_entry.path(entry, false, false), + lnum = vim.F.if_nil(entry.lnum, 1), + col = vim.F.if_nil(entry.col, 1), + text = text, + } +end + +local send_selected_to_list_without_closing_prompt = function(prompt_bufnr, mode, target) + local picker = action_state.get_current_picker(prompt_bufnr) + + local qf_entries = {} + for _, entry in ipairs(picker:get_multi_selection()) do + table.insert(qf_entries, entry_to_qf(entry)) + end + + local prompt = picker:_get_prompt() + -- actions.close(prompt_bufnr) + + vim.api.nvim_exec_autocmds("QuickFixCmdPre", {}) + if target == "loclist" then + vim.fn.setloclist(picker.original_win_id, qf_entries, mode) + else + local qf_title = string.format([[%s (%s)]], picker.prompt_title, prompt) + vim.fn.setqflist(qf_entries, mode) + vim.fn.setqflist({}, "a", { title = qf_title }) + end + vim.api.nvim_exec_autocmds("QuickFixCmdPost", {}) +end + +function custom_actions._multiopen(prompt_bufnr, cmd, cmd2, mode, list) + -- actions.send_selected_to_loclist(prompt_bufnr) + local picker = action_state.get_current_picker(prompt_bufnr) + local multi = picker:get_multi_selection() + local single = picker:get_selection() + + local str = "" + + if #multi > 0 then + send_selected_to_list_without_closing_prompt(prompt_bufnr, mode, list) + + for i, j in ipairs(multi) do + if i % 2 == 1 then + str = str .. cmd .. " " .. j[1] .. " | " + else + str = str .. cmd2 .. " " .. j[1] .. " | " + end + end + else + str = cmd .. " " .. single[1] + end + + -- To avoid populating qf or doing ":edit! file", close the prompt first + actions.close(prompt_bufnr) + vim.api.nvim_command(str) +end + +function custom_actions.multi_selection_open(prompt_bufnr) + return custom_actions._multiopen(prompt_bufnr, "edit", "edit", "a", "loclist") +end + +function custom_actions.multi_selection_vsplit(prompt_bufnr) + return custom_actions._multiopen(prompt_bufnr, "vsplit", "split", "a", "loclist") +end + +function custom_actions.multi_selection_split(prompt_bufnr) + return custom_actions._multiopen(prompt_bufnr, "split", "vsplit", "a", "loclist") +end + +function custom_actions.multi_selection_vtab(prompt_bufnr) + return custom_actions._multiopen(prompt_bufnr, "tabe", "tabe", "a", "loclist") +end + +function custom_actions.set_extension(prompt_bufnr) + local current_input = action_state.get_current_line() + + vim.ui.input({ prompt = "Search in extension: *." }, function(input) + if input == nil then + return + end + + -- Close and reopen a prompt with the same input + actions.close(prompt_bufnr) + builtin.live_grep { default_text = current_input, type_filter = input } + end) +end + +function custom_actions.to_live_grep_args(prompt_bufnr) + local current_input = action_state.get_current_line() + + -- Close and reopen a prompt with live_grep_args + actions.close(prompt_bufnr) + require("telescope").extensions.live_grep_args.live_grep_args { default_text = current_input } +end + +function custom_actions.set_folders(prompt_bufnr) + local current_input = action_state.get_current_line() + + local data = {} + scan.scan_dir(vim.loop.cwd(), { + hidden = true, + only_dirs = true, + respect_gitignore = true, + on_insert = function(entry) + table.insert(data, entry .. "/") + end, + }) + table.insert(data, 1, "./") + + actions.close(prompt_bufnr) + -- Create a new picker with Telescope to select folders we want to filter in + pickers + .new({ + prompt_title = 'Select folders for current ("' .. current_input .. '") search', + finder = finders.new_table { results = data, entry_maker = make_entry.gen_from_file {} }, + previewer = conf.file_previewer {}, + sorter = conf.file_sorter {}, + attach_mappings = function(prompt_bufnr2) + action_set.select:replace(function() + local current_picker = action_state.get_current_picker(prompt_bufnr2) + + local dirs = {} + local selections = current_picker:get_multi_selection() + if vim.tbl_isempty(selections) then + table.insert(dirs, action_state.get_selected_entry().value) + else + for _, selection in ipairs(selections) do + table.insert(dirs, selection.value) + end + end + + actions.close(prompt_bufnr2) + builtin.live_grep { default_text = current_input, search_dirs = dirs } + end) + return true + end, + }) + :find() +end + +function custom_actions.set_files(prompt_bufnr) + local current_input = action_state.get_current_line() + local find_command = { "rg", "--files", "--color=never", "--no-heading" } + actions.close(prompt_bufnr) + if current_input ~= "" then + find_command = { "rg", "--color=never", "--no-heading", "-l", current_input } + end + + local opts = { + entry_maker = make_entry.gen_from_file(), + find_command = find_command, + } + + print(vim.inspect(find_command)) + -- Create a new picker with Telescope to select files we want to filter in + pickers + .new(opts, { + prompt_title = 'Select files for current ("' .. current_input .. '") search', + __locations_input = true, + finder = finders.new_oneshot_job(find_command, opts), + previewer = conf.grep_previewer(opts), + sorter = conf.file_sorter(opts), + attach_mappings = function(prompt_bufnr2) + actions.select_default:replace(function() + local current_picker = action_state.get_current_picker(prompt_bufnr2) + + local files = {} + local selections = current_picker:get_multi_selection() + if vim.tbl_isempty(selections) then + local entry = action_state.get_selected_entry() + table.insert(files, entry.value) + else + for _, selection in ipairs(selections) do + table.insert(files, selection.value) + end + end + + -- Close the preview picker and select a new one, restricted to the files selected + actions.close(prompt_bufnr2) + builtin.live_grep { default_text = current_input, search_dirs = files } + end) + return true + end, + }) + :find() +end + +local options = { + defaults = { + vimgrep_arguments = { + "rg", + "-L", + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + "--smart-case", + }, + prompt_prefix = "  ", + selection_caret = " ", + entry_prefix = " ", + initial_mode = "insert", + selection_strategy = "reset", + sorting_strategy = "ascending", + layout_strategy = "horizontal", + layout_config = { + horizontal = { + prompt_position = "top", + preview_width = 0.60, + results_width = 0.8, + }, + vertical = { + mirror = false, + }, + width = 0.90, + height = 0.92, + preview_cutoff = 200, + }, + file_sorter = require("telescope.sorters").get_fuzzy_file, + file_ignore_patterns = { "node_modules" }, + generic_sorter = require("telescope.sorters").get_generic_fuzzy_sorter, + path_display = { "truncate" }, + winblend = 0, + border = {}, + borderchars = { "─", "│", "─", "│", "╭", "╮", "╯", "╰" }, + color_devicons = true, + set_env = { ["COLORTERM"] = "truecolor" }, -- default = nil, + file_previewer = require("telescope.previewers").vim_buffer_cat.new, + grep_previewer = require("telescope.previewers").vim_buffer_vimgrep.new, + qflist_previewer = require("telescope.previewers").vim_buffer_qflist.new, + -- Developer configurations: Not meant for general override + buffer_previewer_maker = require("telescope.previewers").buffer_previewer_maker, + mappings = { + n = { ["q"] = actions.close }, + }, + }, + pickers = { + buffers = { + show_all_buffers = true, + sort_lastused = true, + mappings = { + n = { + ["d"] = "delete_buffer", + }, + i = { + [""] = "delete_buffer", + }, + }, + }, + find_files = { + mappings = { + i = { + -- Fuzzy refine ("Freeze the current list and start a fuzzy search in the frozen list") + [""] = actions.to_fuzzy_refine, + + -- Send to qflist or loclist + [""] = actions.smart_send_to_loclist, + [""] = actions.smart_send_to_qflist, + + -- Multi selection open + [""] = custom_actions.multi_selection_open, + [""] = custom_actions.multi_selection_vsplit, + [""] = custom_actions.multi_selection_split, + [""] = custom_actions.multi_selection_tab, + }, + n = i, + }, + }, + live_grep = { + mappings = { + i = { + -- Fuzzy refine ("Freeze the current list and start a fuzzy search in the frozen list") + [""] = actions.to_fuzzy_refine, + + -- Send to qflist or loclist + [""] = actions.smart_send_to_loclist, + [""] = actions.smart_send_to_qflist, + + -- To quote prompt -> Pass to live_grep_args + [""] = custom_actions.to_live_grep_args, + + -- Search for files/folder/extensions + [""] = custom_actions.set_files, + [""] = custom_actions.set_folders, + [""] = custom_actions.set_extension, + }, + n = i, + }, + }, + }, + + extensions_list = { "themes", "terms", "fzf", "macrothis", "live_grep_args", "advanced_git_search" }, + extensions = { + fzf = { + fuzzy = true, + override_generic_sorter = true, + override_file_sorter = true, + case_mode = "smart_case", + }, + live_grep_args = { + auto_quoting = true, + mappings = { + i = { + -- Fuzzy refine ("Freeze the current list and start a fuzzy search in the frozen list") + [""] = actions.to_fuzzy_refine, + + -- Send to qflist or loclist + [""] = actions.smart_send_to_loclist, + [""] = actions.smart_send_to_qflist, + + -- Quote prompt, for passing parameters to vimgrep + [""] = lga_actions.quote_prompt(), + }, + }, + advanced_git_search = {}, + }, + }, +} + +return options diff --git a/lua/configs/treesitter.lua b/lua/configs/treesitter.lua new file mode 100644 index 0000000..897c4e3 --- /dev/null +++ b/lua/configs/treesitter.lua @@ -0,0 +1,12 @@ +local options = { + ensure_installed = { "lua", "vim", "vimdoc" }, + + highlight = { + enable = true, + use_languagetree = true, + }, + + indent = { enable = true }, +} + +return options diff --git a/lua/configs/treesitter_textobjects.lua b/lua/configs/treesitter_textobjects.lua new file mode 100644 index 0000000..9d50c83 --- /dev/null +++ b/lua/configs/treesitter_textobjects.lua @@ -0,0 +1,133 @@ +local M = {} + +M.textobjects = { + select = { + enable = true, + + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + + keymaps = { + -- You can use the capture groups defined in textobjects.scm + ["a="] = { query = "@assignment.outer", desc = "Select outer part of an assignment" }, + ["i="] = { query = "@assignment.inner", desc = "Select inner part of an assignment" }, + ["l="] = { query = "@assignment.lhs", desc = "Select left hand side of an assignment" }, + ["r="] = { query = "@assignment.rhs", desc = "Select right hand side of an assignment" }, + + ["aa"] = { query = "@parameter.outer", desc = "Select outer part of a parameter/argument" }, + ["ia"] = { query = "@parameter.inner", desc = "Select inner part of a parameter/argument" }, + + ["ai"] = { query = "@conditional.outer", desc = "Select outer part of a conditional" }, + ["ii"] = { query = "@conditional.inner", desc = "Select inner part of a conditional" }, + + ["al"] = { query = "@loop.outer", desc = "Select outer part of a loop" }, + ["il"] = { query = "@loop.inner", desc = "Select inner part of a loop" }, + + ["af"] = { query = "@call.outer", desc = "Select outer part of a function call" }, + ["if"] = { query = "@call.inner", desc = "Select inner part of a function call" }, + + ["am"] = { query = "@function.outer", desc = "Select outer part of a function def" }, + ["im"] = { query = "@function.inner", desc = "Select inner part of a function def" }, + + ["ak"] = { query = "@class.outer", desc = "Select outer part of a class" }, + ["ik"] = { query = "@class.inner", desc = "Select inner part of a class" }, + + ["ac"] = { query = "@comment.outer", desc = "Select outer part of a comment" }, + ["ic"] = { query = "@comment.inner", desc = "Select inner part of a comment" }, + }, + }, + move = { + enable = true, + -- Whether to set jumps in the jumplist + set_jumps = true, + goto_next_start = { + ["]a"] = { query = "@parameter.outer", desc = "Goto next start outer parameter" }, + ["]i"] = { query = "@conditional.outer", desc = "Goto next start outer conditional" }, + ["]l"] = { query = "@loop.outer", desc = "Goto next start outer loop" }, + ["]f"] = { query = "@call.outer", desc = "Goto next start outer call" }, + ["]m"] = { query = "@function.outer", desc = "Goto next start outer function" }, + ["]k"] = { query = "@class.outer", desc = "Goto next start outer class" }, + ["]c"] = { query = "@comment.outer", desc = "Goto next start outer comment" }, + }, + goto_next_end = { + ["]A"] = { query = "@parameter.outer", desc = "Goto next end outer parameter" }, + ["]I"] = { query = "@conditional.outer", desc = "Goto next end outer conditional" }, + ["]L"] = { query = "@loop.outer", desc = "Goto next end outer loop" }, + ["]F"] = { query = "@call.outer", desc = "Goto next end outer call" }, + ["]M"] = { query = "@function.outer", desc = "Goto next end outer function" }, + ["]K"] = { query = "@class.outer", desc = "Goto next end outer class" }, + ["]C"] = { query = "@comment.outer", desc = "Goto next end outer comment" }, + }, + goto_previous_start = { + ["[a"] = { query = "@parameter.outer", desc = "Goto previous start outer parameter" }, + ["[i"] = { query = "@conditional.outer", desc = "Goto previous start outer conditional" }, + ["[l"] = { query = "@loop.outer", desc = "Goto previous start outer loop" }, + ["[f"] = { query = "@call.outer", desc = "Goto previous start outer call" }, + ["[m"] = { query = "@function.outer", desc = "Goto previous start outer function" }, + ["[k"] = { query = "@class.outer", desc = "Goto previous start outer class" }, + ["[c"] = { query = "@comment.outer", desc = "Goto previous start outer comment" }, + }, + goto_previous_end = { + ["[A"] = { query = "@parameter.outer", desc = "Goto previous end outer parameter" }, + ["[I"] = { query = "@conditional.outer", desc = "Goto previous end outer conditional" }, + ["[L"] = { query = "@loop.outer", desc = "Goto previous end outer loop" }, + ["[F"] = { query = "@call.outer", desc = "Goto previous end outer call" }, + ["[M"] = { query = "@function.outer", desc = "Goto previous end outer function" }, + ["[K"] = { query = "@class.outer", desc = "Goto previous end outer class" }, + ["[C"] = { query = "@comment.outer", desc = "Goto previous end outer comment" }, + }, + }, + + swap = { + enable = true, + + swap_next = { + ["na"] = { query = "@parameter.inner", desc = "Swap with next inner parameter" }, + ["ni"] = { query = "@conditional.outer", desc = "Swap with next outer conditional" }, + ["nl"] = { query = "@loop.outer", desc = "Swap with next outer loop" }, + ["nf"] = { query = "@call.outer", desc = "Swap with next outer call" }, + ["nm"] = { query = "@function.outer", desc = "Swap with next outer function" }, + ["nk"] = { query = "@class.outer", desc = "Swap with next outer class" }, + ["nc"] = { query = "@comment.outer", desc = "Swap with next outer comment" }, + + ["nA"] = { query = "@parameter.outer", desc = "Swap with next outer parameter" }, + ["nI"] = { query = "@conditional.inner", desc = "Swap with next inner conditional" }, + ["nL"] = { query = "@loop.inner", desc = "Swap with next inner loop" }, + ["nF"] = { query = "@call.inner", desc = "Swap with next inner call" }, + ["nM"] = { query = "@function.inner", desc = "Swap with next inner function" }, + ["nK"] = { query = "@class.inner", desc = "Swap with next inner class" }, + ["nC"] = { query = "@comment.inner", desc = "Swap with next inner comment" }, + }, + swap_previous = { + ["pa"] = { query = "@parameter.inner", desc = "Swap with previous inner parameter" }, + ["pi"] = { query = "@conditional.outer", desc = "Swap with previous outer conditional" }, + ["pl"] = { query = "@loop.outer", desc = "Swap with previous outer loop" }, + ["pf"] = { query = "@call.outer", desc = "Swap with previous outer call" }, + ["pm"] = { query = "@function.outer", desc = "Swap with previous outer function" }, + ["pk"] = { query = "@class.outer", desc = "Swap with previous outer class" }, + ["pc"] = { query = "@comment.outer", desc = "Swap with previous outer comment" }, + + ["pA"] = { query = "@parameter.outer", desc = "Swap with previous outer parameter" }, + ["pI"] = { query = "@conditional.inner", desc = "Swap with previous inner conditional" }, + ["pL"] = { query = "@loop.inner", desc = "Swap with previous inner loop" }, + ["pF"] = { query = "@call.inner", desc = "Swap with previous inner call" }, + ["pM"] = { query = "@function.inner", desc = "Swap with previous inner function" }, + ["pK"] = { query = "@class.inner", desc = "Swap with previous inner class" }, + ["pC"] = { query = "@comment.inner", desc = "Swap with previous inner comment" }, + }, + }, +} + +-- local ts_repeat_move = require "nvim-treesitter.textobjects.repeatable_move" + +-- Repeat movement with ; and , +-- vim.keymap.set({"n", "x", "o"}, ",", ts_repeat_move.repeat_last_move_next) +-- vim.keymap.set({"n", "x", "o"}, ",", ts_repeat_move.repeat_last_move_previous) + +-- Optionnally, make builtin f, F, t, T also repeatable with ; and , +-- vim.keymap.set({"n", "x", "o"}, "f", ts_repeat_move.builtin_f) +-- vim.keymap.set({"n", "x", "o"}, "F", ts_repeat_move.builtin_F) +-- vim.keymap.set({"n", "x", "o"}, "t", ts_repeat_move.builtin_t) +-- vim.keymap.set({"n", "x", "o"}, "T", ts_repeat_move.builtin_T) + +return M diff --git a/lua/mappings.lua b/lua/mappings.lua new file mode 100644 index 0000000..13c2c17 --- /dev/null +++ b/lua/mappings.lua @@ -0,0 +1,477 @@ +local map = vim.keymap.set + +map("n", ";", ":", { desc = "CMD enter command mode" }) +map("i", "jk", "") + +map("n", "", ":Telescope resume ", { desc = "Telescope resume" }) +map("n", "", ":Telescope keymaps ", { desc = "Show (and search) all [k]eymaps" }) + +map("n", "", ":Telescope find_files ", { desc = "Find files" }) +map("n", "", ":Telescope find_files follow=true no_ignore=true hidden=true ", { desc = "Find all files" }) +map("n", "", ":Telescope live_grep ", { desc = "Live grep" }) +map("n", "", ":Telescope buffers ", { desc = "Find buffers" }) +map("n", "/", ":Telescope search_history ", { desc = "Search history" }) +map("n", "//", ":noh", { desc = "Clear highlights" }) + +-- go to beginning and end +map("i", "", "^i", { desc = "Beginning of line" }) +map("i", "", "", { desc = "End of line" }) + +-- navigate within insert mode +map("i", "", "", { desc = "Move left" }) +map("i", "", "", { desc = "Move right" }) +map("i", "", "", { desc = "Move down" }) +map("i", "", "", { desc = "Move up" }) + +map("n", "", " w ", { desc = "Save file" }) + +map("n", "rr", ":source $MYVIMRC", { desc = "Reload config file" }) +map("n", "", " noh ", { desc = "Clear highlights" }) +-- switch between windows +map("n", "", "h", { desc = "Window left" }) +map("n", "", "l", { desc = "Window right" }) +map("n", "", "j", { desc = "Window down" }) +map("n", "", "k", { desc = "Window up" }) + +-- [""] = { " tab Git diff %", "Git diff this file" }, +map("n", "", " DiffviewOpen -- %", { desc = "Git diff this file" }) +map("n", "", " DiffviewFileHistory %", { desc = "Git history diff this file" }) +map("n", "", " DiffviewClose", { desc = "Close git diff" }) +-- [""] = { " tab Git diff", "Git diff global" }, +map("n", "", " DiffviewOpen", { desc = "Git diff global" }) +map("n", "", ":DiffviewOpen HEAD~", { desc = "Show last N commits" }) +map("n", "gd", " DiffviewClose", { desc = "Git diff close" }) + +-- save +map("n", "", " w ", { desc = "Save file" }) +-- Quit +map("n", "", " q! ", { desc = "Force quit window" }) + +-- line numbers +-- map("n", "n", " set nu! ", { desc = "Toggle line number" }) +-- map("n", "rn", " set rnu! ", { desc = "Toggle relative number" }) + +-- Movement +-- Allow moving the cursor through wrapped lines with j, k, and +-- http://www.reddit.com/r/vim/comments/2k4cbr/problem_with_gj_and_gk/ +-- empty mode is same as using :map +-- also don't use gmap("n", j|k,n in operator pending mode, {desc = so it doesn't alter d, y or c behaviou) +-- map("n", "j", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { desc = "Move down", opts = { expr = true } }) +-- map("n", "k", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { desc = "Move up", opts = { expr = true } }) +-- map("n", "", 'v:count || mode(1)[0:1] == "no" ? "k" : "gk"', { desc = "Move up", opts = { expr = true } }) +-- map("n", "", 'v:count || mode(1)[0:1] == "no" ? "j" : "gj"', { desc = "Move down", opts = { expr = true } }) + +-- Copy/pasting into /tmp +-- map("n", "y", " :w! /tmp/vimtmp", { desc = "Save into a global tmp file" }) +-- map("n", "p", " :r! cat /tmp/vimtmp", { desc = "Restore from the global tmp file" }) + +-- (Double) Trouble +map("n", "tx", ":Trouble diagnostics toggle", { desc = "[T]rouble diagnostics" }) +map("n", "tX", ":Trouble diagnostics toggle filter.buf=0", { desc = "[T]rouble buffer diagnostics" }) +map("n", "ts", ":Trouble symbols toggle focus=false", { desc = "[T]rouble [S]ymbols" }) +map( + "n", + "tl", + ":Trouble lsp toggle focus=false win.position=right", + { desc = "[T]rouble [L]sp def / ref / ..." } +) +map("n", "tL", ":Trouble loclist toggle", { desc = "[T]rouble [L]oclist" }) +map("n", "tQ", ":Trouble qflist toggle", { desc = "[T]rouble [Q]uickfix" }) + +-- DAP +map("n", "dgg", ":lua require('dap').continue() ", { desc = "Continue debu[g]ging" }) +map("n", "dg", ":lua require('dapui').toggle() ", { desc = "Toggle DAP ui" }) +map("n", "dgw", ":lua require('dapui').eval() ", { desc = "Open floating windows about current [w]ord" }) +map("n", "dgb", ":lua require('dap').toggle_breakpoint() ", { desc = "Toggle [b]reakpoint" }) +map("n", "dgf", ":lua require('dap-python').test_method() ", { desc = "Debug [f]unction" }) +map("n", "dgo", ":lua require('dap').step_over() ", { desc = "DAP step [o]ver method" }) +map("n", "dgt", ":lua require('dap').step_into() ", { desc = "DAP step in[t]o method" }) +map("n", "dgp", ":lua require('dap').step_back() ", { desc = "DAP step back ([p]revious)" }) +map("n", "dgs", function() + local widgets = require "dap.ui.widgets" + local sidebar = widgets.sidebar(widgets.scopes) + sidebar.open { widgth = "50%" } +end, { desc = "DAP Show debugged [s]copes" }) +map("v", "dgd", ":lua require('dap-python').debug_selection()", { desc = "DAP debug selection" }) +map("v", "dgw", ":lua require('dap-python').eval()", { desc = "DAP eval selection" }) + +-- LSP +map("n", "fm", function() + vim.lsp.buf.format { async = true } +end, { desc = "LSP formatting" }) + +map("t", "", vim.api.nvim_replace_termcodes("", true, true, true), { desc = "Escape terminal mode" }) + +-- Indentation +map("v", "<", "", ">gv", { desc = "Indent line" }) + +-- Don't copy the replaced text after pasting in visual mode +-- https://vim.fandom.com/wiki/Replace_a_word_with_yanked_text#alternative_mapping_for_paste +map("x", "p", 'p:let @+=@0:let @"=@0', { desc = "Dont copy replaced text" }) + +map("n", "", "o", { desc = "Insert new line below" }) +map("n", "", "O", { desc = "Insert new line above" }) + +-- Vim fugitive +map( + "n", + "", + " vertical topleft Git vertical resize 50", + { desc = "Show Git status on a left pane" } +) + +-- Fn shortcuts +map("n", "", " tabprevious", { desc = "Previous tab" }) +map("n", "", " tabnext", { desc = "Next tab" }) +map("n", "", " Flog -all", { desc = "Show git tree" }) +map("n", "", " tab Git show -", { desc = "Git show N last commits" }) +map("n", "", " TagbarToggle", { desc = "Show tagbar" }) +map("n", "ra", " call VrcQuery()", { desc = "Call REST endpoint" }) +map("n", "dl", "0d$", { desc = "Delete line from start" }) + +-- Git stuffs +map("n", "gpu", " Git pull", { desc = "Git pull" }) +map("n", "gpf", ":Git push ", { desc = "Git push with option" }) +map("n", "gmm", " Git merge master", { desc = "Git merge master" }) +map("n", "gmi", ":Git merge ", { desc = "Git merge ..." }) +map( + "n", + "ga", + ":Git commit -a --amend --no-edit --no-verify", + { desc = "Git commit -a --amend --no-edit --no-verify" } +) +map("n", "gnb", ":Git checkout -b ", { desc = "Checkout to a new branch" }) +map("n", "gri", ":Git rebase -i HEAD~", { desc = "Git rebase interactive from HEAD" }) +map("n", "grm", ":Git rebase -i master", { desc = "Git rebase interactive from master" }) +map("n", "grr", ":Git rebase -i ", { desc = "Git rebase interactive from