iron.nvim
iron.nvim copied to clipboard
Feature Request: Send line and move cursor down
For most REPLs, I find it quite convenient to execute code line by line. I've written a small helper function to make send the current line and then move the cursor to the next line:
vim.keymap.set('n', '<space><space>', function()
local last_line = vim.fn.line('$')
local pos = vim.api.nvim_win_get_cursor(0)
require('iron.core').send_line()
vim.api.nvim_win_set_cursor(0, { math.min(pos[1] + 1, last_line), pos[2] })
end)
I'd love to see this functionality to be in the package or to go into the documentation.
This is great. Would be helpful to have this for sending motion or chunks to the REPL, as well.
I have this mapped to <M-e> like so:
keymaps = {
...
send_line = "<space>sl",
},
Then put somewhere:
vim.cmd [[nmap <M-e> <space>sl<CR>]]
In the same vein, is there a way to enter number of lines (say 3) and send those with a shortcut?
Perhaps a better way to do this would be to create <plug>(…)
mappings for all the binds. Then people could define their own surrounding behaviour much more flexibly
@mllg Thanks for this, it helps, but I am trying to expand to include visual mode but not quite working.
send_line()
works, but not visual_send()
- no response
Yep, I agree with @BlueDrink9 need for expansion of goodies.
vim.keymap.set('n', '<space><space>', function()
local iron = require("iron.core")
local last_line = vim.fn.line('$')
local pos = vim.api.nvim_win_get_cursor(0)
local curr_mode = vim.api.nvim_get_mode().mode
if curr_mode == 'n' then
iron.send_line()
vim.api.nvim_win_set_cursor(0, { math.min(pos[1] + 1, last_line), pos[2] })
elseif curr_mode == 'v' then
iron.visual_send()
end
end)