Skip to content

Instantly share code, notes, and snippets.

@kevinma2010
Created July 21, 2025 06:31
Show Gist options
  • Select an option

  • Save kevinma2010/c696cbd06a37c2aa2a3cb70a9b6cab9d to your computer and use it in GitHub Desktop.

Select an option

Save kevinma2010/c696cbd06a37c2aa2a3cb70a9b6cab9d to your computer and use it in GitHub Desktop.
-- Function to open a terminal on the far right
local function open_term_on_right()
-- Set terminal width to 30% of the editor's width
local percentage = 30
local width = math.floor(vim.o.columns * (percentage / 100))
-- Open a terminal in a new vertical split
vim.cmd('vert term')
-- Move focus to the right-most window (the new terminal)
vim.cmd('wincmd L')
-- Resize the terminal window to the calculated width
vim.cmd('vertical resize ' .. width)
end
-- Map <leader>tr to open the terminal in normal mode
vim.keymap.set('n', '<leader>tr', open_term_on_right, {
noremap = true,
silent = true,
desc = "Open terminal on the far right"
})
-- Map Esc to exit terminal mode and return to normal mode
vim.keymap.set('t', '<Esc>', [[<C-\><C-n>]], {
noremap = true,
silent = true,
desc = "Exit terminal mode"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment