0

FYI noob here.

I want to run current file in floating terminal. I'm using NvChad and when I execute ALT+i I get the following: enter image description here

I already played with some key binds, but I haven't achieved what I need. Currently, in my ~/.config/nvim/lua/custom/mappings.lua I have the following:

---@type MappingsTable
local M = {}

M.general = {
  n = {
    [";"] = { ":", "enter command mode", opts = { nowait = true } },
  },
}

-- more keybinds!
M.custom = {
  n = {
    ["<C-R>"] = {"<cmd>sp<CR><cmd>term python %<CR>", "Run current Python file in terminal"},
    ["<C-W>"] = {":bd!<CR>", "Close current buffer"}
  }
}

return M

When I do C-R I can run succesfuly the python file but currently it goes horizontally and below my current file.

I tried tabnew and split but no luck.

By the way, from documentation I have:

  • C = CTRL

  • leader = SPACE

  • A = ALT

  • S = SHIFT

  • A-i: to open a terminal in a floating tab

  • A-h: to open a terminal in horizontal term

  • A-v: to open a terminal in vertical term

And I'm using Linux fedora

Any thoughts?

1 Answer 1

0

I would do:

-- more keybinds!
M.custom = {
  n = {
    ["<C-R>"] = {"<Cmd>lua require('nvterm.terminal').send('py ' .. vim.fn.expand('%') .. '\\r', 'float')<CR>", "Run current Python file in terminal"},
    ["<C-W>"] = {":bd!<CR>", "Close current buffer"}
  }
}
7
  • Thank you! This works for me! @Vivian De Smedt By the way, it's not a big deal, but when I run it I get the floating terminal and I have one line with the py file.py, and for some reason I have 2 more lines in blank like if I have pressed enter.
    – indochina
    Apr 2 at 21:39
  • 1
    Oh nevermind I understood, the \\r is a special character sequence that sends a "carriage return" to the terminal. Thanks!
    – indochina
    Apr 2 at 21:51
  • Oh crap, I got a new problem. When having activated a virtualenv I cannot do it, what a bummer.
    – indochina
    Apr 3 at 3:26
  • 1
    Haha, never mind again! Did a noob mistake, echo $PATH was not correct.
    – indochina
    Apr 3 at 3:58
  • 1
    PS I wouldn’t override the defaults for redo and wincmd
    – D. Ben Knoble
    Apr 3 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.