fix: set terminal open in new tab
This commit is contained in:
parent
8ed8f42731
commit
f3fb31a81d
1 changed files with 30 additions and 10 deletions
|
|
@ -8,18 +8,38 @@ vim.keymap.set('n', '<leader>cd', function()
|
||||||
print("cd to " .. path)
|
print("cd to " .. path)
|
||||||
end, { noremap = true, silent = true, desc = '현재 파일 경로로 cd' })
|
end, { noremap = true, silent = true, desc = '현재 파일 경로로 cd' })
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>`', function()
|
local terminal_tab_id = nil
|
||||||
local total_width = vim.o.columns
|
local previous_tab_id = nil
|
||||||
local target_width = math.floor(total_width * 0.3)
|
|
||||||
|
|
||||||
vim.cmd('vsplit')
|
vim.keymap.set({'n', 't'}, '<leader>`', function()
|
||||||
vim.cmd('wincmd l')
|
local current_tab = vim.api.nvim_get_current_tabpage()
|
||||||
vim.cmd('vertical resize ' .. target_width)
|
|
||||||
vim.cmd('terminal')
|
if terminal_tab_id and vim.api.nvim_tabpage_is_valid(terminal_tab_id) then
|
||||||
|
if current_tab == terminal_tab_id then
|
||||||
|
if previous_tab_id and vim.api.nvim_tabpage_is_valid(previous_tab_id) then
|
||||||
|
vim.api.nvim_set_current_tabpage(previous_tab_id)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
previous_tab_id = current_tab
|
||||||
|
vim.api.nvim_set_current_tabpage(terminal_tab_id)
|
||||||
|
|
||||||
|
-- 이미 열린 터미널 탭일 경우에도 인서트 모드로
|
||||||
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
if vim.bo[bufnr].buftype == "terminal" then
|
||||||
vim.cmd('startinsert')
|
vim.cmd('startinsert')
|
||||||
end, { noremap = true, silent = true, desc = '오른쪽에 터미널 열기 (30% 너비)' })
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
previous_tab_id = current_tab
|
||||||
|
vim.cmd('tabnew')
|
||||||
|
vim.cmd('terminal bash')
|
||||||
|
vim.cmd('startinsert')
|
||||||
|
terminal_tab_id = vim.api.nvim_get_current_tabpage()
|
||||||
|
|
||||||
vim.keymap.set('t', '<Esc>', [[<C-\><C-n>]], { noremap = true, silent = true })
|
local bufnr = vim.api.nvim_get_current_buf()
|
||||||
|
vim.api.nvim_buf_set_name(bufnr, '[Terminal]')
|
||||||
|
end
|
||||||
|
end, { noremap = true, silent = true, desc = '터미널 탭 토글 (bash)' })
|
||||||
|
|
||||||
vim.keymap.set('n', '<leader>tn', ':tabnew<CR>')
|
vim.keymap.set('n', '<leader>tn', ':tabnew<CR>')
|
||||||
vim.keymap.set('n', '<leader>tl', ':tabnext<CR>')
|
vim.keymap.set('n', '<leader>tl', ':tabnext<CR>')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue