在 MATLAB 中,我们可以向编辑器写入以下内容
%% -- a example cell --
plot(rand(3));
%% -- another cell
A=rand(2^10);
t=linspace(-pi,pi,2^10);
compass(fft(A*sin(t))
and we can just hit Ctrl+Enter to run the cell being clicked by the mouse pointer.
现在我知道在 Vim 中我可以做到
:'<,>'w !matlab
运行可视化选择的代码块。
但是如何在 Vim/gVim 中实现类似 MATLAB 的单元格模式呢?
例如一些Python代码
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 be needed if we concatenate the import section and the cell
print random.randint(1,100)
有人可以提供一些想法吗?
不确定您到底在问什么,但如果您想要的是在用鼠标双击块时处理单元格块,那么您可以映射鼠标双击(<2-LeftMouse>
映射)来调用函数:
nnoremap <buffer> <2-LeftMouse> :call ProcessMouseDoubleClick()<CR>
ProcessMouseDoubleClick() 是一个函数,它 (1) 直观地选择“单元格”区域以及 (2) 问题'<,>'w !matlab
让 matlab 运行选定的代码。
当调用 ProcessMouseDoubleClick 时,Vim 光标将位于您在文档中单击的任何位置。除此之外,鼠标没有什么特别的。因此,您还可以将任何键映射到相同的功能,例如“评估单元格”的助记符命令:
map <buffer> <Leader>ec :call ProcessMouseDoubleClick()<CR>
因此,实际上没有任何理由让函数名称引用鼠标,您可能想将其称为类似的名称EvaluateMatlabCell()
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)