Skip to content

Instantly share code, notes, and snippets.

@mattn
Created December 19, 2018 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattn/00236f847e6af5a8be2dc785142c957c to your computer and use it in GitHub Desktop.
Save mattn/00236f847e6af5a8be2dc785142c957c to your computer and use it in GitHub Desktop.
{
"argv": [
"python",
"c:/Users/mattn/AppData/Roaming/jupyter/kernels/vimkernel/vimkernel.py",
"-f",
"{connection_file}"
],
"display_name": "Vim"
}
from ipykernel.kernelbase import Kernel
from subprocess import Popen, STDOUT, PIPE
class Vim(Kernel):
implementation = 'Vim'
implementation_version = '0.1'
language = 'no-op'
language_version = '0.1'
language_info = {'name': 'Vim', 'mimetype': 'text/plain'}
banner = 'Vim script'
_d = {}
def do_execute(self, code, silent, store_history=True,
user_expressions=None, allow_stdin=False):
with open('prog.vim', 'w') as f:
f.write("\n".join(code.splitlines()))
p = Popen(['vim', '-X', '-N', '-u', 'NONE', '-i', 'NONE', '-V1', '-e', '-s', '-S', 'prog.vim', '+qall!'], stdout=PIPE, stderr=STDOUT, shell=True)
p.wait()
exitcode = p.returncode
output = p.communicate()[0].decode()
self.send_response(self.iopub_socket, 'stream', {'name': 'stdout', 'text': output})
return {'status': 'ok',
'execution_count': self.execution_count,
'payload': [],
'user_expressions': {},
}
if __name__ == '__main__':
from ipykernel.kernelapp import IPKernelApp
IPKernelApp.launch_instance(kernel_class=Vim)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment