Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Last active May 29, 2021 00:05
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chemzqm/e22ddf489ec24c7d21bbcb047f4b3f86 to your computer and use it in GitHub Desktop.
Save chemzqm/e22ddf489ec24c7d21bbcb047f4b3f86 to your computer and use it in GitHub Desktop.
repl with coc.nvim
// Save the file to ~/.vim/coc-extensions
// Usage: xmap <silent> <TAB> <Plug>(coc-repl-sendtext)
const {commands, workspace} = require('coc.nvim')
exports.activate = context => {
let {nvim} = workspace
let terminal
context.subscriptions.push(commands.registerCommand('repl.openTerminal', async () => {
let filetype = await nvim.eval('&filetype')
let prog = ''
if (filetype == 'javascript') {
prog = 'node'
} else if (filetype == 'typescript') {
prog = 'ts-node'
} else if (filetype == 'python') {
prog = 'python'
}
terminal = await workspace.createTerminal({
name: prog || 'terminal'
})
if (prog) {
terminal.sendText(prog, true)
}
}))
context.subscriptions.push(commands.registerCommand('repl.showTerminal', async () => {
if (terminal) {
terminal.show()
}
}))
context.subscriptions.push(commands.registerCommand('repl.disposeTerminal', async () => {
if (terminal) {
terminal.dispose()
}
}))
context.subscriptions.push(workspace.registerKeymap(['x'], 'repl-sendtext', async () => {
await nvim.call('eval', 'feedkeys("\\<esc>", "in")')
let doc = workspace.getDocument(workspace.bufnr)
if (!doc) return
let visualmode = await nvim.call('visualmode')
let range = await workspace.getSelectedRange(visualmode, doc)
if (!range) return
let text = doc.textDocument.getText(range)
if (text && terminal) terminal.sendText(text, true)
}, {sync: false, silent: true}))
}
@shy00n
Copy link

shy00n commented Nov 27, 2020

After issuing
:CocCommand repl.openTerminal
vim freezes, get control back when I hit Ctrl-c.
VIM - Vi IMproved version 8.2.1897
(ubuntu wsl2)
Linux DESKTOP-8D 4.19.128-microsoft-standard #1 SMP Tue Jun 23 12:58:10 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

I also get when attempt to edit the file.

Error detected while processing BufReadPost Autocommands for "*.js":
E20: Mark not set

Theses r only settting on my init.vim for `/.js'

au BufNewFile,BufRead *.js, *.html, *.css, *.scala, *.jl
    \ set tabstop=2 |
    \ set softtabstop=2 |
    \ set shiftwidth=2

Thank you,

@chemzqm
Copy link
Author

chemzqm commented Nov 28, 2020

No idea, the log is not complete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment