vim-repl icon indicating copy to clipboard operation
vim-repl copied to clipboard

support for neovim

Open tgzhou98 opened this issue 6 years ago • 25 comments

I'm not sure how much the work is. It just a feature request.

When I use <leader>r to open terminal program, neovim shows the following error.

image

tgzhou98 avatar Jul 08 '18 11:07 tgzhou98

I have to admit that currently, I cannot provide support for neovim because that I'm not a neovim user. I tried to install neovim and something went wrong with my vimrc.

sillybun avatar Jul 09 '18 14:07 sillybun

Looks like all the terminal related stuff works differently in vim and neovim. So it's probably a bit of a pain.

This quick & dirty hack could be a start:

diff --git a/autoload/repl.vim b/autoload/repl.vim
index 0c43602..a4a56b5 100644
--- a/autoload/repl.vim
+++ b/autoload/repl.vim
@@ -96,7 +96,7 @@ endfunction
 function! repl#REPLClose()
        if repl#REPLIsVisible()
         if index(split(repl#REPLGetName(), ' '), 'ipdb') != -1 || index(split(repl#REPLGetName(), ' '), 'pdb') != -1
-            call term_sendkeys('ZYTREPL', "\<C-W>\<C-C>")
+            call jobsend(g:term_job_id, "\<C-W>\<C-C>")
             call repl#Sends(['quit()'], ['ipdb>', 'pdb>'])
         else
             exe "call term_sendkeys('" . 'ZYTREPL' . ''', "\<C-W>\<C-C>")'
@@ -151,7 +151,9 @@ function! repl#REPLOpen(...)
                if exists('g:repl_height')
                        exe 'bo term ++close ++rows=' . float2nr(g:repl_height) . ' ' . repl#REPLGetName()
                else
-                       exe 'bo term ++close ' . repl#REPLGetName()
+                       exe 'bo vsplit | enew'
+      let g:term_job_id = termopen(repl#REPLGetName())
+                       exe 'startinsert'
                endif
        elseif g:repl_position == 1
                if exists('g:repl_height')
@@ -265,7 +267,7 @@ function! repl#REPLSaveCheckPoint() abort
         endif
         let l:checkid = repl#REPLGetCheckID(getline('.'))
         if repl#REPLIsVisible()
-            call term_sendkeys('ZYTREPL', '__import__("dill").dump_session("CHECKPOINT_' . l:checkid .  '.data")' . "\<Cr>")
+            call jobsend(g:term_job_id, '__import__("dill").dump_session("CHECKPOINT_' . l:checkid .  '.data")' . "\<Cr>")
             if matchstr(getline(line('.') + 1), '# \d\d\d\d-\d\d\?-\d\d?') !=# ''
                 call setline(line('.') + 1, '# ' . strftime('%Y-%m-%d'))
             else
@@ -282,7 +284,7 @@ function! repl#REPLLoadCheckPoint() abort
     endif
     let l:checkid = repl#REPLGetCheckID(getline('.'))
     if repl#REPLIsVisible()
-        call term_sendkeys('ZYTREPL', '__import__("dill").load_session("CHECKPOINT_' . l:checkid .  '.data")' . "\<Cr>")
+        call jobsend(g:term_job_id, '__import__("dill").load_session("CHECKPOINT_' . l:checkid .  '.data")' . "\<Cr>")
     endif
 endfunction

@@ -302,8 +304,7 @@ function! repl#SendCurrentLine() abort
                 return
             endif
         endif
-               exe "call term_sendkeys('" . 'ZYTREPL' . ''', getline(".") . "\<Cr>")'
-               exe "call term_wait('" . 'ZYTREPL' . ''',  50)'
+               call jobsend(g:term_job_id, getline(".") . "\<Cr>")
        endif
 endfunction

@@ -654,7 +655,7 @@ function! repl#Sends(tasks, symbols)
         let g:currentlinenumber = -1
         let g:currentrepltype = repl#REPLGetShortName()
         " echom len(g:tasks)
-        let g:term_send_task_codes = ['LABEL Start', 'wait repl#CheckInputState()', 'call term_sendkeys("ZYTREPL", g:tasks[g:taskprocess] . "\<Cr>")', 'let g:taskprocess = g:taskprocess + 1', 'if g:taskprocess == len(g:tasks)', 'return', 'endif', 'GOTO Start']
+        let g:term_send_task_codes = ['LABEL Start', 'wait repl#CheckInputState()', 'call jobsend(' . g:term_job_id . ', g:tasks[g:taskprocess] . "\<Cr>")', 'let g:taskprocess = g:taskprocess + 1', 'if g:taskprocess == len(g:tasks)', 'return', 'endif', 'GOTO Start']
         " let g:term_send_task_index = 0
         " call job_start("echo 'g:term_send_task'", {'close_cb': 'AsyncFuncRun'})
         call AsyncCodeRun(g:term_send_task_codes, "term_send_task")
@@ -711,10 +712,9 @@ function! repl#SendLines(first, last) abort
             endwhile
             for line in getline(l:firstline, a:last)
                 let l:deletespaceline = line[l:i:]
-                exe "call term_sendkeys('" . 'ZYTREPL' . ''', l:deletespaceline . "\<Cr>")'
-                exe 'call term_wait("ZYTREPL", 50)'
+                exe "call jobsend(" . g:term_job_id . ', l:deletespaceline . "\<Cr>")'
             endfor
