Wikia

Vim Tips Wiki

Changes: Run matlab script

Edit

Back to page

(Comments)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
I added the following to my .vimrc to be able to run the matlab script under edition usign a single <F5> stroke (with shift-F6 you run Matlab in a terminal):
+
{{TipProposed
  +
|id=0
  +
|previous=0
  +
|next=0
  +
|created=July 30, 2012
  +
|complexity=basic
  +
|author=
  +
|version=7.0
  +
|subpage=/201207
  +
|category1=Matlab
  +
|category2=
  +
}}
  +
I added the following to my [[vimrc]] to be able to run a Matlab script by pressing F5 (with Shift-F6 you run Matlab in a terminal):
   
 
<pre>
 
<pre>
 
" The matlab Connection
 
" The matlab Connection
  +
nnoremap <F5> :call MatlabRun()<CR><CR>
  +
nnoremap <S-F6> :call RunMatlab()<CR><CR>
   
map <F5> :call MatlabRun()<CR><CR>
+
function! MatlabRun()
map <S-F6> :call RunMatlab()<CR><CR>
+
execute "w"
  +
execute "!matlab-ctrl.py \"". expand("%:r") . "\""
  +
endfunction
   
func! MatlabRun()
+
function! RunMatlab()
exec "w"
+
execute "w"
exec "!matlab-ctrl.py \"". expand("%:r") . "\""
 
endfunc
 
 
func! RunMatlab()
 
exec "w"
 
 
call system("matlab-launch.sh \"" . expand("%:r") . "\"")
 
call system("matlab-launch.sh \"" . expand("%:r") . "\"")
endfunc
+
endfunction
 
</pre>
 
</pre>
   
Line 19: Line 21:
 
#!/usr/bin/python2
 
#!/usr/bin/python2
   
from subprocess import call
+
from subprocess import call
from subprocess import check_output
+
from subprocess import check_output
 
import sys
 
import sys
   
Line 49: Line 51:
 
exit 0
 
exit 0
 
</pre>
 
</pre>
[[Category:Matlab]]
+
  +
==Comments==
  +
- tmux + Slimux is an alternative --[[User:Memming|Memming]] ([[User talk:Memming|talk]]) 14:03, February 12, 2014 (UTC)

Latest revision as of 14:03, February 12, 2014

Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).

Please use new tips to discuss whether this page should be a permanent tip, or whether it should be merged to an existing tip.
created July 30, 2012 · complexity basic · version 7.0

I added the following to my vimrc to be able to run a Matlab script by pressing F5 (with Shift-F6 you run Matlab in a terminal):

" The matlab Connection
nnoremap <F5> :call MatlabRun()<CR><CR>
nnoremap <S-F6> :call RunMatlab()<CR><CR>

function! MatlabRun()
  execute "w"
  execute "!matlab-ctrl.py \"". expand("%:r") . "\""
endfunction

function! RunMatlab()
  execute "w"
  call system("matlab-launch.sh \"" . expand("%:r") . "\"")
endfunction

I have the following scripts in my $PATH:

matlab-ctrl.py

#!/usr/bin/python2

from subprocess import call
from subprocess import check_output
import sys

wcmd = ["xdotool","search","--name","MatlabT"]
w = check_output(wcmd)
w = w.replace('\n','')

if len(sys.argv) > 1:
  s = sys.argv[1]

cmd = ["xdotool","key","--window",w]

for i in range(len(s)):
  cmd.append(s[i])

cmd.append("Return")

call(cmd)

matlab-launch.sh

#!/bin/bash
texfile="$1"
terminal -e "/opt/MATLAB/R2011a/bin/matlab -r clc -nosplash -nodesktop" -T MatlabT --hide-menubar &> /dev/null &
# try to return focus to GVIM
xdotool search --class --name "${texfile}.*GVIM" windowactivate &>/dev/null
exit 0

CommentsEdit

- tmux + Slimux is an alternative --Memming (talk) 14:03, February 12, 2014 (UTC)

Around Wikia's network

Random Wiki