From d063a5461c7cf16bcb2a429f7bf2812d7462cab8 Mon Sep 17 00:00:00 2001 From: ignuki Date: Thu, 13 Feb 2025 20:23:23 +0100 Subject: [PATCH] fixes and improvements --- keystrokes.txt | 0 nvim/.config/nvim/lua/ink/init.lua | 109 +++++++++---------- nvim/.config/nvim/lua/ink/remap.lua | 8 +- nvim/.config/nvim/lua/plugins/completion.lua | 2 + nvim/.config/nvim/lua/plugins/linting.lua | 1 + nvim/.config/nvim/lua/plugins/tmux.lua | 27 ++++- tmux/.is_vim.sh | 25 +++++ tmux/.tmux.conf | 10 +- 8 files changed, 112 insertions(+), 70 deletions(-) create mode 100644 keystrokes.txt create mode 100755 tmux/.is_vim.sh diff --git a/keystrokes.txt b/keystrokes.txt new file mode 100644 index 0000000..e69de29 diff --git a/nvim/.config/nvim/lua/ink/init.lua b/nvim/.config/nvim/lua/ink/init.lua index a8cd911..00fa5e3 100644 --- a/nvim/.config/nvim/lua/ink/init.lua +++ b/nvim/.config/nvim/lua/ink/init.lua @@ -5,43 +5,43 @@ vim.wo.number = true vim.opt.relativenumber = true vim.opt.mouse = "a" vim.opt.clipboard = "unnamedplus" -vim.opt.breakindent = true -- Enable break indent -vim.opt.undofile = true -- Save undo history -vim.opt.ignorecase = true -- ignore case in searches by default -vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered -vim.w.signcolumn = "yes" -- Keep signcolumn on by default -vim.opt.updatetime = 250 -- Decrease update time -vim.opt.timeoutlen = 300 -- time to wait for a mapped sequence to complete (in milliseconds) -vim.opt.backup = false -- creates a backup file -vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited +vim.opt.breakindent = true -- Enable break indent +vim.opt.undofile = true -- Save undo history +vim.opt.ignorecase = true -- ignore case in searches by default +vim.opt.smartcase = true -- but make it case sensitive if an uppercase is entered +vim.w.signcolumn = "yes" -- Keep signcolumn on by default +vim.opt.updatetime = 250 -- Decrease update time +vim.opt.timeoutlen = 300 -- time to wait for a mapped sequence to complete (in milliseconds) +vim.opt.backup = false -- creates a backup file +vim.opt.writebackup = false -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited vim.opt.completeopt = "menuone,noselect" -- Set completeopt to have a better completion experience -vim.opt.termguicolors = true -- set termguicolors to enable highlight groups -vim.opt.whichwrap = "bs<>[]hl" -- which "horizontal" keys are allowed to travel to prev/next line -vim.opt.wrap = false -- display lines as one long line -vim.opt.linebreak = true -- companion to wrap don't split words -vim.opt.scrolloff = 4 -- minimal number of screen lines to keep above and below the cursor -vim.opt.sidescrolloff = 8 -- minimal number of screen columns either side of cursor if wrap is `false` -vim.opt.numberwidth = 2 -- set number column width to 2 {default 4} -vim.opt.shiftwidth = 4 -- Number of spaces inserted when indenting -vim.opt.tabstop = 4 -- A TAB character looks like 4 spaces -vim.opt.softtabstop = 4 -- Number of spaces inserted instead of a TAB character -vim.opt.expandtab = true -- Pressing the TAB key will insert spaces instead of a TAB character +vim.opt.termguicolors = true -- set termguicolors to enable highlight groups +vim.opt.whichwrap = "bs<>[]hl" -- which "horizontal" keys are allowed to travel to prev/next line +vim.opt.wrap = false -- display lines as one long line +vim.opt.linebreak = true -- companion to wrap don't split words +vim.opt.scrolloff = 4 -- minimal number of screen lines to keep above and below the cursor +vim.opt.sidescrolloff = 8 -- minimal number of screen columns either side of cursor if wrap is `false` +vim.opt.numberwidth = 2 -- set number column width to 2 {default 4} +vim.opt.shiftwidth = 4 -- Number of spaces inserted when indenting +vim.opt.tabstop = 4 -- A TAB character looks like 4 spaces +vim.opt.softtabstop = 4 -- Number of spaces inserted instead of a TAB character +vim.opt.expandtab = true -- Pressing the TAB key will insert spaces instead of a TAB character vim.opt.cursorline = true -vim.opt.splitbelow = true -- open new vertical split bottom -vim.opt.splitright = true -- open new horizontal splits right -vim.opt.swapfile = false -- creates a swapfile -vim.opt.smartindent = true -- make indenting smarter again -vim.opt.showtabline = 2 -- always show tabs -vim.opt.backspace = "indent,eol,start" -- allow backspace on -vim.opt.pumheight = 10 -- pop up menu height -vim.wo.conceallevel = 0 -- so that `` is visible in markdown files -vim.opt.encoding = "utf-8" -- the encoding written to a file -vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages +vim.opt.splitbelow = true -- open new vertical split bottom +vim.opt.splitright = true -- open new horizontal splits right +vim.opt.swapfile = false -- creates a swapfile +vim.opt.smartindent = true -- make indenting smarter again +vim.opt.showtabline = 2 -- always show tabs +vim.opt.backspace = "indent,eol,start" -- allow backspace on +vim.opt.pumheight = 10 -- pop up menu height +vim.wo.conceallevel = 0 -- so that `` is visible in markdown files +vim.opt.encoding = "utf-8" -- the encoding written to a file +vim.opt.cmdheight = 1 -- more space in the neovim command line for displaying messages vim.opt.autoindent = true -vim.opt.shortmess:append("c") -- don't give |ins-completion-menu| messages -vim.opt.iskeyword:append("-") -- hyphenated words recognized by searches -vim.opt.formatoptions:remove({ "c", "r", "o" }) -- don't insert the current comment leader automatically for auto-wrapping comments using 'textwidth', hitting in insert mode, or hitting 'o' or 'O' in normal mode. +vim.opt.shortmess:append("c") -- don't give |ins-completion-menu| messages +vim.opt.iskeyword:append("-") -- hyphenated words recognized by searches +vim.opt.formatoptions:remove({ "c", "r", "o" }) -- don't insert the current comment leader automatically for auto-wrapping comments using 'textwidth', hitting in insert mode, or hitting 'o' or 'O' in normal mode. vim.opt.runtimepath:remove("/usr/share/vim/vimfiles") -- separate vim plugins from neovim in case vim still in use vim.opt.foldmethod = "expr" @@ -52,31 +52,27 @@ vim.opt.foldlevelstart = 99 vim.opt.foldnestmax = 6 vim.opt.incsearch = true -- search as characters are entered -vim.opt.tags:append({ ".git/tags", "tags" }) - -vim.opt.shell = "/bin/zsh" - -- remove trailing whitespace vim.api.nvim_create_autocmd({ "BufWritePre" }, { - pattern = { "*" }, - callback = function() - local save_cursor = vim.fn.getpos(".") - pcall(function() - vim.cmd([[%s/\s\+$//e]]) - end) - vim.fn.setpos(".", save_cursor) - end, + pattern = { "*" }, + callback = function() + local save_cursor = vim.fn.getpos(".") + pcall(function() + vim.cmd([[%s/\s\+$//e]]) + end) + vim.fn.setpos(".", save_cursor) + end, }) -- local uv = vim.uv local uv = vim.loop vim.api.nvim_create_autocmd({ "VimEnter", "VimLeave" }, { - callback = function() - if vim.env.TMUX_PLUGIN_MANAGER_PATH then - uv.spawn(vim.env.TMUX_PLUGIN_MANAGER_PATH .. "/tmux-window-name/scripts/rename_session_windows.py", {}) - end - end, + callback = function() + if vim.env.TMUX_PLUGIN_MANAGER_PATH then + uv.spawn(vim.env.TMUX_PLUGIN_MANAGER_PATH .. "/tmux-window-name/scripts/rename_session_windows.py", {}) + end + end, }) -- -- Filetypes to enable spellcheck @@ -90,11 +86,10 @@ vim.api.nvim_create_augroup("Spellcheck", { clear = true }) -- Create an autocommand to enable spellcheck for specified file types vim.api.nvim_create_autocmd({ "FileType" }, { - group = "Spellcheck", -- Grouping the command for easier management - pattern = spell_types, -- Only apply to these file types - callback = function() - vim.opt_local.spell = true -- Enable spellcheck for these file types - end, - desc = "Enable spellcheck for defined filetypes", -- Description for clarity + group = "Spellcheck", -- Grouping the command for easier management + pattern = spell_types, -- Only apply to these file types + callback = function() + vim.opt_local.spell = true -- Enable spellcheck for these file types + end, + desc = "Enable spellcheck for defined filetypes", -- Description for clarity }) - diff --git a/nvim/.config/nvim/lua/ink/remap.lua b/nvim/.config/nvim/lua/ink/remap.lua index 3437d6e..910ec8d 100644 --- a/nvim/.config/nvim/lua/ink/remap.lua +++ b/nvim/.config/nvim/lua/ink/remap.lua @@ -47,10 +47,10 @@ map("n", "gl", "`.", { desc = "Jump to the last change in the file" }) -- map('n', '', 'zr', { desc = 'Open all folds' }) -- map('n', '', 'zR', { desc = 'Open all folds' }) -map("n", "", "", { desc = "Move to split upwards" }) -map("n", "", "", { desc = "Move to split upwards" }) -map("n", "", "", { desc = "Move to split left" }) -map("n", "", "", { desc = "Move to split right" }) +-- map("n", "", "", { desc = "Move to split upwards" }) +-- map("n", "", "", { desc = "Move to split upwards" }) +-- map("n", "", "", { desc = "Move to split left" }) +-- map("n", "", "", { desc = "Move to split right" }) map("n", "", "", { desc = "Move screen up one line" }) map("n", "", "", { desc = "Move screen down one line" }) diff --git a/nvim/.config/nvim/lua/plugins/completion.lua b/nvim/.config/nvim/lua/plugins/completion.lua index c317e54..6b2370c 100644 --- a/nvim/.config/nvim/lua/plugins/completion.lua +++ b/nvim/.config/nvim/lua/plugins/completion.lua @@ -228,6 +228,8 @@ return { ["rust-analyzer"] = {}, }, }, + -- brew install bash-language-server + bashls = {}, -- lua_ls = { -- settings = { -- Lua = { diff --git a/nvim/.config/nvim/lua/plugins/linting.lua b/nvim/.config/nvim/lua/plugins/linting.lua index 179e7bf..80e3f15 100644 --- a/nvim/.config/nvim/lua/plugins/linting.lua +++ b/nvim/.config/nvim/lua/plugins/linting.lua @@ -6,6 +6,7 @@ return { local lint = require("lint") lint.linters_by_ft = { lua = { "luacheck" }, + bash = { "bash" }, } local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true }) diff --git a/nvim/.config/nvim/lua/plugins/tmux.lua b/nvim/.config/nvim/lua/plugins/tmux.lua index 6633be3..95c8d44 100644 --- a/nvim/.config/nvim/lua/plugins/tmux.lua +++ b/nvim/.config/nvim/lua/plugins/tmux.lua @@ -8,12 +8,27 @@ return { disable_when_zoomed = true, -- defaults to false }) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateLeft) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateDown) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateUp) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateRight) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateLastActive) - vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateNext) + vim.keymap.set( + "n", + "", + nvim_tmux_nav.NvimTmuxNavigateLeft, + { desc = "Move to the split to the left" } + ) + vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateDown, { desc = "Move to the split below" }) + vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateUp, { desc = "Move to the split above" }) + vim.keymap.set( + "n", + "", + nvim_tmux_nav.NvimTmuxNavigateRight, + { desc = "Move to the split to the right" } + ) + vim.keymap.set( + "n", + "", + nvim_tmux_nav.NvimTmuxNavigateLastActive, + { desc = "Move to the last active split" } + ) + vim.keymap.set("n", "", nvim_tmux_nav.NvimTmuxNavigateNext, { desc = "Move to the next split" }) end, }, } diff --git a/tmux/.is_vim.sh b/tmux/.is_vim.sh new file mode 100755 index 0000000..04903de --- /dev/null +++ b/tmux/.is_vim.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash +# Usage: is_vim.sh +# tty: Specify tty to check for vim process. +tty=$1 + +# Construct process tree. +children=(); +pids=( $(ps -o pid= -t $tty) ) + +while read -r pid ppid +do + [[ -n pid && pid -ne ppid ]] && children[ppid]+=" $pid" +done <<< "$(ps -Ao pid=,ppid=)" + +# Get all descendant pids of processes in $tty with BFS +idx=0 +while (( ${#pids[@]} > idx )) +do + pid=${pids[idx++]} + pids+=( ${children[pid]-} ) +done + +# Check whether any child pids are vim +ps -o state=,comm= -p "${pids[@]}" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$' +exit $? diff --git a/tmux/.tmux.conf b/tmux/.tmux.conf index 2e27c56..3918b95 100644 --- a/tmux/.tmux.conf +++ b/tmux/.tmux.conf @@ -29,8 +29,8 @@ set -g @tmux_window_name_shells "['bash', 'fish', 'sh', 'zsh']" set -g @tmux_window_dir_programs "['nvim', 'vim', 'vi', 'git']" set -g @tmux_window_name_use_tilde "True" set -g @tmux_window_name_max_name_len "100" -set-option -g default-shell $SHELL -set -g default-command "$SHELL -i" +# set-option -g default-shell $SHELL +# set -g default-command "$SHELL -i" # Other examples: # set -g @plugin 'github_username/plugin_name' @@ -61,8 +61,12 @@ setw -g mode-keys vi # decide whether we're in a Vim process #is_vim="ps -o state= -o comm= -t '#{pane_tty}' \ # | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" + is_vim="~/.is_vim.sh '#{pane_tty}'" +# is_vim="children=(); i=0; pids=( $(ps -o pid=,tty= | grep -iE '#{s|/dev/||:pane_tty}' | awk '\{print $1\}') ); \ +# while read -r c p; do [[ -n c && c -ne p && p -ne 0 ]] && children[p]+=\" $\{c\}\"; done <<< \"$(ps -Ao pid=,ppid=)\"; \ +# while (( $\{#pids[@]\} > i )); do pid=$\{pids[i++]\}; pids+=( $\{children[pid]-\} ); done; \ +# ps -o state=,comm= -p \"$\{pids[@]\}\" | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'" -is_vim="~/is_vim.sh '#{pane_tty}'" bind-key -n 'S-Left' if-shell "$is_vim" 'send-keys S-Left' 'select-pane -L' bind-key -n 'S-Down' if-shell "$is_vim" 'send-keys S-Down' 'select-pane -D'