kickstart.nvim/ftplugin/python.lua
2024-09-06 22:15:53 +02:00

18 lines
832 B
Lua

-- original from: https://stackoverflow.com/questions/76954973/how-to-set-keybindings-to-execute-python-files-in-neovim-using-the-built-in-term
local function run_curr_python_file_in_toggleterm()
local file_name = vim.api.nvim_buf_get_name(0)
local py_cmd = vim.api.nvim_replace_termcodes('python3 "' .. file_name .. '"<cr>', true, false, true)
-- local py_cmd = vim.api.nvim_replace_termcodes('python3 "' .. file_name .. '"<cr> <Esc> :ToggleTerm', true, false, true)
local end_cmd = vim.api.nvim_replace_termcodes('<C-d>', true, false, true)
vim.cmd ':ToggleTerm direction=float'
vim.api.nvim_feedkeys(py_cmd, 't', false)
vim.api.nvim_feedkeys(end_cmd, 't', false)
end
vim.keymap.set({ 'n' }, '<A-e>', '', {
desc = 'Run .py file via Neovim built-in terminal',
callback = run_curr_python_file_in_toggleterm,
})