-            exe "call term_sendkeys('" . 'ZYTREPL' . ''', "\<Cr>")'
+            exe "call jobsend(" . g:term_job_id . ', "\<Cr>")'
         endif
        endif
 endfunction
diff --git a/plugin/default.vim b/plugin/default.vim
index 8125af8..0a1725b 100644
--- a/plugin/default.vim
+++ b/plugin/default.vim
@@ -4,7 +4,7 @@ let g:REPLVIM_PATH = g:REPLVIM_PATH[:strridx(g:REPLVIM_PATH, "plugin") - 1]
 if !exists("g:repl_program")
        let g:repl_program = {
                                \       "python": "python",
-                               \       "default": "bash"
+                               \       "default": "python"
                                \       }
 endif

Very basic \w command working, a lot of things would still crash.

Not a neovim user myself... I was just curious :)

DavidEGx avatar Aug 01 '19 13:08 DavidEGx

On Windows the Neovim install seems to go fine. When I run :REPLToggle I get this:

'++close' is not recognized as an internal or external command, operable program or batch file. [Process exited 1]'

Would be really cool to have this in Neovim!

baogorek avatar Nov 14 '19 22:11 baogorek

+1 Really hoping to get this in Neovim!

huyiqun avatar Dec 17 '19 20:12 huyiqun

It would be great indeed. What about adding that Neovim is not supported at the beginning of the README?

Phantas0s avatar Apr 26 '20 08:04 Phantas0s

Guys you can try: https://github.com/hkupty/iron.nvim It's pretty good, but has its quirks. It is NOT refined as this is for multiple languages. So, it can't discern if you have an empty line with in a function. So, u have to stick a tab or something. Also, I am using sillybun's solution for gluepython3 development. And, I could not change the repl. If anyone makes iron.nvim work for AWS gluepython3 , then pls let me know by responding to: https://github.com/hkupty/iron.nvim/issues/157 Still, I am reasonably happy with just vim.

yelled1 avatar Jun 16 '20 03:06 yelled1

Good call, @yelled1, and while you're there, pick up hkupty/nvimux as well. It simulates tmux and gives you the ability to use CTRL-B O to jump between REPL and code. Here's my init.vim and plugins.lua.

baogorek avatar Jun 18 '20 12:06 baogorek

Good call, @yelled1, and while you're there, pick up hkupty/nvimux as well. It simulates tmux and gives you the ability to use CTRL-B O to jump between REPL and code. Here's my init.vim and plugins.lua.

Thank you will try.

yelled1 avatar Jun 18 '20 15:06 yelled1

Would've really appreciated neovim support. I'm also getting the ++close

drskoolie avatar Jun 25 '20 09:06 drskoolie

Another vote for neovim. Sorry I don't know enough to contribute.

ccaprani avatar Sep 08 '20 03:09 ccaprani

neovim vote

shkronjax avatar Oct 20 '20 07:10 shkronjax

who can help to tell me how to use neovim and vim simutaneously on macOS? I have never used neovim yet/

sillybun avatar Oct 21 '20 12:10 sillybun

who can help to tell me how to use neovim and vim simutaneously on macOS? I have never used neovim yet/

https://github.com/neovim/neovim/releases/ macOS Download nvim-macos.tar.gz Extract: tar xzvf nvim-macos.tar.gz Run ./nvim-osx64/bin/nvim neovim has its own vimrc file...on Ubuntu its under ~/.config/nvim/init.vim...probably same location on macOS as well(create file if not there after install). You just copy paste your configuration from your vimrc to init.vim or make a symlink. I keep neovims configs separate. On vim I use Conquer of Completion for IDE like features and on nvim LSP protocol and language servers. I suggest u keep vimrc and ~/.config/nvim/init.vim separate.

another option seems to be brew install neovim I hang out at engineermans discord often(google search it and join discord). If u want to keep chatting about vim. Also love your plugin on vim works very nicely.

shkronjax avatar Oct 21 '20 13:10 shkronjax

Any updates? My error message reads:

Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen

E117: Unknown function: term_sendkeys

ECon87 avatar Dec 12 '20 16:12 ECon87

Any updates? My error message reads:

Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen

E117: Unknown function: term_sendkeys

Actually, if ur dying to use it on neovim, then coc-python will work now. You just do need to remap the keys to Sillybun's. I use both.

yelled1 avatar Dec 12 '20 21:12 yelled1

Any updates? My error message reads: Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen E117: Unknown function: term_sendkeys

Actually, if ur dying to use it on neovim, then coc-python will work now. You just do need to remap the keys to Sillybun's. I use both.

Thank you. I tried devising my own function but it took forever. coc-python works.

Can you choose the placement of the terminal?

ECon87 avatar Dec 12 '20 21:12 ECon87

Have not tried. GitHub - hkupty/iron.nvim: Interactive Repl Over Neovim is pretty good & let u choose the terminal position, but not as mature as vim-repl. You will hit some prb. Also, https://github.com/kassio/neoterm is another option.

On Sat, Dec 12, 2020 at 4:22 PM Evangelos Constantinou < [email protected]> wrote:

Any updates? My error message reads: Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen E117: Unknown function: term_sendkeys

Actually, if ur dying to use it on neovim, then coc-python https://github.com/neoclide/coc-pythonwill work now. You just do need to remap the keys to Sillybun's. I use both.

Thank you. I tried devising my own function but it took forever. coc-python works.

Can you choose the placement of the terminal?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sillybun/vim-repl/issues/3#issuecomment-743889375, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVXWP7K33MC5CJA7URLSUPNLFANCNFSM4FI2X6NA .

yelled1 avatar Dec 13 '20 07:12 yelled1

Have not tried. GitHub - hkupty/iron.nvim: Interactive Repl Over Neovim is pretty good & let u choose the terminal position, but not as mature as vim-repl. You will hit some prb. Also, https://github.com/kassio/neoterm is another option. On Sat, Dec 12, 2020 at 4:22 PM Evangelos Constantinou < @.***> wrote: Any updates? My error message reads: Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen E117: Unknown function: term_sendkeys Actually, if ur dying to use it on neovim, then coc-python https://github.com/neoclide/coc-pythonwill work now. You just do need to remap the keys to Sillybun's. I use both. Thank you. I tried devising my own function but it took forever. coc-python works. Can you choose the placement of the terminal? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVXWP7K33MC5CJA7URLSUPNLFANCNFSM4FI2X6NA .

Thanks. I figured it out with coc-python (well kind of) for any one who is interested. After sending your selection to the terminal, the position can be re-adjusted with the usual window adjustment keybindings (i.e., ctrl-w-H).

One drawback of using coc-python relative to vim-repl is that the latter automatically moves to the end of the selection after the code is sent.

ECon87 avatar Dec 13 '20 17:12 ECon87

Just use below with caveat that u might want to change ** to something that you would use & You will not be able to use "mY" & you might want to change to something else. When not available then hack'em => why we use (neo)vim.

autocmd FileType python nnoremap l :CocCommand python.upgradePythonLanguageServer<Cr> autocmd FileType python nnoremap r :CocCommand python.startREPL<CR> autocmd FileType python vmap ** mY:CocCommand python.execSelectionInTerminal<Cr>'Yj autocmd Filetype python imap *\ *<Esc>0v$:CocCommand python.execSelectionInTerminal<Cr>j autocmd Filetype python nmap ** 0v$:CocCommand python.execSelectionInTerminal<Cr>j

On Sun, Dec 13, 2020 at 12:18 PM Evangelos Constantinou < [email protected]> wrote:

Have not tried. GitHub - hkupty/iron.nvim: Interactive Repl Over Neovim is pretty good & let u choose the terminal position, but not as mature as vim-repl. You will hit some prb. Also, https://github.com/kassio/neoterm is another option. … <#m_3697932679282546535_> On Sat, Dec 12, 2020 at 4:22 PM Evangelos Constantinou < @.***> wrote: Any updates? My error message reads: Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen E117: Unknown function: term_sendkeys Actually, if ur dying to use it on neovim, then coc-python https://github.com/neoclide/coc-pythonwill work now. You just do need to remap the keys to Sillybun's. I use both. Thank you. I tried devising my own function but it took forever. coc-python works. Can you choose the placement of the terminal? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3 (comment) https://github.com/sillybun/vim-repl/issues/3#issuecomment-743889375>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVXWP7K33MC5CJA7URLSUPNLFANCNFSM4FI2X6NA .

Thanks. I figured it out with coc-python (well kind of) for any one who is interested. After sending your selection to the terminal, the position can be re-adjusted with the usual window adjustment keybindings (i.e., ctrl-w-H).

One drawback of using coc-python relative to vim-repl is that the latter automatically moves to the end of the selection after the code is sent.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sillybun/vim-repl/issues/3#issuecomment-744039139, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVVZOHPWT77QIBEFI5DSUTZPTANCNFSM4FI2X6NA .

yelled1 avatar Dec 13 '20 19:12 yelled1

Just use below with caveat that u might want to change ** to something that you would use & You will not be able to use "mY" & you might want to change to something else. When not available then hack'em => why we use (neo)vim. autocmd FileType python nnoremap l :CocCommand python.upgradePythonLanguageServer<Cr> autocmd FileType python nnoremap r :CocCommand python.startREPL<CR> autocmd FileType python vmap ** mY:CocCommand python.execSelectionInTerminal<Cr>'Yj autocmd Filetype python imap \ <Esc>0v$:CocCommand python.execSelectionInTerminal<Cr>j autocmd Filetype python nmap * 0v$:CocCommand python.execSelectionInTerminal<Cr>j On Sun, Dec 13, 2020 at 12:18 PM Evangelos Constantinou < [email protected]> wrote: Have not tried. GitHub - hkupty/iron.nvim: Interactive Repl Over Neovim is pretty good & let u choose the terminal position, but not as mature as vim-repl. You will hit some prb. Also, https://github.com/kassio/neoterm is another option. … <#m_3697932679282546535_> On Sat, Dec 12, 2020 at 4:22 PM Evangelos Constantinou < @.> wrote: Any updates? My error message reads: Error detected while processing function repl#REPLToggle[10]..repl#REPLOpen E117: Unknown function: term_sendkeys Actually, if ur dying to use it on neovim, then coc-python https://github.com/neoclide/coc-pythonwill work now. You just do need to remap the keys to Sillybun's. I use both. Thank you. I tried devising my own function but it took forever. coc-python works. Can you choose the placement of the terminal? — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3 (comment) <#3 (comment)>>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVXWP7K33MC5CJA7URLSUPNLFANCNFSM4FI2X6NA . Thanks. I figured it out with coc-python (well kind of) for any one who is interested. After sending your selection to the terminal, the position can be re-adjusted with the usual window adjustment keybindings (i.e., ctrl-w-H). One drawback of using coc-python relative to vim-repl is that the latter automatically moves to the end of the selection after the code is sent. — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARVDVVZOHPWT77QIBEFI5DSUTZPTANCNFSM4FI2X6NA .

Thank you

ECon87 avatar Dec 16 '20 15:12 ECon87

Ur welcome & @ECon87 You might want to close this issue.

yelled1 avatar Dec 16 '20 17:12 yelled1

It's not my issue. I don't think I can close it

ECon87 avatar Dec 16 '20 18:12 ECon87

neovim vote! Really love this plugin!

EPC204 avatar Mar 14 '21 14:03 EPC204

This plugin looks awesome, so I've started working on adding neovim support over on my fork . @DavidEGx’s code was a good starting point :+1: Opening a REPL and sending (pytho) code to it already works, but there still are some things to be done. I'll create a PR if @sillybun is interested in including the feature.

On a side note: I only found out about the missing neovim support after getting the errors described in this issue, a small note in the README would be nice untile neovim support is available :) .

I’m pretty bad at vimscript, though ^^

lrittel avatar Jan 21 '22 05:01 lrittel

@rittelle that will be awesome

sillybun avatar Jan 24 '22 07:01 sillybun