Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
> Latest version: ![GitHub tag (latest SemVer)](https://img.shields.io/github/v/tag/johnseth97/codex.nvim?sort=semver)

### Features:
- ✅ Toggle Codex window or side-panel with `:CodexToggle`
- ✅ Toggle Codex window, side-panel, or horizontal split with `:CodexToggle`
- ✅ Optional keymap mapping via `setup` call
- ✅ Background running when window hidden
- ✅ Statusline integration via `require('codex').status()`
Expand Down Expand Up @@ -36,7 +36,7 @@ return {
{
'<leader>cc', -- Change this to your preferred keybinding
function() require('codex').toggle() end,
desc = 'Toggle Codex popup or side-panel',
desc = 'Toggle Codex window',
mode = { 'n', 't' }
},
},
Expand All @@ -46,19 +46,25 @@ return {
quit = '<C-q>', -- Keybind to close the Codex window (default: Ctrl + q)
}, -- Disable internal default keymap (<leader>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)
width = 0.8, -- Width of the floating window or split (0.0 to 1.0)
height = 0.8, -- Height of the floating window or split (0.0 to 1.0)
model = nil, -- Optional: pass a string to use a specific model (e.g., 'o3-mini')
autoinstall = true, -- Automatically install the Codex CLI if not found
panel = false, -- Open Codex in a side-panel (vertical split) instead of floating window
panel = false, -- Open Codex in a panel (split) instead of floating window
layout = 'vertical', -- 'vertical' or 'horizontal' (only applies when panel = true)
use_buffer = false, -- Capture Codex stdout into a normal buffer instead of a terminal buffer
},
}```

### Usage:
- Call `:Codex` (or `:CodexToggle`) to open or close the Codex popup or side-panel.
- Call `:Codex` (or `:CodexToggle`) to open or close the Codex window.
- Map your own keybindings via the `keymaps.toggle` setting.
- To choose floating popup vs side-panel, set `panel = false` (popup) or `panel = true` (panel) in your setup options.
- Configure the window display:
- Set `panel = false` for a floating window (default)
- Set `panel = true` for an in-place split panel
- When `panel = true`, use `layout` to choose split direction:
- `layout = 'vertical'` - Vertical split on the right (default)
- `layout = 'horizontal'` - Horizontal split at the bottom
- To capture Codex output in an editable buffer instead of a terminal, set `use_buffer = true` (or `false` to keep terminal) in your setup options.
- Add the following code to show backgrounded Codex window in lualine:

Expand Down
40 changes: 35 additions & 5 deletions lua/codex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ local config = {
cmd = 'codex',
model = nil, -- Default to the latest model
autoinstall = true,
panel = false, -- if true, open Codex in a side-panel instead of floating window
use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal
panel = false, -- if true, open Codex in a panel instead of floating window
layout = 'vertical', -- 'vertical' or 'horizontal' (only applies when panel = true)
use_buffer = false, -- if true, capture Codex stdout into a normal buffer instead of a terminal
}

function M.setup(user_config)
Expand Down Expand Up @@ -100,6 +101,35 @@ local function open_panel()
state.win = win
end

--- Open Codex in a horizontal split at the bottom
local function open_horizontal_split()
-- Create a horizontal split at the bottom and show the buffer
vim.cmd('rightbelow split')
local win = vim.api.nvim_get_current_win()
vim.api.nvim_win_set_buf(win, state.buf)
-- Adjust height according to config (percentage of total lines)
local height = math.floor(vim.o.lines * config.height)
vim.api.nvim_win_set_height(win, height)
state.win = win
end

--- Open the window based on the configured panel and layout settings
local function open_based_on_config()
if config.panel then
-- Panel mode: check layout to decide between vertical and horizontal
local layout = config.layout or 'vertical'
if layout == 'horizontal' then
open_horizontal_split()
else
-- Default to vertical split for backward compatibility
open_panel()
end
else
-- Floating window mode
open_window()
end
end

function M.open()
local function create_clean_buf()
local buf = vim.api.nvim_create_buf(false, false)
Expand Down Expand Up @@ -142,7 +172,7 @@ function M.open()
'You can install manually with:',
' npm install -g @openai/codex',
})
if config.panel then open_panel() else open_window() end
open_based_on_config()
end
end)
return
Expand All @@ -159,7 +189,7 @@ function M.open()
'',
'Or enable autoinstall in setup: require("codex").setup{ autoinstall = true }',
})
if config.panel then open_panel() else open_window() end
open_based_on_config()
return
end
end
Expand All @@ -172,7 +202,7 @@ function M.open()
state.buf = create_clean_buf()
end

if config.panel then open_panel() else open_window() end
open_based_on_config()

if not state.job then
-- assemble command
Expand Down