I'm now a R user and very comfortable in using Vim-R-plugin where you can use many shortcuts to send R scripts edited in vim window to the R executive window. Recently I started to learn Python and would setup a similar environment. It turns out that everything I found online is for a professional-like Python user, too complicate and time-cost for a beginner like me. What I want is very simple. Such like, I have two windows: edit my python script on vim window(macvim) and another executive window, either terminal or IDLE. My question is how I can set up them smoothly like the R-VIM system rather than copy and paste.
1 Answers
You can use ConqueTerm to open both vim and Python (or iPython, or IDLE) within one vim session. Then you can remap a key to send vim code to the interpreter.
Here's a solution I tried. Stick this in your vimrc
file: vmap <silent> <leader>m "*y<C-w><C-w>p
I had mapped comma as the leader key, so it executed when I entered "comma-m". It worked in Linux but not on Windows for some reason. Here's a SO question I asked about it.
EDIT:
Here's a similar idea, using AutoHotKey to send code from vim to RStudio (running separately). This actually worked well, but I decided just to use RStudio's "vim mode" instead to keep things simple. For your purposes, you can replace "RStudio" with the window name of whatever interpreter you're using.
AutoHotKey script called "paste2repl.ahk":
^m::
SendRaw ahk
SetTitleMatchMode, 2
IfWinExist, RStudio
WinActivate
SendPlay ^v `n
vimscript (for your .vimrc file):
" Sending code to Rgui
" -- This is called by AutoHotKey script "paste2repl.ahk"
" -- <C-m> sends "ahk" to Vim, then pastes the code to RStudio Console
vmap <silent> ahk "+y']0j
nmap <silent> ahk "+yy0j
imap <silent> ahk <Esc>"+yy0j