From 417457e65404d4f51af3a7ed9ec2a0996bd5137b Mon Sep 17 00:00:00 2001 From: johnseth97 <17620345+johnseth97@users.noreply.github.com> Date: Tue, 19 Aug 2025 21:30:01 -0400 Subject: [PATCH] feat(config)!: fixed conflicting keybinds, allow remap The new default will now use to close the codex window, remappable by the user. Other vim standard methods have many conflicts with the codex app --- README.md | 11 ++++++----- lua/codex/init.lua | 17 ++++++++++++++--- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 62a4d95..52853f4 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,14 @@ # Codex Neovim Plugin image -## A Neovim plugin integrating the open-sourced Codex CLI (`codex`). +## A Neovim plugin integrating the open-sourced Codex CLI (`codex`) > Latest version: ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/johnseth97/codex.nvim?sort=semver) -Note: As of v1.0.0, no longer closes the Codex window. Press q to close, and to safely interrupt model generation without resetting context. - ### Features: - ✅ Toggle Codex floating window with `:CodexToggle` - ✅ Optional keymap mapping via `setup` call - ✅ Background running when window hidden -- ✅ Statusline integration via `require('codex').status()` +- ✅ Statusline integration via `require('codex').status()` ### Installation: @@ -42,7 +40,10 @@ return { }, }, opts = { - keymaps = {}, -- Disable internal default keymap (cc -> :CodexToggle) + keymaps = { + toggle = nil, -- Keybind to toggle Codex window (Disabled by default, watch out for conflicts) + quit = '', -- Keybind to close the Codex window (default: Ctrl + q) + }, -- Disable internal default keymap (cc -> :CodexToggle) border = 'rounded', -- Options: 'single', 'double', or 'rounded' width = 0.8, -- Width of the floating window (0.0 to 1.0) height = 0.8, -- Height of the floating window (0.0 to 1.0) diff --git a/lua/codex/init.lua b/lua/codex/init.lua index 22a4f26..0571c94 100644 --- a/lua/codex/init.lua +++ b/lua/codex/init.lua @@ -5,7 +5,10 @@ local state = require 'codex.state' local M = {} local config = { - keymaps = {}, + keymaps = { + toggle = nil, + quit = '', -- Default: Ctrl+q to quit + }, border = 'single', width = 0.8, height = 0.8, @@ -86,11 +89,19 @@ end function M.open() local function create_clean_buf() local buf = vim.api.nvim_create_buf(false, false) + vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide') vim.api.nvim_buf_set_option(buf, 'swapfile', false) vim.api.nvim_buf_set_option(buf, 'filetype', 'codex') - vim.api.nvim_buf_set_keymap(buf, 't', 'q', [[lua require('codex').close()]], { noremap = true, silent = true }) - vim.api.nvim_buf_set_keymap(buf, 'n', 'q', [[lua require('codex').close()]], { noremap = true, silent = true }) + + -- Apply configured quit keybinding + + if config.keymaps.quit then + local quit_cmd = [[lua require('codex').close()]] + vim.api.nvim_buf_set_keymap(buf, 't', config.keymaps.quit, [[]] .. quit_cmd, { noremap = true, silent = true }) + vim.api.nvim_buf_set_keymap(buf, 'n', config.keymaps.quit, quit_cmd, { noremap = true, silent = true }) + end + return buf end