if HasPlug('toggleterm.nvim') then require("toggleterm").setup({ open_mapping = [[]], direction = 'float', float_opts = { border = 'rounded', width = function(term) return math.floor(vim.o.columns * 0.5) end, height = function(term) return math.floor(vim.o.lines * 0.5) end, winblend = 20, row = vim.o.lines * 0.5 - 3, col = vim.o.columns * 0.5, }, }) function _G.set_terminal_keymaps() local opts = { buffer = 0 } vim.keymap.set('t', '', [[]], opts) vim.keymap.set('t', 'jk', [[]], opts) vim.keymap.set('t', '', [[wincmd h]], opts) vim.keymap.set('t', '', [[wincmd j]], opts) vim.keymap.set('t', '', [[wincmd k]], opts) vim.keymap.set('t', '', [[wincmd l]], opts) vim.keymap.set('t', '', [[]], opts) end -- vim.cmd('autocmd TermOpen term://* lua set_terminal_keymaps()') vim.cmd('autocmd FileType toggleterm lua set_terminal_keymaps()') local Terminal = require('toggleterm.terminal').Terminal local ipythonId = 779 local ipython = Terminal:new({ size = function(term) if term.direction == "horizontal" then return 15 elseif term.direction == "vertical" then return vim.o.columns * 0.4 end end, cmd = "ipython", hidden = true, direction = "vertical", close_on_exit = false, auto_scroll = true, id = ipythonId, }) function _ipython_toggle() local currentWindow=vim.fn.winnr() ipython:toggle(vim.o.columns * 0.5, 'vertical') vim.cmd(currentWindow .. "wincmd w") end vim.api.nvim_set_keymap("n", "tp", "lua _ipython_toggle()", { noremap = true, silent = true }) vim.api.nvim_set_keymap("n", "tl", string.format("ToggleTermSendCurrentLine %d", ipythonId), { noremap = true, silent = true }) -- sends all the (whole) lines in your visual selection vim.api.nvim_set_keymap("v", "tl", string.format(":ToggleTermSendVisualLines %d", ipythonId), { noremap = true, silent = true }) -- sends only the visually selected text (this can be a block of text vim.api.nvim_set_keymap("x", "tl", string.format(":ToggleTermSendVisualSelection %d", ipythonId), { noremap = true, silent = true }) print(vim.o.shell) if vim.o.shell == 'pwsh' or vim.o.shell == 'powershell' then local powershell_options = { shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;", shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait", shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode", shellquote = "", shellxquote = "", } for option, value in pairs(powershell_options) do vim.opt[option] = value end end end