English 中文(简体)
• 如何从Vim内部效仿Matlab的指挥(F5)?
原标题:How to emulate Matlab’s Run command (F5) from within Vim?

作为马特拉布特的一个外部编辑,我使用的是Libert和gVim。

在Matlab编辑中,你可以使用F5。 我试图在Vim复制这一产品(从gvim-gtk Debian书包封)。

我知道,有可能将姓名或现有档案或选定案文按“星号”方式送交马特拉布:

execute  !echo "  ."run( ".expand("%:p")." )" .  "| matlab -nojvm  
execute  !matlab -nodisplay <  .expand("%:p") 
noremap <C-CR> :?%%?;/%%/w !matlab -nojvm

但我想利用Matlab GUI(我已经开过)。

这里,我认为我可以找到解决办法:

  1. a. 动向使用关键地图,以便:

    • (a) Put in the clipboard something like: run( path-to-file ) or cd( folder );run( filename ).
    • (b) Call a shell command that gives the focus to the Matlab GUI
  2. 此时此刻,我应设在马特拉布指挥窗口,因此,我仅新闻Ctrl-,应当保持剪辑的内容。 (尽管我关于六氯环己烷的过夜,我还是使用“Matlab”与“Windows”关键约束器。)

Step 1(a): The following will put the run( filename ) command to the clipboard, and Matlab will paste it when Ctrl-V is pressed:

let @+="run( ".expand("%:p")." )" 

下面两个指挥部将与欧伦特中纽顿的过去合作,但这不是我所希望的,因为我想避免这一步骤的用意:

let @*="run( ".expand("%:p")." )" 

execute  !echo "  . "run( ".expand("%:p")." )" .  "| xclip   

<>Step 1(b): 为了注重马特拉布窗口,我使用了以下指挥系统:

wmctrl -a MATLAB &

This works well, but it might also raise a browser window, if it happens to have a page open with the word Matlab in its title (like the one you are reading at the moment).

另见更为复杂的解决办法:。 是否有一条中子指令来确定与某一特定过程有关的窗户识别?

My (now old) option, but Ctrl-V does not work! Only mouse pasting does:

function! MatRun()
    let @+="run( ".expand("%:p")." )" 
    let @*="run( ".expand("%:p")." )" 
    :call system( xclip , @+)
    !wmctrl -a MAT
endfunction

map <F5> :call MatRun() <cr><cr>

Somehow, Ctrl- 如果与<代码>wmctrl<>/code>合并,则不适用(见以下表格)。 对我来说,整个要点是避免为这一行动使用 mo。

Thank you for your help.

Update: a working option

我的坏处正在使用<代码>xclip。 如果我已经使用<代码>xclip -selection c。 见下文。

如果有人找到更好的解决办法,例如:在马特拉布指挥窗口直接开车,确保你掌握指挥窗口(,-0),或避免将浏览器窗户带上wmctrl

最佳回答

EDIT: See plugin made from it: https://github.com/elmanuelito/vim-matlab-behave

Sorry for replying to my own question. It s my bad, I was using xclip where I should have used xclip -selection c . I put below the different codes that work out for me: it reproduces the F5 and the evaluate cell behavior but you have to press Ctrl-V or use the mouse to paste in Matlab Command Window. If you are not on the command window, use matlab shortcut Ctrl-0 to jump to it. The script automatically goes from vim to matlab(unless you have another window with the name "matlab" in it). I added marks to go back to the former cursor position afterwards.

www.un.org/spanish/ecosoc 操作整个文字材料: 这是“Run/F5”行为(指右编和执行整个文字):

function! MatRun()
   normal mm " mark current cursor in mark m"
   let @+="cd( ".expand("%:p:h")." ); run( ./".expand("%:f"). " )"
   call system( xclip -selection c  , @+)
   call system( xclip  , @+)
   normal `m "go back to cursor location"
   !wmctrl -a MATLAB 
endfunction
map ,m :call MatRun() <cr><cr>

www.un.org/spanish/ecosoc 仅管理: 这是Ctrl+Enter行为。 (edit): 我现在予以延长,以便从档案的开始(/%^)的头上调,到档案的结束($$)的头下调%(end edit)

function! MatRunCell()
    normal mm "remember cursor"
    :?%%|\%^?;/%%|\%$/w !xclip -selection c  "pipe the cell to xclip"
    normal `m "go back to cursor location"
    !wmctrl -a MATLAB  "go to matlab window"
endfunction
map ,k :call MatRunCell()  <cr><cr>

