Quality of life features, ensure start in insert mode when only the terminal is initially launched, automatically adding node_modules binaries to PATH in relative working dir

This commit is contained in:
Curt Spark 2024-11-09 07:08:49 +00:00
parent 6d81f1431d
commit bca52717b3
2 changed files with 37 additions and 18 deletions

View File

@ -14,12 +14,17 @@ vim.cmd("map <C-c> <Nop>")
-- vim.cmd("tnoremap <Esc> <C-\\><C-n>")
vim.cmd("tnoremap <C-g> <C-\\><C-n>")
-- Autostart in Insert mode
vim.cmd("startinsert")
-- vim.cmd("startinsert")
-- Autostart terminal buffers in insert/terminal mode
vim.api.nvim_create_autocmd({ 'VimEnter' }, {
pattern = 'bash',
command = 'startinsert',
})
-- Relative and Absolute line numbers. Hybrid.
vim.opt.nu = true
vim.opt.relativenumber = true
vim.o.statuscolumn = "%s %l %r "
-- vim.o.statuscolumn = "%s %l %r " -- Both displayed on their own seperate lines
-- Highlight current cursor line
vim.opt.cursorline = true
@ -79,6 +84,31 @@ vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, {
command = 'set filetype=yaml.docker-compose',
})
-- Spooky thing that will attempt to add any relative to current working directory node_modules binaries to PATH on startup
node_modules_path_original = vim.env.PATH
-- Refresh PATH on new file
vim.api.nvim_create_autocmd({ 'BufEnter', 'BufNewFile' }, {
callback = function ()
vim.env.PATH = node_modules_path_original
currentPWD = vim.loop.cwd()
node_modules_path = vim.fn.system("printf `if [[ -d " .. currentPWD .. "/node_modules ]]; then find ./node_modules -maxdepth 2 -regex '.*/bin' | xargs realpath | paste -s -d ':'; else realpath " .. currentPWD.. "/node_modules; fi`")
vim.env.PATH = vim.env.PATH .. ":" .. node_modules_path
end,
})
-- Spooky thing that will change the vim working directory based on what we cd into via the :terminal to keep them in sync, uses an external wrapper script called cd-nvim which overrides the cd command to send the signal alongside with the new working directory to Neovim
-- See :help terminal-events, we can use this to implement cd commands etc changing the working directory of the nvim host and other terminal app to nvim host ipc.
-- sleep 5 && printf "\033]7;file://${PWD}/foo/bar\033\\"
-- \033]7 AKA \x1b]7 enclosed by another \033\\ is used as a custom signal to denote which is a valid request to handle I'm asssuming, but technically everything in the terminal is being listened to
vim.api.nvim_create_autocmd({ 'TermRequest' }, {
desc = 'Handles OSC 7 dir change requests',
callback = function(ev)
if string.sub(vim.v.termrequest, 1, 4) == '\x1b]7;' then
local dir = string.gsub(vim.v.termrequest, '\x1b]7;file://[^/.]*', '')
vim.cmd("cd " .. dir)
end
end
})
-- LSP Configuration
local lsp_zero = require('lsp-zero')
@ -371,15 +401,3 @@ require("which-key").add ({
end, desc = "Debugger: Step into" },
}
})
-- See :help terminal-events, we can use this to implement cd commands etc changing the working directory of the nvim host and other terminal app to nvim host ipc.
-- sleep 5 && printf "\033]7;file://${PWD}/foo/bar\033\\"
vim.api.nvim_create_autocmd({ 'TermRequest' }, {
desc = 'Handles OSC 7 dir change requests',
callback = function(ev)
if string.sub(vim.v.termrequest, 1, 4) == '\x1b]7;' then
local dir = string.gsub(vim.v.termrequest, '\x1b]7;file://[^/.]*', '')
vim.cmd("cd " .. dir)
end
end
})

View File

@ -1,16 +1,17 @@
{
"LuaSnip": { "branch": "master", "commit": "29417eea5b7c4b6beda105ced072855101d9680e" },
"LuaSnip": { "branch": "master", "commit": "2737edc9e674e537dc0a97e3405658d57d2d31ed" },
"cmp-nvim-lsp": { "branch": "main", "commit": "39e2eda76828d88b773cc27a3f61d2ad782c922d" },
"dashboard-nvim": { "branch": "master", "commit": "ae309606940d26d8c9df8b048a6e136b6bbec478" },
"gruvbox.nvim": { "branch": "main", "commit": "49d9c0b150ba70efcd831ec7b3cb8ee740067045" },
"lazy.nvim": { "branch": "main", "commit": "b1134ab82ee4279e31f7ddf7e34b2a99eb9b7bc9" },
"lsp-zero.nvim": { "branch": "v3.x", "commit": "56db3d5ce5476b183783160e6045f7337ba12b83" },
"lsp-zero.nvim": { "branch": "v3.x", "commit": "ab2a3413646fedd77aa0eab4214a6473e62f6a64" },
"mini.statusline": { "branch": "main", "commit": "813854243156472c9d0bc9c64ea0af159b9b37ca" },
"nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" },
"nvim-dap": { "branch": "master", "commit": "8517126e9323e346f6a99b3b594c5a940b914dcd" },
"nvim-lspconfig": { "branch": "master", "commit": "bc6ada4b0892b7f10852c0b8ca7209fd39a6d754" },
"nvim-lspconfig": { "branch": "master", "commit": "d01864641c6e43c681c3e9f6cf4745c75fdd9dcc" },
"nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" },
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
"telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" },
"which-key.nvim": { "branch": "main", "commit": "8badb359f7ab8711e2575ef75dfe6fbbd87e4821" }
"vim-jsdoc": { "branch": "master", "commit": "6e5bc2a1f98a69e4902081c9f5969b228a7a5fd6" },
"which-key.nvim": { "branch": "main", "commit": "68e37e12913a66b60073906f5d3f14dee0de19f2" }
}