iron.nvim
iron.nvim copied to clipboard
Unable to send a cell to repl
Hi, Thanks for this awesome plugin and I am really enjoying it.
Current I am able to send code to the repl via motion command(j,k, etc) which is very convenient.
It will be nice if I can send a cell to repl and jump to the next automatically. I searched around and found that these plugins which seems good for me but failed to make it.
jupytext.vim
iron.nvim
vim-textobj-hydrogen
I am able to jump between cells using the shortcuts defined in vim-textobj-hydrogen .

The problem is that I am not able to send the cell to repl with shortcuts defined in the below config:
I am using nvim stable 0.8.3 and all the latest plugins by today(2023/4/17). Appreciate your feedback on if it is a configuration issue or how I can debug it.
I just test the setting and it works fine. Maybe can need to figure out what is your problem. The textobj and the ]x command just works fine. I guess you may miss the lua config of iron.nvim, you need use that config instead of the default config. Or you can change the mapping of ]x.
Hi Meicale, Thanks for your feedback. I tried changing the mapping and it didn't help and this is my iron config, anything am I missing?
local iron = require("iron.core")
vim.g.mapleader = ";"
iron.setup {
config = {
-- Whether a repl should be discarded or not
scratch_repl = true,
-- Your repl definitions come here
repl_definition = {
sh = {
-- Can be a table or a function that
-- returns a table (see below)
command = {"bash"}
}
},
-- How the repl window will be displayed
-- See below for more information
repl_open_cmd = require("iron.view").split.vertical(100)
},
-- Iron doesn't set keymaps by default anymore.
-- You can set them here or manually add keymaps to the functions in iron.core
keymaps = {
send_motion = "<leader>j",
visual_send = "<leader>v",
send_file = "<leader>f",
send_line = "<leader>l",
send_mark = "<leader>k",
mark_motion = "<leader>mc",
mark_visual = "<leader>mc",
remove_mark = "<leader>md",
cr = "<leader>s<cr>",
-- interrupt = "<leader>s<leader>",
-- exit = "<leader>q",
-- clear = "<leader>c",
},
-- If the highlight is on, you can change how it looks
-- For the available options, check nvim_set_hl
highlight = {
italic = true
},
ignore_blank_lines = true, -- ignore blank lines when sending visual select lines
}
-- iron also has a list of commands, see :h iron-commands for all available commands
vim.keymap.set('n', '<leader>T', '<cmd>IronRepl<cr>')
vim.keymap.set('n', '<leader>R', '<cmd>IronRestart<cr>')
vim.keymap.set('n', '<leader>F', '<cmd>IronFocus<cr>')
vim.keymap.set('n', '<leader>H', '<cmd>IronHide<cr>')
vim.g.mapleader = "\\"
Hi Meicale, Thanks for your feedback. I tried changing the mapping and it didn't help and this is my iron config, anything am I missing?
local iron = require("iron.core") vim.g.mapleader = ";" iron.setup { config = { -- Whether a repl should be discarded or not scratch_repl = true, -- Your repl definitions come here repl_definition = { sh = { -- Can be a table or a function that -- returns a table (see below)
command = {"bash"}
} },
I think you use this to run python code, so that you need using command = {"ipython"} and install ipython in your machine. I recommend that you just double check the blog related to your config.
I implemented my own function to send code chunk to REPL and it works fine.
https://github.com/milanglacier/nvim/blob/b9214c06907cd573bf9d85267116907fb9dbc1e2/lua/conf/langs.lua#L20
@weiyshay use it
(inner tag) for me as a workaround. maybe help you.
:help text-objects
*v_at* *at*
at "a tag block", select [count] tag blocks, from the
[count]'th unmatched "<aaa>" backwards to the matching
"</aaa>", including the "<aaa>" and "</aaa>".
See |tag-blocks| about the details.
When used in Visual mode it is made charwise.
*v_it* *it*
it "inner tag block", select [count] tag blocks, from the
[count]'th unmatched "<aaa>" backwards to the matching
"</aaa>", excluding the "<aaa>" and "</aaa>".
See |tag-blocks| about the details.
When used in Visual mode it is made charwise.
Tag blocks *tag-blocks*
For the "it" and "at" text objects an attempt is done to select blocks between
matching tags for HTML and XML. But since these are not completely compatible
there are a few restrictions.
The normal method is to select a <tag> until the matching </tag>. For "at"
the tags are included, for "it" they are excluded. But when "it" is repeated
the tags will be included (otherwise nothing would change). Also, "it" used
on a tag block with no contents will select the leading tag.
you can remap : vim.cmd [[nmap st sit]]
e.g.:
# <cell>
a = 10
b = 20
c = 30
# </cell>
My take using vimscript to achieve something similar. I mapped <CR> in visual mode to send code and move down. and \\
will select and send the code block
let g:CodeFence = "###"
function! IsLineIndented()
let lineContent = getline('.')
if match(lineContent, ' ') == 0
return 1
else
return 0
endif
endfunction
function! IsFence()
return getline('.') == g:CodeFence
endfunction!
function! BuildFence()
exe "normal Go".g:CodeFence
if IsLineIndented()
normal 0dt#
endif
endfunction
function! OpenCell() abort
let cmd = 'normal *kV``jo'
execute cmd
endfunction
function! CloseCell() abort
let cmd = 'normal #jV``'
execute cmd
normal -
endfunction
" nnoremap <leader>cc :call CloseCell()<cr>
function! BetweenCell() abort
let Start = line(".")
let End = search('^'.g:CodeFence, 'Wbs')
normal +
if Start - End == 1
normal V
else
normal V''
endif
endfunction
function! SelectVisual() abort
if search('^'.g:CodeFence, 'W') == 0
call BuildFence()
call CloseCell()
else
normal -
call BetweenCell()
endif
endfunction
nmap \\ :call SelectVisual()<cr><cr>
keymap in lua
vim.keymap.set("v", "<CR>", function()
iron.visual_send()
vim.cmd("norm! j")
end, { buffer = args.buf, desc = "repl_v_send" })