iron.nvim icon indicating copy to clipboard operation
iron.nvim copied to clipboard

Feature Request: Send line and move cursor down

Open mllg opened this issue 2 years ago • 7 comments

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.

mllg avatar Jul 25 '22 13:07 mllg

This is great. Would be helpful to have this for sending motion or chunks to the REPL, as well.

guymorlan avatar Jul 27 '22 11:07 guymorlan

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>]]

drusmanbashir avatar Jul 27 '22 15:07 drusmanbashir

In the same vein, is there a way to enter number of lines (say 3) and send those with a shortcut?

drusmanbashir avatar Jul 27 '22 15:07 drusmanbashir

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

BlueDrink9 avatar Dec 06 '22 20:12 BlueDrink9

@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)

yelled1 avatar Aug 21 '23 21:08 yelled1