But I like better the following one, though more complicated (and could certainly be made vim-only). The following, ensures you are in the right directory to run the cell, and also goes back to Vim after evaluating the cell (if you have correctly configured the external editor in matlab. I use:gvim --servername MAT --remote-tab-silent).

 function! MatRunCellAdvanced()
     execute "!echo "cd( ".expand("%:p:h")." )">/tmp/buff"  
     normal mm
     :?%%|\%^?;/%%|\%$/w>> /tmp/buff
     execute "!echo "edit ".expand("%:f")."">>/tmp/buff"
     !cat /tmp/buff|xclip -selection c
     !cat /tmp/buff|xclip
     normal `m
     !wmctrl -a MATLAB 
 endfunction
map ,n :call MatRunCellAdvanced()  <cr><cr>

Run current line : Copy current line to clipboard and go to matlab window. (once again Control+V to paste it in matlab, if it s the short-cut you use in matlab)

 function! MatRunLine()
     " write current line and pipe to xclip "
     :.w !xclip -selection c
     !wmctrl -a MATLAB 
 endfunction
 map ,l :call MatRunLine()  <cr><cr>

www.un.org/spanish/ecosoc 长期甄选: 颁布F9行为。

  function! MatRunSelect()
     normal mm
     !rm -f /tmp/buff
     :redir > /tmp/buff
     :echo @*
     :redir END
     execute "!echo " ">>/tmp/buff"
     execute "!echo "edit ".expand("%:p")."">>/tmp/buff"
     !cat /tmp/buff|xclip -selection c
      normal `m
     !wmctrl -a MATLAB 
  endfunction

Bold Cell title Bold font in the cell title

 highlight MATCELL cterm=bold term=bold gui=bold
 match MATCELL /%%.*$/

Where to put those commands All of these commands in .vim/after/ftplugin/matlab.vim

edit Instead of using:

 run( ./".expand("%:f")." )"

我现在发言。

run( ".expand("%:p")." )"

处理体积与文字目录不同的情况。 我没有找到办法仅仅抽取文字名称,因此我完全走。 有些人也许会找到更恶毒的解决办法。

问题回答

对于那些刚刚希望能够从肉体上操作肉体,不需要其他胎面的心灵,你可以尝试使用肉体的指挥线。

www.un.org/spanish/ga matlab -nosplash -nodesktop -r %:r将开始使用新的材料,并将现有文件作为文字(或功能没有参数)与商品登记总局的F5相似。 你们将需要进行撤离,以摆脱婚礼,随后又返回。 当然,只有当你想要掌握的档案处于马塔布路或终点站的工作名录时,才会这样做。

这可能是不方便的,因为新书状的启动时间已到,因此,书本的操作时间可能为时段。 你可以尝试使用<代码>-nojvm,以避免java造成的间接费用,但我认为最佳解决办法是使肉类弹壳保持开放。

You can do this with a Vim Plugin called Conque-Shell.
Once installed you can start the matlab shell with :ConqueTerm matlab -nodesktop and you will get a buffer that you can use like the matlab console. Executing code parts will work just fine with yank and paste. Or you could create vim functions that do this for you. Since I m not very good at this I can only provide this ugly mapping here:

:nmap <f5> :let @"=expand( %:r )<cr>:buffer matlab -nodesktop<tab><cr>”p<cr>

我在Windows上使用Autohotkey(我也用该 Esc钥匙)。 可以在没有行政权的情况下安装自动取款机,对公司机器有用。

采用下文所述安排:

  • In gvim, pressing CTRL-L in normal mode will evaluate the current line in Matlab (then return to gvim).
  • In visual mode, it will evaluate the current selection in Matlab (and also return to Vim).

可以通过绘制CTRL-E的地图,实现单元模式(见下文)。 (“自动钥匙”文字将在马特拉布实施,无论由CTRL-E在格维姆进行测绘。) 之后,你可以同时或在不同屏幕上建立马特拉布特和维恩,这为工作提供了重要途径。

在我的自动热点档案中,我使用了这一地图:

^l::
; execute line or current selection in Matlab
    IfWinActive, ahk_class Vim
    {
        ; CTRL-E is mapped to a Vim shortcut to yank the text you want
        Send, ^e
        WinActivate, ahk_class SunAwtFrame  
        Send, ^0^v{Enter}
        WinActivate, ahk_class ahk_class Vim
    } else if WinActive, ahk_class SunAwtFrame  
    {
        Send, ^0^v{Enter}
    } 
Return 

接着,我用以下简称:

:nnoremap ^E Y
:vnoremap ^R y

注: 欧洲复兴开发银行是一个字面上的CTRL-E,通过下列网址进入正文:CTRL-VCTRL-Q

注2:SunAwtFrame 是“Windows”在我的机器上把Matlab窗户称作“。 你可以使用Windowspy(与Autohotkey捆绑在一起)来确认,这在你的机器上是一样的。





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签