Vim9Script VLANG REPL

Vim9Script REPL

An easy method to achieve bidirectional communication between Python and Vim by using temporary text files. From https://github.com/mattn/vim_kernel

In [15]:
# import relevant modules
from subprocess import Popen,PIPE,STDOUT
from os import environ,remove
import json
import shutil
In [16]:
# The path to vim90 - Windows
vim_exe_path = "C:\\Users\\Seve\\Vim\\vim90\\vim.exe"
In [17]:
vim = Popen([vim_exe_path,                                                                             
             '-X',                                                                                    
             '-N',                                                                                     
             '-u',                                                                                     
             'NONE',                                                                                   
             '-i',                                                                                     
             'NONE',                                                                                   
             '-e',                                                                                     
             '-s',                                                                                     
             '-S',                                                                                     
             'kernel.vim'
            ], stdout=PIPE, stderr=STDOUT, shell=False, env=environ.copy())

Pass a vim9script to VIM (stdin)

In [18]:
with open(str(vim.pid)+".input", 'w', encoding='utf-8') as f:
    f.write("""
vim9script
def VimNew(): number
  var sum = 0
  for i in range(1, 29999)
      sum += i
  endfor
  return sum
enddef

var start = reltime()
echo VimNew()
echo 'Vim new: ' .. reltimestr(reltime(start))
    """)

Read stdout

In [19]:
with open(str(vim.pid)+".output", 'r', encoding='utf-8') as f:
        output = json.loads(f.read())
In [20]:
output
Out[20]:
{'stderr': '', 'stdout': '449985000\nVim new:   0.003460'}
In [21]:
remove(str(vim.pid)+".output")

VLANG REPL

Get Tailwind CSS

%%html

Set path for the V compiler

In [3]:
v_exe_path = "C:\\Users\\Seve\\workplace\\v\\v.exe"

AssertionError if the V compiler isn't installed

In [4]:
assert shutil.which(v_exe_path) is not None
In [14]:
v = Popen([v_exe_path,                                                                             
             'run',                                                                                 
             'kernel.v'
            ], stdout=PIPE, stderr=STDOUT, shell=False, env=environ.copy())

with open("1.v", 'w', encoding='utf-8') as f:
    f.write("""
// V snippet
mut nums := [1, 3, 5, 7]
println("List of integers $nums") // [1, 3, 5, 7]
    """)
In [10]:
%%javascript 
$.ajaxSetup({ cache: false })
function UpdateVdiv(){
$.getJSON("./1.output",
         function(data){
            var now = new Date().toString().split("GMT")[0];
            $('#content').html(data.stdout);
            $('#timeupdate').html('Last updated:'+ now);
            }         
         );
}

setInterval(UpdateVdiv, 1000);
VLANG

In [ ]:
with open("1.output", 'r', encoding='utf-8') as f:
        output = json.loads(f.read())
In [ ]:
output

Cell Folding Extension

In [ ]:
! pip install nbextension-cellfolding
! jupyter nbextension install --py cellfolding --user
In [ ]:
! jupyter nbextension enable --py cellfolding --user
In [ ]: