How to implement MATLAB-like cell mode in Vim -


in matlab, can write editor following

%% -- example cell --  plot(rand(3));  %% -- cell a=rand(2^10); t=linspace(-pi,pi,2^10); compass(fft(a*sin(t)) 

and can hit ctrl+enter run cell being clicked mouse pointer.

now know in vim, can

:'<,>'w !matlab run visually selected block of code.

but how implement matlab-like cell mode in vim/gvim?

for example python code

import os import subprocess import random  ## 1st cell ps =["python", "-h"] out = subprocess.popen(ps).communicate()[0] print out  ## 2nd cell  # import random -sould not needed if concatenate import section , cell print random.randint(1,100) 

can offer ideas?

not sure you're asking, if want process cell block upon double-clicking in block mouse, can map mouse-double-click (the <2-leftmouse> mapping) call function:

nnoremap <buffer> <2-leftmouse> :call processmousedoubleclick()<cr> 

processmousedoubleclick() function (1) visually selects "cell" area , (2) issues '<,>'w !matlab have matlab run selected code.

when calling processmousedoubleclick vim cursor located @ whatever point clicked in document. other that, there's nothing specific mouse. map key same function, e.g., mnemonic command 'evaluate cell':

map <buffer> <leader>ec :call processmousedoubleclick()<cr> 

so, there's not reason have function name referencing mouse @ all, might want call evaluatematlabcell().


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -