diff --git a/.gitignore b/.gitignore index f54f7dd..ae26a60 100644 --- a/.gitignore +++ b/.gitignore @@ -96,3 +96,6 @@ dist-ssr *backup *undo *sessions +*.bak +nvim_switch/ +*kitty/*.py diff --git a/README.md b/README.md index 3e348b1..9d2a33f 100755 --- a/README.md +++ b/README.md @@ -19,4 +19,3 @@ Example: bash ./bootstrap.sh -q --create-links ## Why `--create-links`? I have multiple Linux installations on my machine. Linking it from one place (this repository) keeps things tidy. Also, changes to dotfiles automatically get applied to all the distros. - diff --git a/bootstrap.sh b/bootstrap.sh index cfe8876..4020553 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -13,7 +13,7 @@ QUIET="n" CREATE_LINKS="n" usage() { - if [ -n "$1" ]; then + if [ "$1" != "" ]; then echo "" echo -e "${CRED}$1${CEND}\n" fi @@ -29,32 +29,32 @@ usage() { } place_dotfile_at_target_location() { - local source_file_location="$1" - local file_target_location="$2" - local TS="$3" + source_file_location="$1" + file_target_location="$2" + TS="$3" # echo "${source_file_location}" # echo "${file_target_location}" # To avoid over writing existing dot file, we rename them # Appending the timestamp to file name - if [ -f "${file_target_location}" ] || [ -L "${file_target_location}" ]; then + if [ -f "$file_target_location" ] || [ -L "$file_target_location" ]; then # echo "mv ${file_target_location} ${file_target_location}_${TS}" && [[ "$QUIET" == "n" ]] && echo "Existing dotfile renamed to ${file_target_location}_${TS}" - mv "${file_target_location}" "${file_target_location}_${TS}" && [ "$QUIET" = "n" ] && echo "Existing setting renamed to ${file_target_location}_${TS}" + mv "$file_target_location" "${file_target_location}_${TS}" && [ "$QUIET" = "n" ] && echo "Existing setting renamed to ${file_target_location}_${TS}" fi - local target_directory - target_directory=$(dirname "${file_target_location}") - if [ ! -d "${target_directory}" ]; then - mkdir -p "${target_directory}" && [ "$QUIET" = "n" ] && echo "Directory ${target_directory} created" + target_directory + target_directory=$(dirname "$file_target_location") + if [ ! -d "$target_directory" ]; then + mkdir -p "$target_directory" && [ "$QUIET" = "n" ] && echo "Directory ${target_directory} created" fi if [ "$CREATE_LINKS" = "y" ]; then # echo "ln -s ${source_file_location} ${target_directory}" - ln -s "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Linked ${file_target_location}" + ln -s "$source_file_location" "$target_directory" && [ "$QUIET" = "n" ] && echo "Linked ${file_target_location}" else # echo "cp ${source_file_location} ${target_directory}" - cp "${source_file_location}" "${target_directory}" && [ "$QUIET" = "n" ] && echo "Copied ${file_target_location}" + cp "$source_file_location" "$target_directory" && [ "$QUIET" = "n" ] && echo "Copied ${file_target_location}" fi } @@ -92,6 +92,7 @@ main() { ;; *) OS="UNSUPPORTED" + ;; esac TS=$(date '+%d_%m_%Y-%H_%M_%S') @@ -100,20 +101,20 @@ main() { cd -P "$(dirname "$0")" || exit # Copy all files in "Common" dotfiles to $HOME directory ("~") - find "./common" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file; -do - local file_target_location="${file/.\/common/$HOME}" - local source_file_location="${file/./$PWD}" - place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" -done + find "./common" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; + do + file_target_location="${file/.\/common/$HOME}" + source_file_location="${file/./$PWD}" + place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" + done # Copy platform specific files to $HOME directory ("~") - find "./${OS}" -type f ! -path '*.DS_Store' ! -path '*.directory' -print0 | while IFS= read -r -d '' file; -do - local file_target_location="${file/.\/${OS}/$HOME}" - local source_file_location="${file/./$PWD}" - place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" -done + find "./${OS}" -type f -not -path '*.DS_Store' -not -path '*.directory' | while read -r file; + do + file_target_location="${file/.\/${OS}/$HOME}" + source_file_location="${file/./$PWD}" + place_dotfile_at_target_location "$source_file_location" "$file_target_location" "$TS" + done } main "$@" diff --git a/common/.bashrc b/common/.bashrc index 68489e8..d8b2c8f 100644 --- a/common/.bashrc +++ b/common/.bashrc @@ -179,10 +179,17 @@ HISTFILE="$XDG_STATE_HOME/shell/bash_history" [ ! -f "$XDG_CONFIG_HOME/exercism/exercism_completion.bash" ] || source "$XDG_CONFIG_HOME/exercism/exercism_completion.bash" if command -v zoxide >/dev/null; then - eval "$(zoxide init bash)" + eval "$(zoxide init --cmd cd bash)" fi # [ctrl+r]:replaces shell command search # [ctrl+t]:fzf & over the files & directories under the current one & paste it to prompt # [alt+c] :fzf & cd into a directory under the current one [ -f $XDG_STATE_HOME/shell/fzf.bash ] && source $XDG_STATE_HOME/shell/fzf.bash + +# Source aliases and shell functions +for alias_file in "$XDG_CONFIG_HOME"/shell/*.sh; do source "$alias_file"; done + +# TIP: Following should be executed AFTER the aliases are sourced +command -v op >/dev/null && bind '"^O":"op\n"' # Fuzzyfind projects and open in nvim +command -v pnew >/dev/null && bind '"^[o":"pnew\n"' # Create a new project quickly diff --git a/common/.config/kitty/kitty.conf b/common/.config/kitty/kitty.conf index 19486cd..487209d 100644 --- a/common/.config/kitty/kitty.conf +++ b/common/.config/kitty/kitty.conf @@ -2,8 +2,6 @@ # TODO: # - Display current directory on OS title: even when nvim or any other forground app is running -# - Vim keymaps +hjkl to move around splits: https://github.com/knubie/vim-kitty-navigator -# - OR + ??? in sync with konsole??? # - [/] to decrease/increase split size #: Fonts {{{ @@ -434,11 +432,11 @@ scrollback_pager nvim -c 'set ft=man' # Enable kitty scrollback.nvim plugin allow_remote_control yes -listen_on unix:/tmp/kitty +listen_on unix:@mykitty shell_integration enabled no-sudo no-complete action_alias kitty_scrollback_nvim kitten /home/pratik/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --nvim-args --clean --noplugin -n -map kitty_mod+h kitty_scrollback_nvim -map kitty_mod+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output +map kitty_mod+g kitty_scrollback_nvim +map kitty_mod+alt+g kitty_scrollback_nvim --config ksb_builtin_last_cmd_output mouse_map kitty_mod+right press ungrabbed combine : mouse_select_command_output : kitty_scrollback_nvim --config ksb_builtin_last_cmd_output map kitty_mod+f7 show_kitty_env_vars @@ -1029,14 +1027,32 @@ enable_audio_bell no # Hide title bar hide_window_decorations yes window_border_width 0.2pt -# New windows open in the same directory as the current window -map ctrl+shift+enter new_window_with_cwd + +# New splits open in the same directory as the current window +map shift+F1 new_window_with_cwd +map kitty_mod+enter new_window_with_cwd +map shift+F2 toggle_layout stack # Zoom the current window enabled_layouts fat:bias=75;full_size=1,stack,tall:bias=50;full_size=2 map F11 toggle_layout stack # Open nvim on the current directory with ctrl+shift+o -map ctrl+shift+o launch --cwd=current --type=tab nvim +map kitty_mod+o launch --cwd=current --type=tab nvim + +# Sync split navigation with VIM: https://github.com/knubie/vim-kitty-navigator +map ctrl+shift+j kitten pass_keys.py bottom ctrl+shift+j +map ctrl+shift+k kitten pass_keys.py top ctrl+shift+k +map ctrl+shift+h kitten pass_keys.py left ctrl+shift+h +map ctrl+shift+l kitten pass_keys.py right ctrl+shift+l +map ctrl+shift+j kitten pass_keys.py bottom ctrl+shift+j "^.* - nvim$" +map ctrl+shift+k kitten pass_keys.py top ctrl+shift+k "^.* - nvim$" +map ctrl+shift+h kitten pass_keys.py left ctrl+shift+h "^.* - nvim$" +map ctrl+shift+l kitten pass_keys.py right ctrl+shift+l "^.* - nvim$" + +# Redundant, they are used for scrollback.nvim as well +# But, this would work even if we uninstall scrollback.nvim +listen_on unix:@mykitty +allow_remote_control yes #: Tab bar {{{ @@ -1896,8 +1912,8 @@ update_check_interval 0 #: cause all invocations of the hints kitten to have the --hints- #: offset=0 option applied. -map ctrl+shift+p nth_window -1 -map ctrl+shift+n nth_window +1 +map kitty_mod+p nth_window -1 +map kitty_mod+n nth_window +1 #: Clipboard {{{ diff --git a/common/.config/nvim/init.lua b/common/.config/nvim/init.lua index 1b3c5b4..0f7cda9 100644 --- a/common/.config/nvim/init.lua +++ b/common/.config/nvim/init.lua @@ -9,13 +9,18 @@ -- TIP: Keymap structure: -- b: buffer -- g: git/github --- c: Coding things +-- c: Coding Stuff -- e: explorer --- f: list & find something +-- l: list & find something -- s: Grep/Search over something -- x: close/dismiss something --- r: restore sessions -- l: List some stuff +-- d: [D]iagnostics +-- t: Test runner stuff + +-- TODO: +-- Reduce noice timeout +-- WhichKey add hints -- Load keymaps & options require("config") @@ -43,6 +48,9 @@ require("lazy").setup({ change_detection = { notify = false, }, + build = { + warn_on_override = true, + }, performance = { rtp = { -- Disable some rtp plugins diff --git a/common/.config/nvim/lua/config/autocmd.lua b/common/.config/nvim/lua/config/autocmd.lua new file mode 100644 index 0000000..e21e3f3 --- /dev/null +++ b/common/.config/nvim/lua/config/autocmd.lua @@ -0,0 +1,20 @@ +-- Auto reload existing session +vim.api.nvim_create_autocmd("VimEnter", { + group = vim.api.nvim_create_augroup("restore_session", { clear = true }), + callback = function() + -- If nvim started with arguments, do NOT restore + if vim.fn.argc() ~= 0 then return end + require("persistence").load() + end, + nested = true, +}) + +-- Enable spell check on markdown and text files +vim.api.nvim_create_autocmd("FileType", { + group = vim.api.nvim_create_augroup("spell_check_text_files", { clear = true }), + pattern = { "markdown", "gitcommit", "text" }, + callback = function() + vim.opt.spell = true + end, + nested = true, +}) diff --git a/common/.config/nvim/lua/config/init.lua b/common/.config/nvim/lua/config/init.lua index 919491d..96131a3 100644 --- a/common/.config/nvim/lua/config/init.lua +++ b/common/.config/nvim/lua/config/init.lua @@ -1,2 +1,3 @@ require("config.keymaps") require("config.options") +require("config.autocmd") diff --git a/common/.config/nvim/lua/config/keymaps.lua b/common/.config/nvim/lua/config/keymaps.lua index bc7b8d7..dda7d9c 100644 --- a/common/.config/nvim/lua/config/keymaps.lua +++ b/common/.config/nvim/lua/config/keymaps.lua @@ -4,7 +4,14 @@ if vim.loop.fs_stat(vim_mappings) then vim.cmd("source " .. vim_mappings) end +vim.keymap.set({ "n" }, "", function() + vim.cmd("source " .. vim.fn.expand(vim.fn.stdpath("config") .. "/init.lua")) +end, { desc = "Apply NVIM config changes" }) + +vim.keymap.set({ "n", "v" }, "y", '"+y', { desc = "Copy to system clipboard" }) +vim.keymap.set({ "n", "v" }, "p", '"+p', { desc = "Paste from system clipboard" }) vim.keymap.set({ "n" }, "", " %y+ ", { desc = "Copy entire content of the current buffer" }) + vim.keymap.set("n", "fn", "enew", { desc = "Create new file/buffer" }) -- Remap for dealing with word wrap @@ -29,6 +36,12 @@ vim.keymap.set("n", "", "m .-2==", { desc = "Move line up" }) vim.keymap.set("v", "", ":m '>+1gv=gv", { desc = "Move line down" }) vim.keymap.set("v", "", ":m '<-2gv=gv", { desc = "Move line up" }) +vim.keymap.set("i", "", "u", { desc = "Add undo breakpoint and delete last word" }) +vim.keymap.set("i", ",", ",u", { desc = "Auto add undo breakpoints on ','" }) +vim.keymap.set("i", ".", ".u", { desc = "Auto add undo breakpoints on '.'" }) +vim.keymap.set("i", ";", ";u", { desc = "Auto add undo breakpoints on ';'" }) +vim.keymap.set("i", "\r", "\ru", { desc = "Auto add undo breakpoints on new lines" }) + -- Traverse Buffer vim.keymap.set("n", "", "bnext", { desc = "Switch to next buffer" }) vim.keymap.set("n", "", "bprevious", { desc = "Switch to previous buffer" }) @@ -38,7 +51,7 @@ vim.keymap.set({ "i", "x", "n", "s" }, "", "w", { desc = "Sav vim.keymap.set({ "i", "x", "n", "s" }, "", "wqa", { desc = "Save all files and Quit Neovim" }) -- Close Current Buffer -vim.keymap.set({ "n", "v" }, "bx", function() +vim.keymap.set({ "n", "v" }, "xb", function() if vim.bo.modified then vim.cmd.write() end @@ -46,17 +59,32 @@ vim.keymap.set({ "n", "v" }, "bx", function() end, { desc = "Save and close current buffer" }) -- Traverse quickfix +-- TODO: Friendly message when no quickfix vim.keymap.set("n", "[q", vim.cmd.cprev, { desc = "Previous quickfix" }) vim.keymap.set("n", "]q", vim.cmd.cnext, { desc = "Next quickfix" }) -- Clear searches vim.keymap.set({ "i", "n" }, "", "noh", { desc = "Escape and clear hlsearch" }) -vim.keymap.set("n", "/", "nohlsearchdiffupdatenormal! ", - { desc = "Redraw / clear hlsearch / diff update" }) +vim.keymap.set("n", "/", "nohlsearchdiffupdatenormal! ", { desc = "Redraw / clear hlsearch / diff update" }) +-- https://github.com/mhinz/vim-galore#saner-behavior-of-n-and-n vim.keymap.set("n", "n", "'Nn'[v:searchforward].'zv'", { expr = true, desc = "Next search result" }) -vim.keymap.set("x", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) -vim.keymap.set("o", "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) +vim.keymap.set({ "x", "o" }, "n", "'Nn'[v:searchforward]", { expr = true, desc = "Next search result" }) vim.keymap.set("n", "N", "'nN'[v:searchforward].'zv'", { expr = true, desc = "Prev search result" }) -vim.keymap.set("x", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) -vim.keymap.set("o", "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) +vim.keymap.set({ "x", "o" }, "N", "'nN'[v:searchforward]", { expr = true, desc = "Prev search result" }) + +-- diagnostic: From LazyVim +local diagnostic_goto = function(next, severity) + local go = next and vim.diagnostic.goto_next or vim.diagnostic.goto_prev + severity = severity and vim.diagnostic.severity[severity] or nil + return function() + go({ severity = severity }) + end +end +vim.keymap.set("n", "cd", vim.diagnostic.open_float, { desc = "Line Diagnostics" }) +vim.keymap.set("n", "]d", diagnostic_goto(true), { desc = "Next Diagnostic" }) +vim.keymap.set("n", "[d", diagnostic_goto(false), { desc = "Prev Diagnostic" }) +vim.keymap.set("n", "]e", diagnostic_goto(true, "ERROR"), { desc = "Next Error" }) +vim.keymap.set("n", "[e", diagnostic_goto(false, "ERROR"), { desc = "Prev Error" }) +vim.keymap.set("n", "]w", diagnostic_goto(true, "WARN"), { desc = "Next Warning" }) +vim.keymap.set("n", "[w", diagnostic_goto(false, "WARN"), { desc = "Prev Warning" }) diff --git a/common/.config/nvim/lua/config/util.lua b/common/.config/nvim/lua/config/util.lua new file mode 100644 index 0000000..dfe96dc --- /dev/null +++ b/common/.config/nvim/lua/config/util.lua @@ -0,0 +1,121 @@ +-- Required mostly be lualine plugin +-- Copied from Lazyvim +local M = { + icons = { + misc = { + dots = "󰇘", + }, + dap = { + Stopped = { "󰁕 ", "DiagnosticWarn", "DapStoppedLine" }, + Breakpoint = " ", + BreakpointCondition = " ", + BreakpointRejected = { " ", "DiagnosticError" }, + LogPoint = ".>", + }, + diagnostics = { Error = " ", Warn = " ", Hint = " ", Info = " " }, + git = { added = " ", modified = " ", removed = " " }, + kinds = { + Array = " ", + Boolean = "󰨙 ", + Class = " ", + Codeium = "󰘦 ", + Color = " ", + Control = " ", + Collapsed = " ", + Constant = "󰏿 ", + Constructor = " ", + Copilot = " ", + Enum = " ", + EnumMember = " ", + Event = " ", + Field = " ", + File = "󰈙 ", + Folder = " ", + Function = "󰊕 ", + Interface = " ", + Key = "󰌋 ", + Keyword = " ", + Method = "󰊕 ", + Module = " ", + Namespace = "󰦮 ", + Null = "󰟢 ", + Number = "󰎠 ", + Object = " ", + Operator = " ", + Package = " ", + Property = " ", + Reference = " ", + Snippet = " ", + String = " ", + Struct = "󰆼 ", + TabNine = "󰏚 ", + Text = " ", + TypeParameter = " ", + Unit = " ", + Value = " ", + Variable = "󰀫 ", + }, + }, +} + +function M.fg(name) + ---@type {foreground?:number}? + ---@diagnostic disable-next-line: deprecated + local hl = vim.api.nvim_get_hl and vim.api.nvim_get_hl(0, { name = name }) or vim.api.nvim_get_hl_by_name(name, true) + ---@diagnostic disable-next-line: undefined-field + local fg = hl and (hl.fg or hl.foreground) + return fg and { fg = string.format("#%06x", fg) } or nil +end + +---@param opts? lsp.Client.filter +function M.get_clients(opts) + local ret = {} ---@type lsp.Client[] + if vim.lsp.get_clients then + ret = vim.lsp.get_clients(opts) + else + ---@diagnostic disable-next-line: deprecated + ret = vim.lsp.get_active_clients(opts) + if opts and opts.method then + ---@param client lsp.Client + ret = vim.tbl_filter(function(client) + return client.supports_method(opts.method, { bufnr = opts.bufnr }) + end, ret) + end + end + return opts and opts.filter and vim.tbl_filter(opts.filter, ret) or ret +end + +---@param from string +---@param to string +function M.on_rename(from, to) + local clients = M.get_clients() + for _, client in ipairs(clients) do + if client.supports_method("workspace/willRenameFiles") then + ---@diagnostic disable-next-line: invisible + local resp = client.request_sync("workspace/willRenameFiles", { + files = { + { + oldUri = vim.uri_from_fname(from), + newUri = vim.uri_from_fname(to), + }, + }, + }, 1000, 0) + if resp and resp.result ~= nil then + vim.lsp.util.apply_workspace_edit(resp.result, client.offset_encoding) + end + end + end +end + +---@param on_attach fun(client, buffer) +function M.on_lsp_attach(on_attach) + vim.api.nvim_create_autocmd("LspAttach", { + callback = function(args) + local buffer = args.buf ---@type number + local client = vim.lsp.get_client_by_id(args.data.client_id) + on_attach(client, buffer) + end, + }) +end + +return M diff --git a/common/.config/nvim/lua/plugins/coding-cmp.lua b/common/.config/nvim/lua/plugins/coding-cmp.lua index eecef14..19836e0 100644 --- a/common/.config/nvim/lua/plugins/coding-cmp.lua +++ b/common/.config/nvim/lua/plugins/coding-cmp.lua @@ -1,4 +1,7 @@ return { + + -- TODO: Figureout how to add custom snippets + { -- Autocompletion "hrsh7th/nvim-cmp", @@ -10,17 +13,17 @@ return { -- Adds LSP completion capabilities "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-path", + "hrsh7th/cmp-buffer", -- Adds a number of user-friendly snippets "rafamadriz/friendly-snippets", - - -- Autocompletion for commands - "hrsh7th/cmp-cmdline", }, config = function() -- [[ Configure nvim-cmp ]] -- See `:help cmp` + -- vim.api.nvim_set_hl(0, "CmpGhostText", { link = "Comment", default = true }) local cmp = require("cmp") + local defaults = require("cmp.config.default")() local luasnip = require("luasnip") require("luasnip.loaders.from_vscode").lazy_load() luasnip.config.setup({}) @@ -37,58 +40,64 @@ return { mapping = cmp.mapping.preset.insert({ [""] = cmp.mapping.select_next_item(), [""] = cmp.mapping.select_prev_item(), - [""] = cmp.mapping.scroll_docs(-4), - [""] = cmp.mapping.scroll_docs(4), + + [""] = cmp.mapping.scroll_docs(-4), + [""] = cmp.mapping.scroll_docs(4), + [""] = cmp.mapping.complete({}), + [""] = cmp.mapping.abort(), + + -- Enter to perform the completion [""] = cmp.mapping.confirm({ + select = true, + }), + [""] = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = true, }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_next_item() - elseif luasnip.expand_or_locally_jumpable() then - luasnip.expand_or_jump() - else - fallback() - end - end, { "i", "s" }), - [""] = cmp.mapping(function(fallback) - if cmp.visible() then - cmp.select_prev_item() - elseif luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - else - fallback() - end - end, { "i", "s" }), }), sources = { { name = "nvim_lsp" }, { name = "luasnip" }, { name = "path" }, + { { name = "buffer" } }, }, + -- experimental = { + -- ghost_text = { + -- hl_group = "CmpGhostText", + -- }, + -- }, + sorting = defaults.sorting, }) + end, + }, - cmp.setup.cmdline("/", { - mapping = cmp.mapping.preset.cmdline(), - sources = { - { name = "buffer" }, - } - }) - cmp.setup.cmdline(":", { - mapping = cmp.mapping.preset.cmdline(), - sources = cmp.config.sources({ - { name = "path" }, - }, { - { - name = "cmdline", - option = { - ignore_cmds = { "Man", "!" } - } - } - }) - }) - end + { + "L4MON4D3/LuaSnip", + keys = { + { + "", + function() + return require("luasnip").jumpable(1) and "luasnip-jump-next" or "" + end, + expr = true, + silent = true, + mode = "i", + }, + { + "", + function() + require("luasnip").jump(1) + end, + mode = "s", + }, + { + "", + function() + require("luasnip").jump(-1) + end, + mode = { "i", "s" }, + }, + }, }, } diff --git a/common/.config/nvim/lua/plugins/coding-debug.lua b/common/.config/nvim/lua/plugins/coding-debug.lua index a1d8a27..54d671a 100644 --- a/common/.config/nvim/lua/plugins/coding-debug.lua +++ b/common/.config/nvim/lua/plugins/coding-debug.lua @@ -1,10 +1,5 @@ --- debug.lua --- --- Shows how to use the DAP plugin to debug your code. --- -- Primarily focused on configuring the debugger for Go, but can --- be extended to other languages as well. That's why it's called --- kickstart.nvim and not kitchen-sink.nvim ;) +-- be extended to other languages as well. return { "mfussenegger/nvim-dap", @@ -24,23 +19,20 @@ return { local dapui = require("dapui") require("mason-nvim-dap").setup({ - -- Makes a best effort to setup the various debuggers with - -- reasonable debug configurations + -- Makes a best effort to setup the various debuggers with reasonable debug configurations automatic_setup = true, - -- You can provide additional configuration to the handlers, -- see mason-nvim-dap README for more information handlers = {}, - -- You'll need to check that you have the required things installed - -- online, please don't ask me how to install them :) + -- You'll need to check that you have the required things installed online ensure_installed = { -- Update this to ensure that you have the debuggers for the langs you want - "delve", + -- "delve", + -- TODO: Rust, C#, TS/JS, Python }, }) - -- Basic debugging keymaps, feel free to change to your liking! vim.keymap.set("n", "", dap.continue, { desc = "Debug: Start/Continue" }) vim.keymap.set("n", "", dap.step_into, { desc = "Debug: Step Into" }) vim.keymap.set("n", "", dap.step_over, { desc = "Debug: Step Over" }) @@ -50,12 +42,9 @@ return { dap.set_breakpoint(vim.fn.input("Breakpoint condition: ")) end, { desc = "Debug: Set Breakpoint" }) - -- Dap UI setup -- For more information, see |:help nvim-dap-ui| dapui.setup({ -- Set icons to characters that are more likely to work in every terminal. - -- Feel free to remove or use ones that you like more! :) - -- Don't feel like these are good choices. icons = { expanded = "▾", collapsed = "▸", current_frame = "*" }, controls = { icons = { @@ -80,6 +69,7 @@ return { dap.listeners.before.event_exited["dapui_config"] = dapui.close -- Install golang specific config - require("dap-go").setup() + -- require("dap-go").setup() + -- TODO: Rust, C#, TS/JS, Python end, } diff --git a/common/.config/nvim/lua/plugins/coding-formatting.lua b/common/.config/nvim/lua/plugins/coding-formatting.lua index d6460cb..28c2c5f 100644 --- a/common/.config/nvim/lua/plugins/coding-formatting.lua +++ b/common/.config/nvim/lua/plugins/coding-formatting.lua @@ -1,70 +1,51 @@ --- autoformat.lua return { - "neovim/nvim-lspconfig", - config = function() - -- Switch for controlling whether you want autoformatting. - -- Use :KickstartFormatToggle to toggle autoformatting on or off - local format_is_enabled = true - vim.api.nvim_create_user_command("KickstartFormatToggle", function() - format_is_enabled = not format_is_enabled - print("Setting autoformatting to: " .. tostring(format_is_enabled)) - end, {}) + { + "stevearc/conform.nvim", + lazy = true, + event = { "BufReadPre", "BufNewFile" }, + config = function() + local conform = require("conform") - -- Create an augroup that is used for managing our formatting autocmds. - -- We need one augroup per client to make sure that multiple clients - -- can attach to the same buffer without interfering with each other. - local _augroups = {} - local get_augroup = function(client) - if not _augroups[client.id] then - local group_name = "kickstart-lsp-format-" .. client.name - local id = vim.api.nvim_create_augroup(group_name, { clear = true }) - _augroups[client.id] = id - end + conform.setup({ + formatters_by_ft = { + javascript = { { "prettierd", "prettier" } }, + typescript = { { "prettierd", "prettier" } }, + javascriptreact = { { "prettierd", "prettier" } }, + typescriptreact = { { "prettierd", "prettier" } }, + svelte = { { "prettierd", "prettier" } }, + css = { { "prettierd", "prettier" } }, + html = { { "prettierd", "prettier" } }, + json = { { "prettierd", "prettier" } }, + yaml = { { "prettierd", "prettier" } }, + markdown = { { "prettierd", "prettier" } }, + graphql = { { "prettierd", "prettier" } }, + lua = { "stylua" }, + python = { "black" }, + sh = { "shfmt", "shellharden" }, + bash = { "shfmt", "shellharden" }, + zsh = { "shfmt", "shellharden" }, + ["*"] = { "codespell" }, + ["_"] = { "trim_whitespace" }, + }, + format_on_save = { + lsp_fallback = true, + async = false, + timeout_ms = 1000, + }, + formatters = { + shfmt = { + prepend_args = { "-i", "4" }, + }, + }, + }) - return _augroups[client.id] - end - - -- Whenever an LSP attaches to a buffer, we will run this function. - -- - -- See `:help LspAttach` for more information about this autocmd event. - vim.api.nvim_create_autocmd("LspAttach", { - group = vim.api.nvim_create_augroup("kickstart-lsp-attach-format", { clear = true }), - -- This is where we attach the autoformatting for reasonable clients - callback = function(args) - local client_id = args.data.client_id - local client = vim.lsp.get_client_by_id(client_id) - local bufnr = args.buf - - -- Only attach to clients that support document formatting - if not client.server_capabilities.documentFormattingProvider then - return - end - - -- Tsserver usually works poorly. Sorry you work with bad languages - -- You can remove this line if you know what you're doing :) - if client.name == "tsserver" then - return - end - - -- Create an autocmd that will run *before* we save the buffer. - -- Run the formatting command for the LSP that has just attached. - vim.api.nvim_create_autocmd("BufWritePre", { - group = get_augroup(client), - buffer = bufnr, - callback = function() - if not format_is_enabled then - return - end - - vim.lsp.buf.format({ - async = false, - filter = function(c) - return c.id == client.id - end, - }) - end, + vim.keymap.set({ "n", "v" }, "cf", function() + conform.format({ + lsp_fallback = true, + async = false, + timeout_ms = 1000, }) - end, - }) - end, + end, { desc = "[C]ode [F]ormat (visual selection)" }) + end, + }, } diff --git a/common/.config/nvim/lua/plugins/coding-generic.lua b/common/.config/nvim/lua/plugins/coding-generic.lua index c30ae72..01b90e3 100644 --- a/common/.config/nvim/lua/plugins/coding-generic.lua +++ b/common/.config/nvim/lua/plugins/coding-generic.lua @@ -5,7 +5,16 @@ return { { "machakann/vim-highlightedyank" }, -- "gc" to comment visual regions/lines - { "numToStr/Comment.nvim", opts = {} }, + { + "numToStr/Comment.nvim", + config = function() + require("Comment").setup({ + pre_hook = function() + return vim.bo.commentstring + end, + }) + end, + }, -- auto pairs { @@ -18,13 +27,21 @@ return { { "lukas-reineke/indent-blankline.nvim", opts = { - indent = { char = "│", tab_char = "│", }, + indent = { char = "│", tab_char = "│" }, scope = { enabled = false }, exclude = { filetypes = { - "help", "alpha", "dashboard", "neo-tree", - "Trouble", "trouble", "lazy", "mason", - "notify", "toggleterm", "lazyterm", + "help", + "alpha", + "dashboard", + "neo-tree", + "Trouble", + "trouble", + "lazy", + "mason", + "notify", + "toggleterm", + "lazyterm", }, }, }, @@ -34,13 +51,18 @@ return { -- Highlights the current level of indentation, and animates the highlighting. { "echasnovski/mini.indentscope", - opts = { symbol = "│", options = { try_as_border = true }, }, + opts = { symbol = "│", options = { try_as_border = true } }, init = function() vim.api.nvim_create_autocmd("FileType", { pattern = { - "help", "neo-tree", "Trouble", "trouble", - "lazy", "mason", "notify", "toggleterm", - "lazyterm", + "help", + "neo-tree", + "Trouble", + "trouble", + "lazy", + "mason", + "notify", + "toggleterm", }, callback = function() vim.b.miniindentscope_disable = true @@ -61,14 +83,134 @@ return { }, }, keys = { - { "]t", function() require("todo-comments").jump_next() end, desc = "Next todo comment" }, - { "[t", function() require("todo-comments").jump_prev() end, desc = "Previous todo comment" }, + { + "]t", + function() + require("todo-comments").jump_next() + end, + desc = "Next todo comment", + }, + { + "[t", + function() + require("todo-comments").jump_prev() + end, + desc = "Previous todo comment", + }, - -- TODO: Find better keymaps for below - -- { "xt", "TodoTrouble", desc = "Todo (Trouble)" }, - -- { "xT", "TodoTrouble keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme (Trouble)" }, - -- { "st", "TodoTelescope", desc = "Todo" }, - -- { "sT", "TodoTelescope keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme" }, + { "dt", "TodoTrouble", desc = "Todo (Trouble)" }, + { "dT", "TodoTrouble keywords=TODO,FIX,FIXME", desc = "Todo/Fix/Fixme (Trouble)" }, + -- TODO: Include hidden files + { "lt", "TodoTelescope", desc = "List Todo" }, + { "lT", "TodoTelescope keywords=TODO,FIX,FIXME", desc = "List Todo/Fix/Fixme" }, + }, + }, + + -- better diagnostics list and others + { + "folke/trouble.nvim", + cmd = { "TroubleToggle", "Trouble" }, + opts = { use_diagnostic_signs = true }, + keys = { + { "dx", "TroubleToggle document_diagnostics", desc = "Document Diagnostics (Trouble)" }, + { "dw", "TroubleToggle workspace_diagnostics", desc = "Workspace Diagnostics (Trouble)" }, + { "dl", "TroubleToggle loclist", desc = "Location List (Trouble)" }, + { "dq", "TroubleToggle quickfix", desc = "Quickfix List (Trouble)" }, + { + "[q", + function() + if require("trouble").is_open() then + require("trouble").previous({ skip_groups = true, jump = true }) + else + local ok, err = pcall(vim.cmd.cprev) + if not ok then + vim.notify(err, vim.log.levels.ERROR) + end + end + end, + desc = "Previous trouble/quickfix item", + }, + { + "]q", + function() + if require("trouble").is_open() then + require("trouble").next({ skip_groups = true, jump = true }) + else + local ok, err = pcall(vim.cmd.cnext) + if not ok then + vim.notify(err, vim.log.levels.ERROR) + end + end + end, + desc = "Next trouble/quickfix item", + }, + }, + }, + + -- Inlay hints + { + "lvimuser/lsp-inlayhints.nvim", + config = function() + require("lsp-inlayhints").setup() + + -- Lazy load on LspAttach + vim.api.nvim_create_augroup("LspAttach_inlayhints", {}) + vim.api.nvim_create_autocmd("LspAttach", { + group = "LspAttach_inlayhints", + callback = function(args) + if not (args.data and args.data.client_id) then + return + end + + local bufnr = args.buf + local client = vim.lsp.get_client_by_id(args.data.client_id) + require("lsp-inlayhints").on_attach(client, bufnr) + end, + }) + end, + }, + + -- Lsp Breadcrumbs for lualine + { + "SmiteshP/nvim-navic", + lazy = true, + init = function() + vim.g.navic_silence = true + require("config.util").on_lsp_attach(function(client, buffer) + if client.supports_method("textDocument/documentSymbol") then + require("nvim-navic").attach(client, buffer) + end + end) + end, + opts = function() + return { + separator = " ", + highlight = true, + depth_limit = 5, + icons = require("config.util").icons.kinds, + lazy_update_context = true, + } + end, + }, + + { + "SmiteshP/nvim-navbuddy", + dependencies = { + "SmiteshP/nvim-navic", + "MunifTanjim/nui.nvim", + }, + opts = { + lsp = { auto_attach = true }, + icons = require("config.util").icons.kinds, + }, + keys = { + { + "v", + function() + return require("nvim-navbuddy").open() + end, + desc = "N[v]igate through document symbols", + }, }, }, } diff --git a/common/.config/nvim/lua/plugins/coding-git.lua b/common/.config/nvim/lua/plugins/coding-git.lua index 7ddb978..43a120b 100644 --- a/common/.config/nvim/lua/plugins/coding-git.lua +++ b/common/.config/nvim/lua/plugins/coding-git.lua @@ -1,6 +1,6 @@ return { - { "tpope/vim-fugitive", }, + { "tpope/vim-fugitive" }, --{ "tpope/vim-rhubarb" }, --If fugitive.vim is the Git, rhubarb.vim is the Hub. { @@ -14,6 +14,7 @@ return { delete = { text = "_" }, topdelete = { text = "‾" }, changedelete = { text = "~" }, + untracked = { text = "▎" }, }, on_attach = function(bufnr) local gs = package.loaded.gitsigns @@ -52,6 +53,7 @@ return { end, { desc = "reset git hunk" }) -- normal mode map("n", "ghp", gs.preview_hunk, { desc = "preview git hunk" }) + map("n", "gp", gs.preview_hunk, { desc = "preview git hunk" }) map("n", "ghr", gs.reset_hunk, { desc = "git reset hunk" }) map("n", "ghb", function() diff --git a/common/.config/nvim/lua/plugins/coding-lint.lua b/common/.config/nvim/lua/plugins/coding-lint.lua new file mode 100644 index 0000000..7e68e99 --- /dev/null +++ b/common/.config/nvim/lua/plugins/coding-lint.lua @@ -0,0 +1,61 @@ +return { + { + "mfussenegger/nvim-lint", + lazy = true, + event = { "BufReadPre", "BufNewFile" }, + config = function() + local lint = require("lint") + + -- Linters are only required for dynamically typed languages + lint.linters_by_ft = { + -- javascript = { "eslint_d" }, + -- typescript = { "eslint_d" }, + -- javascriptreact = { "eslint_d" }, + -- typescriptreact = { "eslint_d" }, + svelte = { "eslint_d" }, + python = { "pylint" }, + ["*"] = { "codespell" }, + } + + -- Uncomment and use the below section in `package.json` to enable eslint_d + -- "eslintConfig": { + -- "root": true, + -- "extends": [ + -- "eslint:recommended", + -- "plugin:@typescript-eslint/recommended" + -- ], + -- "parser": "@typescript-eslint/parser", + -- "parserOptions": { + -- "project": [ + -- "./tsconfig.json" + -- ] + -- }, + -- "plugins": [ + -- "@typescript-eslint" + -- ], + -- "rules": { + -- "@typescript-eslint/strict-boolean-expressions": [ + -- 2, + -- { + -- "allowString": false, + -- "allowNumber": false + -- } + -- ] + -- }, + -- "ignorePatterns": [ + -- "src/**/*.test.ts", + -- "src/frontend/generated/*" + -- ] + -- } + + local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) + + vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, { + group = lint_augroup, + callback = function() + lint.try_lint() + end, + }) + end, + }, +} diff --git a/common/.config/nvim/lua/plugins/coding-lsp.lua b/common/.config/nvim/lua/plugins/coding-lsp.lua index b0cdf0c..c315e94 100644 --- a/common/.config/nvim/lua/plugins/coding-lsp.lua +++ b/common/.config/nvim/lua/plugins/coding-lsp.lua @@ -10,25 +10,15 @@ local on_attach = function(_, bufnr) vim.keymap.set("n", keys, func, { buffer = bufnr, desc = desc }) end - nmap("rn", vim.lsp.buf.rename, "[R]e[n]ame") + nmap("cr", vim.lsp.buf.rename, "[R]e[n]ame") nmap("ca", vim.lsp.buf.code_action, "[C]ode [A]ction") - - nmap("gd", require("telescope.builtin").lsp_definitions, "[G]oto [D]efinition") - nmap("gr", require("telescope.builtin").lsp_references, "[G]oto [R]eferences") - nmap("gI", require("telescope.builtin").lsp_implementations, "[G]oto [I]mplementation") - nmap("D", require("telescope.builtin").lsp_type_definitions, "Type [D]efinition") - nmap("ds", require("telescope.builtin").lsp_document_symbols, "[D]ocument [S]ymbols") - nmap("ws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") - -- See `:help K` for why this keymap nmap("K", vim.lsp.buf.hover, "Hover Documentation") - nmap("", vim.lsp.buf.signature_help, "Signature Documentation") + -- nmap("", vim.lsp.buf.signature_help, "Signature Documentation") -- Lesser used LSP functionality - nmap("gD", vim.lsp.buf.declaration, "[G]oto [D]eclaration") - nmap("wa", vim.lsp.buf.add_workspace_folder, "[W]orkspace [A]dd Folder") - nmap("wr", vim.lsp.buf.remove_workspace_folder, "[W]orkspace [R]emove Folder") - nmap("wl", function() + nmap("cws", require("telescope.builtin").lsp_dynamic_workspace_symbols, "[W]orkspace [S]ymbols") + nmap("cwl", function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end, "[W]orkspace [L]ist Folders") @@ -44,62 +34,92 @@ return { "neovim/nvim-lspconfig", dependencies = { -- Automatically install LSPs to stdpath for neovim - { "williamboman/mason.nvim", config = true }, + { "williamboman/mason.nvim", config = true }, { "williamboman/mason-lspconfig.nvim" }, -- Useful status updates for LSP - { "j-hui/fidget.nvim", opts = {} }, + { "j-hui/fidget.nvim", opts = {} }, { "folke/neodev.nvim" }, }, - -- WARN: DO NOT do config here - -- That would override config from autoformat + -- WARN: DO NOT do `config` here it would override `config` from coding-formatting.lua + -- That's why we do the LSP config inside mason-lspconfig }, { "williamboman/mason-lspconfig.nvim", config = function() - -- NOTE: We configure lsp here instead of in the lspconfig's config - -- Reason? read the warnings above - -- Configure LSP -- mason-lspconfig requires that these setup functions are called in this order - -- before setting up the servers. + -- BEFORE setting up the servers. require("mason").setup() - require("mason-lspconfig").setup() + local mason_lspconfig = require("mason-lspconfig") + mason_lspconfig.setup() -- Enable the following language servers - -- Add any additional override configuration in the following tables. They will be passed to - -- the `settings` field of the server config. You must look up that documentation yourself. - -- - -- If you want to override the default filetypes that your language server will attach to you can - -- define the property 'filetypes' to the map in question. + -- Add any additional override configuration in the following tables. They will be passed to the `settings` field of the server config + -- If you want to override the default filetypes that your language server will attach to you can define the property 'filetypes' to the map in question. local servers = { -- clangd = {}, -- gopls = {}, - -- pyright = {}, - -- rust_analyzer = {}, - -- tsserver = {}, - -- html = { filetypes = { 'html', 'twig', 'hbs'} }, lua_ls = { Lua = { workspace = { checkThirdParty = false }, telemetry = { enable = false }, + -- hint = { enable = true }, -- NOTE: toggle below to ignore Lua_LS's noisy `missing-fields` warnings -- diagnostics = { disable = { 'missing-fields' } }, }, }, + + -- Markdown + marksman = {}, + + awk_ls = {}, + bashls = { + filetypes = { "sh", "bash", "zsh" }, + }, + cssls = {}, + dockerls = {}, + docker_compose_language_service = {}, + html = { filetypes = { 'html', 'twig', 'hbs' } }, + jsonls = {}, + pyright = {}, + rust_analyzer = {}, + tsserver = { + typescript = { + inlayHints = { + -- includeInlayParameterNameHints = 'all', + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + } + }, + javascript = { + inlayHints = { + -- includeInlayParameterNameHints = 'all', + includeInlayParameterNameHintsWhenArgumentMatchesName = false, + includeInlayFunctionParameterTypeHints = true, + includeInlayVariableTypeHints = true, + includeInlayVariableTypeHintsWhenTypeMatchesName = false, + includeInlayPropertyDeclarationTypeHints = true, + includeInlayFunctionLikeReturnTypeHints = true, + includeInlayEnumMemberValueHints = true, + } + } + }, } -- nvim-cmp supports additional completion capabilities, so broadcast that to servers local capabilities = vim.lsp.protocol.make_client_capabilities() capabilities = require("cmp_nvim_lsp").default_capabilities(capabilities) - -- Ensure the servers above are installed - local mason_lspconfig = require("mason-lspconfig") - mason_lspconfig.setup({ ensure_installed = vim.tbl_keys(servers), }) @@ -120,22 +140,19 @@ return { { "j-hui/fidget.nvim", opts = { - -- Options related to LSP progress subsystem progress = { - poll_rate = 1, -- How and when to poll for progress messages - suppress_on_insert = true, -- Suppress new messages while in insert mode - ignore_done_already = true, -- Ignore new tasks that are already complete + poll_rate = 1, -- How and when to poll for progress messages + suppress_on_insert = true, -- Suppress new messages while in insert mode + ignore_done_already = true, -- Ignore new tasks that are already complete ignore_empty_message = true, -- Ignore new tasks that don't contain a message - ignore = {}, -- List of LSP servers to ignore + ignore = {}, -- List of LSP servers to ignore - -- Options related to how LSP progress messages are displayed as notifications display = { - render_limit = 1, -- How many LSP messages to show at once + render_limit = 1, -- How many LSP messages to show at once skip_history = true, -- Whether progress notifications should be omitted from history }, }, - -- Options related to notification subsystem notification = { filter = vim.log.levels.WARN, -- Minimum notifications level }, diff --git a/common/.config/nvim/lua/plugins/coding-reactjs.lua b/common/.config/nvim/lua/plugins/coding-reactjs.lua new file mode 100644 index 0000000..23af575 --- /dev/null +++ b/common/.config/nvim/lua/plugins/coding-reactjs.lua @@ -0,0 +1,33 @@ +return { + -- Automatically add closing tags for HTML and JSX + { + "windwp/nvim-ts-autotag", + config = function() + require("nvim-ts-autotag").setup() + end, + }, + + -- Intelligent commenting on JSX + { + "JoosepAlviste/nvim-ts-context-commentstring", + opts = { + options = { + enable_autocmd = false, + }, + }, + config = function() + vim.g.skip_ts_context_commentstring_module = true + end, + }, + + -- Highlight colors + { + "brenoprata10/nvim-highlight-colors", + setup = { + enable_tailwind = true, + }, + config = function() + require("nvim-highlight-colors").setup() + end, + }, +} diff --git a/common/.config/nvim/lua/plugins/coding-test.lua b/common/.config/nvim/lua/plugins/coding-test.lua new file mode 100644 index 0000000..6772a0e --- /dev/null +++ b/common/.config/nvim/lua/plugins/coding-test.lua @@ -0,0 +1,120 @@ +return { + -- Test runner integration + -- Taken from LazyVim + { + "nvim-neotest/neotest", + dependencies = { + "nvim-lua/plenary.nvim", + "antoinemadec/FixCursorHold.nvim", + "nvim-treesitter/nvim-treesitter", + "marilari88/neotest-vitest" + }, + opts = { + -- Do NOT add adapters here + -- Add it to opts.adapters inside config function + adapters = {}, + status = { virtual_text = true }, + output = { open_on_run = true }, + quickfix = { + open = function() + if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then + require("trouble").open({ mode = "quickfix", focus = false }) + else + vim.cmd("copen") + end + end, + }, + }, + config = function(_, opts) + local neotest_ns = vim.api.nvim_create_namespace("neotest") + vim.diagnostic.config({ + virtual_text = { + format = function(diagnostic) + -- Replace newline and tab characters with space for more compact diagnostics + local message = diagnostic.message:gsub("\n", " "):gsub("\t", " "):gsub("%s+", " "):gsub("^%s+", + "") + return message + end, + }, + }, neotest_ns) + + -- WARN: Change the following code if we change lazy.nvim + if require("lazy.core.config").spec.plugins["trouble.nvim"] ~= nil then + opts.consumers = opts.consumers or {} + -- Refresh and auto close trouble after running tests + ---@type neotest.Consumer + opts.consumers.trouble = function(client) + client.listeners.results = function(adapter_id, results, partial) + if partial then + return + end + local tree = assert(client:get_position(nil, { adapter = adapter_id })) + + local failed = 0 + for pos_id, result in pairs(results) do + if result.status == "failed" and tree:get_key(pos_id) then + failed = failed + 1 + end + end + vim.schedule(function() + local trouble = require("trouble") + if trouble.is_open() then + trouble.refresh() + if failed == 0 then + trouble.close() + end + end + end) + return {} + end + end + end + + -- TIP: Add adapters here + table.insert(opts.adapters, require("neotest-vitest")) + + if opts.adapters then + local adapters = {} + for name, config in pairs(opts.adapters or {}) do + if type(name) == "number" then + if type(config) == "string" then + config = require(config) + end + adapters[#adapters + 1] = config + elseif config ~= false then + local adapter = require(name) + if type(config) == "table" and not vim.tbl_isempty(config) then + local meta = getmetatable(adapter) + if adapter.setup then + adapter.setup(config) + elseif meta and meta.__call then + adapter(config) + else + error("Adapter " .. name .. " does not support setup") + end + end + adapters[#adapters + 1] = adapter + end + end + opts.adapters = adapters + end + + require("neotest").setup(opts) + end, + -- stylua: ignore + keys = { + -- TIP: Shortcuts in test summary window: + -- r: Run the selected test + -- a: Attaches to the test result (output) + -- i: Jumps to the code of the test + { "tt", function() require("neotest").run.run(vim.fn.expand("%")) end, desc = "Test: Run File" }, + { "tT", function() require("neotest").run.run(vim.loop.cwd()) end, desc = "Test: Run All Test Files" }, + { "tr", function() require("neotest").run.run() end, desc = "Test: Run Nearest" }, + { "tl", function() require("neotest").run.run_last() end, desc = "Test: Run Last" }, + { "ts", function() require("neotest").summary.toggle() end, desc = "Test: Toggle Summary" }, + { "to", function() require("neotest").output.open({ enter = true, auto_close = true }) end, desc = "Test: Show Output" }, + { "tO", function() require("neotest").output_panel.toggle() end, desc = "Test: Toggle Output Panel" }, + { "tS", function() require("neotest").run.stop() end, desc = "Test: Stop" }, + }, + }, +} diff --git a/common/.config/nvim/lua/plugins/editor.lua b/common/.config/nvim/lua/plugins/editor.lua index 18bdecf..1317f83 100644 --- a/common/.config/nvim/lua/plugins/editor.lua +++ b/common/.config/nvim/lua/plugins/editor.lua @@ -20,16 +20,27 @@ return { function() require("neo-tree.command").execute({ source = "buffers", toggle = true }) end, - desc = "NeoTree: Open [B]uffer [E]xplorer", + desc = "NeoTree: Open [B]buffer [E]xplorer", }, }, + deactivate = function() + vim.cmd([[Neotree close]]) + end, + init = function() + if vim.fn.argc(-1) == 1 then + local stat = vim.loop.fs_stat(vim.fn.argv(0)) + if stat and stat.type == "directory" then + require("neo-tree") + end + end + end, opts = { enable_git_status = true, filesystem = { bind_to_cwd = true, follow_current_file = { enabled = true, -- Highlight the current buffer - leave_dirs_open = true, + leave_dirs_open = false, }, use_libuv_file_watcher = true, -- Sync file system changes filtered_items = { @@ -41,25 +52,65 @@ return { }, window = { position = "left", - width = 30, -- Saner window size + width = 30, -- Saner window size mappings = { - ["s"] = "open_split", -- Default vim keymap for horizontal split - ["v"] = "open_vsplit", -- Default vim keymap for vertical split + ["s"] = "open_split", -- horizontal split + ["v"] = "open_vsplit", -- vertical split + ["Y"] = function(state) + local node = state.tree:get_node() + local path = node:get_id() + vim.fn.setreg("+", path, "c") + end, }, }, default_component_configs = { indent = { indent_size = 2, -- Compact tree display + with_expanders = true, -- if nil and file nesting is enabled, will enable expanders + expander_collapsed = "", + expander_expanded = "", + expander_highlight = "NeoTreeExpander", }, }, sources = { "filesystem", "buffers", "git_status", "document_symbols" }, open_files_do_not_replace_types = { "terminal", "Trouble", "trouble", "qf", "Outline" }, }, + config = function(_, opts) + local config = require("config.util") + + local function on_move(data) + config.on_rename(data.source, data.destination) + end + + local events = require("neo-tree.events") + opts.event_handlers = opts.event_handlers or {} + vim.list_extend(opts.event_handlers, { + { event = events.FILE_MOVED, handler = on_move }, + { event = events.FILE_RENAMED, handler = on_move }, + }) + require("neo-tree").setup(opts) + vim.api.nvim_create_autocmd("TermClose", { + pattern = "*lazygit", + callback = function() + if package.loaded["neo-tree.sources.git_status"] then + require("neo-tree.sources.git_status").refresh() + end + end, + }) + end, }, -- Automatically highlights other instances of the word under cursor { "RRethy/vim-illuminate", + lazy = false, + opts = { + delay = 200, + large_file_cutoff = 2000, + large_file_override = { + providers = { "lsp" }, + }, + }, config = function(_, opts) -- Copied from LazyNvim require("illuminate").configure(opts) @@ -104,13 +155,17 @@ return { }, event = "VeryLazy", keys = { - { "bp", "BufferLineTogglePin", desc = "Toggle buffer-pin" }, + { "bp", "BufferLineTogglePin", desc = "Toggle buffer-pin" }, { "xo", "BufferLineCloseOthers", desc = "Delete other buffers" }, }, opts = { options = { - close_command = function(n) require("mini.bufremove").delete(n, false) end, - right_mouse_command = function(n) require("mini.bufremove").delete(n, false) end, + close_command = function(n) + require("mini.bufremove").delete(n, false) + end, + right_mouse_command = function(n) + require("mini.bufremove").delete(n, false) + end, diagnostics = "nvim_lsp", always_show_bufferline = false, offsets = { @@ -121,6 +176,9 @@ return { text_align = "left", }, }, + numbers = function(opts) + return string.format("%s", opts.raise(opts.id)) + end, }, }, config = function(_, opts) @@ -161,7 +219,7 @@ return { }, opts = { render = "wrapped-compact", -- Smaller popups - timeout = 3000, + timeout = 2500, max_height = function() return math.floor(vim.o.lines * 0.25) end, @@ -184,11 +242,17 @@ return { }, opts = { lsp = { + progress = { + throttle = 1000 / 100, + }, override = { ["vim.lsp.util.convert_input_to_markdown_lines"] = true, ["vim.lsp.util.stylize_markdown"] = true, ["cmp.entry.get_documentation"] = true, }, + hover = { + silent = true, + }, }, routes = { { @@ -214,11 +278,15 @@ return { { find = "yanked" }, { find = "fewer lines" }, { find = "more lines" }, - { find = "EasyMotion" }, -- This can be completely discarded + { find = "EasyMotion" }, { find = "Target key" }, { find = "search hit BOTTOM" }, { find = "lines to indent" }, { find = "lines indented" }, + { find = "lines changed" }, + { find = ">ed" }, + { find = "nx", "NoiceDismiss", desc = "Dismiss all [N]oice notifications" }, - -- TODO: Find better keymaps - -- { "", function() require("noice").redirect(vim.fn.getcmdline()) end, mode = "c", desc = "Redirect Cmdline" }, - -- { "snl", function() require("noice").cmd("last") end, desc = "Noice Last Message" }, - -- { "snh", function() require("noice").cmd("history") end, desc = "Noice History" }, - -- { "sna", function() require("noice").cmd("all") end, desc = "Noice All" }, - -- { "snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" }, - -- { "snd", function() require("noice").cmd("dismiss") end, desc = "Dismiss All" }, - -- { "", function() if not require("noice.lsp").scroll(4) then return "" end end, silent = true, expr = true, desc = "Scroll forward", mode = { "i", "n", "s" } }, - -- { "", function() if not require("noice.lsp").scroll(-4) then return "" end end, silent = true, expr = true, desc = "Scroll backward", mode = { "i", "n", "s" } }, }, }, @@ -249,16 +308,123 @@ return { { "nvim-lualine/lualine.nvim", -- See `:help lualine.txt` - opts = { - -- TODO: Need the following: - -- - Remove encoding & OS - -- - Add Breadcrumb - -- - Show command that was typed - options = { - icons_enabled = false, - component_separators = "|", - section_separators = "", - }, - }, + -- + init = function() + vim.g.lualine_laststatus = vim.o.laststatus + if vim.fn.argc(-1) > 0 then + -- set an empty statusline till lualine loads + vim.o.statusline = " " + else + -- hide the statusline on the starter page + vim.o.laststatus = 0 + end + end, + opts = function() + local lualine_require = require("lualine_require") + lualine_require.require = require + vim.o.laststatus = vim.g.lualine_laststatus + + local config = require("config.util") + + return { + options = { + theme = "auto", + icons_enabled = true, + globalstatus = true, + component_separators = "|", + section_separators = "", + }, + extensions = { "neo-tree", "lazy" }, + sections = { + lualine_a = { "mode" }, + lualine_b = { "branch" }, + + lualine_c = { + { + "diagnostics", + symbols = { + error = config.icons.diagnostics.Error, + warn = config.icons.diagnostics.Warn, + info = config.icons.diagnostics.Info, + hint = config.icons.diagnostics.Hint, + }, + }, + { "filetype", icon_only = true, separator = "", padding = { left = 1, right = 0 } }, + { + "filename", + file_status = true, + path = 1, + }, + -- Breadcrumbs from "nvim-navic" plugin + { + function() + return require("nvim-navic").get_location() + end, + cond = function() + return package.loaded["nvim-navic"] and require("nvim-navic").is_available() + end, + }, + }, + + lualine_x = { + { + function() + return require("noice").api.status.command.get() + end, + cond = function() + return package.loaded["noice"] and require("noice").api.status.command.has() + end, + color = config.fg("Statement"), + }, + { + function() + return require("noice").api.status.mode.get() + end, + cond = function() + return package.loaded["noice"] and require("noice").api.status.mode.has() + end, + color = config.fg("Constant"), + }, + { + function() + return " " .. require("dap").status() + end, + cond = function() + return package.loaded["dap"] and require("dap").status() ~= "" + end, + color = config.fg("Debug"), + }, + { + "diff", + symbols = { + added = config.icons.git.added, + modified = config.icons.git.modified, + removed = config.icons.git.removed, + }, + source = function() + local gitsigns = vim.b.gitsigns_status_dict + if gitsigns then + return { + added = gitsigns.added, + modified = gitsigns.changed, + removed = gitsigns.removed, + } + end + end, + }, + }, + + lualine_y = { + { "progress", separator = " ", padding = { left = 1, right = 0 } }, + { "location", padding = { left = 0, right = 1 } }, + }, + lualine_z = { + function() + return " " .. os.date("%R") + end, + }, + }, + } + end, }, } diff --git a/common/.config/nvim/lua/plugins/telescope.lua b/common/.config/nvim/lua/plugins/telescope.lua index c7ef3dd..bed5026 100644 --- a/common/.config/nvim/lua/plugins/telescope.lua +++ b/common/.config/nvim/lua/plugins/telescope.lua @@ -52,14 +52,10 @@ return { -- Load some required Telescope extensions pcall(require("telescope").load_extension, "fzf") - pcall(require("telescope").load_extension, "noice") - pcall(require("telescope").load_extension, "undo") -- Special Things: [T]elescope - vim.keymap.set("n", "tr", require("telescope.builtin").resume, - { desc = "[T]elescope [R]esume Last Search" }) - vim.keymap.set("n", "tc", require("telescope.builtin").colorscheme, - { desc = "List Colorschemes (with preview)" }) + vim.keymap.set("n", "nc", require("telescope.builtin").colorscheme, + { desc = "List [N]eovim [C]olorschemes (with preview)" }) -- Grep things -> [S]earch vim.keymap.set("n", "sb", function() @@ -83,8 +79,7 @@ return { { desc = "[L]ist & Search NeoVIM [H]elp" }) vim.keymap.set("n", "lk", require("telescope.builtin").keymaps, { desc = "[L]ist & Search NeoVIM [K]eymaps" }) - vim.keymap.set("n", "lm", require("telescope.builtin").marks, { desc = "[L]ist [M]arks" }) - vim.keymap.set("n", "ln", require("telescope.builtin").man_pages, + vim.keymap.set("n", "lm", require("telescope.builtin").man_pages, { desc = "[L]ist & Search System Ma[n] Pages" }) vim.keymap.set("n", "lq", require("telescope.builtin").quickfixhistory, { desc = "[L]ist [Q]uickfix History" }) @@ -106,14 +101,24 @@ return { require("telescope.builtin").lsp_implementations, { desc = "[C]ode: Goto [I]mplementation of the word under cursor" } ) - vim.keymap.set("n", "cr", require("telescope.builtin").lsp_references, + vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, { desc = "[C]ode: List [R]eferences for word under cursor" }) vim.keymap.set( "n", - "ct", + "cgt", require("telescope.builtin").lsp_type_definitions, { desc = "[C]ode: Goto definition of the [T]ype under cursor" } ) + vim.keymap.set("n", "gd", require("telescope.builtin").lsp_definitions, { desc = "[G]oto [D]efinition" }) + vim.keymap.set("n", "cgd", require("telescope.builtin").lsp_type_definitions, + { desc = "Type [D]efinition" }) + vim.keymap.set("n", "cR", require("telescope.builtin").lsp_references, + { desc = "[G]oto [R]eferences" }) + vim.keymap.set("n", "cI", require("telescope.builtin").lsp_implementations, + { desc = "[G]oto [I]mplementation" }) + vim.keymap.set("n", "cs", require("telescope.builtin").lsp_document_symbols, + { desc = "[D]ocument [S]ymbols" }) + -- vim.keymap.set("n", "cgD", vim.lsp.buf.declaration, { desc = "[G]oto [D]eclaration" }) end, }, } diff --git a/common/.config/nvim/lua/plugins/treesitter.lua b/common/.config/nvim/lua/plugins/treesitter.lua index 6153b96..8194c43 100644 --- a/common/.config/nvim/lua/plugins/treesitter.lua +++ b/common/.config/nvim/lua/plugins/treesitter.lua @@ -53,6 +53,7 @@ return { ensure_installed = { -- These 2 are required for cmdline "regex", + "markdown", "markdown_inline", }, @@ -117,8 +118,8 @@ return { floating_preview_opts = {}, peek_definition_code = { -- TIP: Press the shortcut 2 times to enter the floating window - ["df"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, - ["dF"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, + ["cd"] = { query = "@function.outer", desc = "Peek function definition on a popup" }, + ["cD"] = { query = "@class.outer", desc = "Peek class definition on a popup" }, }, }, }, diff --git a/common/.config/nvim/lua/plugins/utility-plugs.lua b/common/.config/nvim/lua/plugins/utility-plugs.lua index f0231bb..c3d83ad 100644 --- a/common/.config/nvim/lua/plugins/utility-plugs.lua +++ b/common/.config/nvim/lua/plugins/utility-plugs.lua @@ -2,13 +2,19 @@ return { -- Navigate between NVIM & Tmux splits seamlessly { "christoomey/vim-tmux-navigator" }, + -- Navigate between NVIM & kitty splits seamlessly + { + "knubie/vim-kitty-navigator", + build = "cp ./*.py ~/.config/kitty/", + }, + -- Open Kitty terminal scrollback as buffer { "mikesmithgh/kitty-scrollback.nvim", lazy = true, cmd = { "KittyScrollbackGenerateKittens", "KittyScrollbackCheckHealth" }, event = { "User KittyScrollbackLaunch" }, - version = "^3.0.0", + version = "^4.0.0", opts = { status_window = { icons = { nvim = "" }, @@ -26,13 +32,9 @@ return { require("which-key").register({ ["e"] = { name = "[E]xplorer", _ = "which_key_ignore" }, ["c"] = { name = "[C]ode", _ = "which_key_ignore" }, - ["d"] = { name = "[D]ocument", _ = "which_key_ignore" }, ["g"] = { name = "[G]it", _ = "which_key_ignore" }, - ["h"] = { name = "Git [H]unk", _ = "which_key_ignore" }, - ["r"] = { name = "[R]ename", _ = "which_key_ignore" }, ["s"] = { name = "[S]earch", _ = "which_key_ignore" }, ["t"] = { name = "[T]oggle", _ = "which_key_ignore" }, - ["w"] = { name = "[W]orkspace", _ = "which_key_ignore" }, }) -- register which-key VISUAL mode -- required for visual hs (hunk stage) to work @@ -43,20 +45,46 @@ return { end, }, - -- Session management. This saves your session in the background, - -- keeping track of open buffers, window arrangement, and more. - -- You can restore sessions when returning through the dashboard. + -- Session management. Saves your session in the background { - -- TODO: - -- 1. Find out where they are stored exactly. - -- 2. Add them to source control - -- 3. Need a startup dashboard with options for loading last session "folke/persistence.nvim", event = "BufReadPre", - opts = { options = vim.opt.sessionoptions:get() }, + opts = { + -- Session files stored at: ~/.config/nvim/sessions/ + dir = vim.fn.expand(vim.fn.stdpath("config") .. "/sessions/"), + options = vim.opt.sessionoptions:get() + -- NOTE: autocmd to autoload sessions at: ../config/autocmd.lua + }, keys = { - { "sr", function() require("persistence").load() end, desc = "[R]estore [S]ession" }, - { "sl", function() require("persistence").load({ last = true }) end, desc = "[R]estore [L]ast Session" }, + -- Since we are auto-restoring sessions, keymaps aren't required + -- { "sr", function() require("persistence").load() end, desc = "[R]estore [S]ession" }, + -- { "sl", function() require("persistence").load({ last = true }) end, desc = "[R]estore [L]ast Session" }, + }, + }, + + -- Speedup loading large files by disabling some plugins + { + "LunarVim/bigfile.nvim", + lazy = true, + opts = { + filesize = 2, --2MiB + pattern = "*", + features = { + "indent_blankline", + "lsp", + "syntax", + "treesitter", + }, + }, + }, + + -- Provides tldr on vertical split + -- `:Tldr [command]` + { + "wlemuel/vim-tldr", + lazy = true, + dependencies = { + "nvim-telescope/telescope.nvim" }, }, } diff --git a/common/.config/shell/aliases b/common/.config/shell/aliases deleted file mode 100644 index 10687b4..0000000 --- a/common/.config/shell/aliases +++ /dev/null @@ -1,100 +0,0 @@ -#!/bin/sh - -# Generic -alias bashreload="source ~/.bashrc" -alias zshreload="source ~/.zshrc" -alias free="free -ht" -alias type="type -a" -alias grep='grep --color=auto' -alias egrep='egrep --color=auto' -alias fgrep='fgrep --color=auto' -alias usersearch="awk -F: '{print \"UserName: \" \$1 \", UserID: \" \$3 \", Home Dir: \" \$6 \", Shell Used: \" \$7}' /etc/passwd | grep" -alias untar='tar -zxvf ' -alias wget="wget --hsts-file ${WGET_HSTS_FILE}" - -alias v="${EDITOR}" -alias snvim="${HOMEBREW_PREFIX}/bin/nvim" # Stable nvim - -url_encode(){ - python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.stdin.read()))" <<< "$1" -} - - -# History -alias histsearch="history | grep" -alias hs="histsearch" -alias hsi="histsearch" - - -# Directories and Directory listings -alias ~="cd ~" -alias ..="cd .." -alias ...='cd ../../../' # Go back 3 directory levels -alias cd_root='cd $(git rev-parse --show-toplevel 2>/dev/null || echo ".")' -alias cd_git_root=cd_root -alias cl=clear -alias lsc='ls --color=auto --hyperlink=auto' -alias ll='lsc -alhF' -alias la='lsc -Ah' -alias l='lsc -CF' -alias lsa="lsc -lAFhZ" -alias mkdir="mkdir -pv" -alias df="df -h" -mkcd () { - mkdir "$1" - cd "$1" || exit -} - -# Network -alias ping="ping -c 10" -alias ping8="ping 8.8.8.8" -alias ping1="ping 1.1.1.1" -alias p8="ping8" -alias p1="ping1" -alias pubip="curl https://ipinfo.io/ip; echo" -alias speedtest="speedtest-cli --secure" -geoip () { - curl -s https://ipinfo.io | sed '/readme\|loc\|postal\|{\|}\|hostname/d;s/org/ISP/;s/"\|,$//g' | awk -F ':' 'NF { printf("%10s: %s \n", $1, $2)}' -} - - -# Git -git_push_all_changes(){ - git add . && git commit -am "${1}" && git push -} -alias git_just_push=git_push_all_changes - - -alias ta="tmux a" -alias tat="tmux a -t" -alias tls="tmux ls" -alias tnew="tmux new" -alias tnewt="tmux new -t" - -# Nvim Distro-Switcher -alias nvim-lazy="NVIM_APPNAME=nvim-lazy nvim" -alias OldConfig="NVIM_APPNAME=oldconfig nvim" -nvims() { - items=$(find -L "$HOME"/.config -maxdepth 2 -name "init.lua" -type f -execdir sh -c 'pwd | xargs basename' \;) - config=$(printf "%s\n" "${items[@]}" | fzf --prompt=" Neovim Config  " --height=~50% --layout=reverse --border --exit-0) - if [ -z "$config" ]; then - echo "Nothing selected" - return 0 - elif [ "$config" = "default" ]; then - config="" - fi - NVIM_APPNAME=$config nvim "$@" -} - -op() { - local chosen_project - chosen_project="$(find -L ~/Code -mindepth 2 -maxdepth 2 -not -path '*/.*' -printf "%T@ %p\n" | sort -nr | cut -d ' ' -f 2- | fzf --border --layout=reverse --height=~50% --prompt='Select a project: ' --preview 'ls -Lltc {1}')" - if [ -z "$chosen_project" ]; then - return 0 - fi - - cd "$chosen_project" || return - nvim -} - -# TODO: Create fuzzy finder for cht.sh & tldr diff --git a/common/.config/shell/aliases.sh b/common/.config/shell/aliases.sh new file mode 100644 index 0000000..7c1fc91 --- /dev/null +++ b/common/.config/shell/aliases.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +# Generic +alias bashreload="source ~/.bashrc" +alias zshreload="source ~/.zshrc" +alias free="free -ht" +alias type="type -a" +alias grep='grep --color=auto' +alias egrep='egrep --color=auto' +alias fgrep='fgrep --color=auto' +alias usersearch="awk -F: '{print \"UserName: \" \$1 \", UserID: \" \$3 \", Home Dir: \" \$6 \", Shell Used: \" \$7}' /etc/passwd | grep" +alias untar='tar -zxvf ' +alias wget="wget --hsts-file ${WGET_HSTS_FILE}" + +alias v="${EDITOR}" +alias snvim="${HOMEBREW_PREFIX}/bin/nvim" # Stable nvim + +# Directories and Directory listings +alias ~="cd ~" +alias ..="cd .." +alias ...='cd ../../../' # Go back 3 directory levels +alias cl=clear + +alias lsc='ls --color=auto --hyperlink' +alias ll='lsc -alhF' +alias la='lsc -Ah' +alias lsa="lsc -lAFhZ" + +alias mkdir="mkdir -pv" +alias df="df -h" +mkcd () { + mkdir "$1" + cd "$1" || exit +} + +# Network +alias ping="ping -c 10" +alias ping8="ping 8.8.8.8" +alias ping1="ping 1.1.1.1" +alias p8="ping8" +alias p1="ping1" +alias pubip="curl https://ipinfo.io/ip; echo" +alias speedtest="speedtest-cli --secure" +geoip () { + curl -s https://ipinfo.io | sed '/readme\|loc\|postal\|{\|}\|hostname/d;s/org/ISP/;s/"\|,$//g' | awk -F ':' 'NF { printf("%10s: %s \n", $1, $2)}' +} + diff --git a/common/.config/shell/p10k.zsh b/common/.config/shell/p10k.zsh index 2c52d66..1bc012f 100644 --- a/common/.config/shell/p10k.zsh +++ b/common/.config/shell/p10k.zsh @@ -788,7 +788,7 @@ # # These variables correspond to the last line of the output of `todo.sh -p ls`: # - # TODO: 24 of 42 tasks shown + # todo: 24 of 42 tasks shown # # Here 24 is P9K_TODO_FILTERED_TASK_COUNT and 42 is P9K_TODO_TOTAL_TASK_COUNT. # diff --git a/common/.gitconfig b/common/.gitconfig index 75bebf9..3fc4f08 100644 --- a/common/.gitconfig +++ b/common/.gitconfig @@ -1,14 +1,37 @@ [user] email = mail@pratik.live name = Pratik Tripathy + [core] autocrlf = input - editor = code --wait + editor = nvim + excludesfile = ~/.gitignore + + # Make `git rebase` safer on macOS + # More info: + trustctime = false + [diff] tool = vscode + [difftool "vscode"] cmd = "code --wait --diff $LOCAL $REMOTE" + +[merge] + tool = vscode + conflictstyle = diff3 + +[mergetool] + prompt = true + keepBackup = false + +[mergetool "vscode"] + cmd = code --wait $MERGED + +[log] + date = relative + [alias] ll = log --pretty=format:'%Cblue%cn (%ce)%Creset commited %Cred%h%Creset %Cgreen%cr%Creset:%n%B' unstage = restore --staged . - + cleanup = "!git remote prune origin && git gc && git clean -df && git stash clear" diff --git a/common/.gitignore b/common/.gitignore index b6b8a77..855920c 100644 --- a/common/.gitignore +++ b/common/.gitignore @@ -97,6 +97,3 @@ lerna-debug.log* **/contents/images **/contents/fonts *kpluginindex.json - -*.bak -nvim_switch/ diff --git a/common/.profile b/common/.profile index 22a5db0..40ce4ff 100644 --- a/common/.profile +++ b/common/.profile @@ -34,12 +34,6 @@ export VISUAL=$EDITOR # Manually follow steps from https://steamcommunity.com/app/646570/discussions/1/3935537639868400686 # To disable ~/.oracle_jre_usage/ from being created -# Source aliases -[ ! -f "$XDG_CONFIG_HOME/shell/aliases" ] || source "$XDG_CONFIG_HOME/shell/aliases" -[ ! -f "$XDG_CONFIG_HOME/shell/aliases_mac" ] || source "$XDG_CONFIG_HOME/shell/aliases_mac" -[ ! -f "$XDG_CONFIG_HOME/shell/aliases_neon" ] || source "$XDG_CONFIG_HOME/shell/aliases_neon" -[ ! -f "$XDG_CONFIG_HOME/shell/aliases_personal" ] || source "$XDG_CONFIG_HOME/shell/aliases_personal" - if [ "$(uname -s)" = "Linux" ]; then export __GL_SHADER_DISK_CACHE_PATH="$XDG_CACHE_HOME/nvidia" diff --git a/common/.vim/autocommands.vim b/common/.vim/autocommands.vim new file mode 100644 index 0000000..695c1e2 --- /dev/null +++ b/common/.vim/autocommands.vim @@ -0,0 +1,7 @@ +" Enable spell check for markdown, gitcommit & text files +augroup spell_check_text_files + autocmd! + autocmd FileType markdown setlocal spell + autocmd FileType gitcommit setlocal spell + autocmd FileType text setlocal spell +augroup END diff --git a/common/.vim/configs.vim b/common/.vim/configs.vim index ae760dc..e3a3414 100644 --- a/common/.vim/configs.vim +++ b/common/.vim/configs.vim @@ -23,7 +23,7 @@ set viewoptions-=options set nolangremap " Do not use non-English keyboards to define keymaps set list " Show tabs as >, trailing spaces as -, non-breakable space as + set signcolumn=yes " Always show the signs column (before line number column) -set scrolloff=5 " Cursor always at middle of the screen +set scrolloff=10 " Cursor always at middle of the screen set updatetime=249 " No typing for this millisec -> write to swap file set timeoutlen=500 " Multiple keys in keymaps must be pressed in these millisecs set noswapfile " Turn off swapfiles @@ -64,11 +64,7 @@ autocmd BufWritePre * %s/\s\+$//e set backspace=indent,eol,start " Sync vim clipboard with system clipboard. Works across Linux, MacOS & Windows. -if has("mac") - set clipboard+=unnamed -else - set clipboard^=unnamed,unnamedplus -endif +set clipboard^=unnamed " Set color if !has('gui_running') diff --git a/common/.vim/key_maps.vim b/common/.vim/key_maps.vim index 5529dc4..8d69011 100644 --- a/common/.vim/key_maps.vim +++ b/common/.vim/key_maps.vim @@ -62,6 +62,10 @@ map l nnoremap :bnext nnoremap :bprevious +" Navigate Quickfixs +nnoremap [q cprev +nnoremap ]q cnext + " Resize window using arrow keys nnoremap :resize +2 nnoremap :resize -2 @@ -83,16 +87,29 @@ nnoremap :wa vnoremap :wa " Move cursor in insert mode -inoremap ^i +inoremap ^i inoremap inoremap inoremap inoremap inoremap +" Ctrl+Backspace to add an undo-point and delete last word +imap u + +" Insert mode: add undo points on "," & "." & ";" +imap , ,u +imap . .u +imap ; ;u + " Copy entire content of the current buffer nnoremap :%y+ +" Copy to system clipboard +nnoremap y "+y +vnoremap y "+y +" To paste from system clipboard "+p + " Clear search, diff update and redraw nnoremap / :nohlsearch:diffupdate:normal! @@ -104,4 +121,3 @@ nnoremap j (easymotion-s) " Show the undo tree nnoremap u :UndotreeToggle - diff --git a/common/.vim/vimrc b/common/.vim/vimrc index a96b9c3..5b93539 100644 --- a/common/.vim/vimrc +++ b/common/.vim/vimrc @@ -10,6 +10,9 @@ source $VIMDIR/configs.vim " Load Keybindings source $VIMDIR/key_maps.vim +" Load Autocommand +source $VIMDIR/autocommands.vim + " Save session files to $HOME/.vim/session directory let g:session_dir="$VIMDIR/session" diff --git a/common/.zshrc b/common/.zshrc index c52e7b8..fca12ef 100644 --- a/common/.zshrc +++ b/common/.zshrc @@ -47,14 +47,9 @@ HIST_STAMPS="dd.mm.yyyy" # Custom plugins may be added to $ZSH_CUSTOM/plugins/ plugins=( git - # dotenv - # dotnet gitignore - # colored-man-pages docker - # fd per-directory-history - # ripgrep sudo zsh-syntax-highlighting zsh-autosuggestions @@ -93,6 +88,7 @@ bindkey -v # Add brew provided autocompletions to path [[ ! -d "/home/linuxbrew/.linuxbrew/share/zsh/site-functions" ]] || FPATH="/home/linuxbrew/.linuxbrew/share/zsh/site-functions:$FPATH" + # Auto/tab completions autoload -Uz compinit zstyle ':completion::complete:*' gain-privileges 1 menu select cache-path "$XDG_CACHE_HOME/zsh/zcompcache" @@ -105,5 +101,11 @@ _comp_options+=(globdots) # Include hidden files # [alt+c] :fzf & cd into a directory under the current one [ -f "$XDG_STATE_HOME/shell/fzf.zsh" ] && source "$XDG_STATE_HOME/shell/fzf.zsh" -command -v zoxide >/dev/null && eval "$(zoxide init zsh)" -command -v zoxide >/dev/null && bindkey -s '^o' 'op\n' # Fuzzyfind projects and open in nvim +command -v zoxide >/dev/null && eval "$(zoxide init --cmd cd zsh)" + +# Source aliases and shell functions +for alias_file in "$XDG_CONFIG_HOME"/shell/*.sh; do source "$alias_file"; done + +# TIP: Following should be executed AFTER the aliases are sourced +command -v op >/dev/null && bindkey -s '^o' 'op\n' # Fuzzyfind projects and open in nvim +command -v pnew >/dev/null && bindkey -s '^[o' 'pnew\n' # Create a new project quickly diff --git a/kde-neon/.config/shell/aliases_neon b/kde-neon/.config/shell/aliases_neon.sh similarity index 100% rename from kde-neon/.config/shell/aliases_neon rename to kde-neon/.config/shell/aliases_neon.sh diff --git a/macos/.aliases_mac b/macos/shell/aliases_mac.sh similarity index 100% rename from macos/.aliases_mac rename to macos/shell/aliases_mac.sh