diff options
| author | Kyren223 <kyren223@proton.me> | 2025-08-16 18:58:14 +0300 |
|---|---|---|
| committer | Kyren223 <kyren223@proton.me> | 2025-08-16 18:58:14 +0300 |
| commit | e1ca57c93e8a65d5e0dde445a1337ffb2240ef3a (patch) | |
| tree | e98f1cab47b844cf767a5be3edbc9edee1f82f34 /.config/nvim/lua/autocmds.lua | |
| parent | eff8eec4c871e902069ef066993cca79fb8bbc29 (diff) | |
Add casey-style alt+m recompilation for krypton
Diffstat (limited to '.config/nvim/lua/autocmds.lua')
| -rw-r--r-- | .config/nvim/lua/autocmds.lua | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/.config/nvim/lua/autocmds.lua b/.config/nvim/lua/autocmds.lua index 608708b..190e4e4 100644 --- a/.config/nvim/lua/autocmds.lua +++ b/.config/nvim/lua/autocmds.lua @@ -14,7 +14,7 @@ vim.api.nvim_create_autocmd('BufEnter', { desc = 'Disable newlines on commented lines from continuing the comment', group = augroup('disable-comments-continuation'), callback = function() - vim.opt_local.formatoptions:remove('r') -- no comments on enter + -- vim.opt_local.formatoptions:remove('r') -- no comments on enter vim.opt_local.formatoptions:remove('o') -- no comments on `o` or `O` end, }) @@ -266,3 +266,41 @@ vim.api.nvim_create_autocmd({ 'VimEnter', 'BufRead', 'BufWinEnter', 'BufWritePos RenderTodoHighlights(bufnr) end, }) + +function Jump_to_error(focus) + local line = vim.api.nvim_get_current_line() + local path, lnum, col = line:match('([^:]+):(%d+):(%d+):') + if not (path and lnum) then + vim.cmd('normal! gd') + return + end + + local main_win = nil + for _, win in ipairs(vim.api.nvim_list_wins()) do + local buf = vim.api.nvim_win_get_buf(win) + if vim.api.nvim_buf_get_option(buf, 'buftype') ~= 'terminal' then + main_win = win + break + end + end + + if main_win then + vim.api.nvim_win_call(main_win, function() + vim.cmd('edit ' .. path) + vim.api.nvim_win_set_cursor(0, { tonumber(lnum), tonumber(col) - 1 }) + end) + if focus then + vim.api.nvim_set_current_win(main_win) + end + else + vim.cmd('edit ' .. path) + vim.api.nvim_win_set_cursor(0, { tonumber(lnum), tonumber(col) - 1 }) + end +end + +vim.api.nvim_create_autocmd('TermOpen', { + callback = function(args) + vim.api.nvim_buf_set_keymap(args.buf, 'n', 'gd', '<cmd>lua Jump_to_error(true)<CR>', { noremap = true, silent = true }) + vim.api.nvim_buf_set_keymap(args.buf, 'n', 'go', '<cmd>lua Jump_to_error(false)<CR>', { noremap = true, silent = true }) + end, +}) |
