Vim and matlab GUI - Emulate matlab Run () with Vim

后端 未结 3 1053
长情又很酷
长情又很酷 2020-12-23 18:17

I\'m using linux and gvim/vim as external editor for matlab.

Using matlab editor you can run a file by pressing F5. I\'m trying to reproduce this with gvim-gtk(offic

3条回答
  •  一个人的身影
    2020-12-23 18:25

    I do this on Windows using Autohotkey (which I also use to swap the Esc and Caps Lock keys). Autohotkey can be installed without admin rights, useful on corporate machines.

    Using the set up described below:

    • 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).

    Cell mode could be achieved through a slightly different mapping for CTRL-E (see below). (The Autohotkey script will execute in Matlab whatever is put into the clipboard by the CTRL-E mapping in gvim.) You can then set up Matlab and gvim side by side or on different screens, and it's a great way to work.

    In my Autohotkey file, I use this mapping:

    ^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 
    

    Then, in vim I use the following shortcut:

    :nnoremap ^E Y
    :vnoremap ^R y
    

    Note: ^E is a a literal CTRL-E entered in vim by pressing CTRL-V CTRL-E or CTRL-Q CTRL-E.

    Note 2: SunAwtFrame is what Windows calls the Matlab window on my machine. You can use Windowspy (which comes bundled with Autohotkey) to confirm that it is called the same on your machine.

提交回复
热议问题