简体   繁体   English

从vim向终端或IDLE发送python脚本的捷径

[英]Short cuts to send python script from vim to terminal or IDLE

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. 我现在是R使用者,并且对使用Vim-R-plugin非常满意,在这里您可以使用许多快捷方式将在vim窗口中编辑的R脚本发送到R执行窗口。 Recently I started to learn Python and would setup a similar environment. 最近,我开始学习Python,并将建立一个类似的环境。 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. 事实证明,我在网上找到的所有内容都是针对像Python这样的专业人士使用的,对于像我这样的初学者而言,这太复杂了,而且花费时间也更多。 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. 例如,我有两个窗口:在vim窗口(macvim)和另一个执行窗口(终端或IDLE)上编辑python脚本。 My question is how I can set up them smoothly like the R-VIM system rather than copy and paste. 我的问题是,如何像R-VIM系统一样平滑地设置它们,而不是复制和粘贴。

You can use ConqueTerm to open both vim and Python (or iPython, or IDLE) within one vim session. 您可以使用ConqueTerm在一个vim会话中同时打开vim和Python(或iPython或IDLE)。 Then you can remap a key to send vim code to the interpreter. 然后,您可以重新映射密钥以将vim代码发送到解释器。

Here's a solution I tried. 这是我尝试过的解决方案。 Stick this in your vimrc file: vmap <silent> <leader>m "*y<Cw><Cw>p 将此粘贴到您的vimrc文件中: vmap <silent> <leader>m "*y<Cw><Cw>p

I had mapped comma as the leader key, so it executed when I entered "comma-m". 我已经将逗号映射为引导键,因此当我输入“逗号-m”时它就会执行。 It worked in Linux but not on Windows for some reason. 由于某种原因,它可以在Linux上运行,但不能在Windows上运行。 Here's a SO question I asked about it. 这是我问的一个SO问题

EDIT: 编辑:

Here's a similar idea, using AutoHotKey to send code from vim to RStudio (running separately). 这是一个类似的想法,使用AutoHotKey将代码从vim发送到RStudio(单独运行)。 This actually worked well, but I decided just to use RStudio's "vim mode" instead to keep things simple. 这实际上效果很好,但是我决定只使用RStudio的“ vim模式”来简化操作。 For your purposes, you can replace "RStudio" with the window name of whatever interpreter you're using. 为了您的目的,您可以将“ RStudio”替换为您使用的任何解释器的窗口名称。

AutoHotKey script called "paste2repl.ahk": AutoHotKey脚本称为“ paste2repl.ahk”:

^m::
SendRaw ahk
SetTitleMatchMode, 2
IfWinExist, RStudio
    WinActivate
    SendPlay ^v `n

vimscript (for your .vimrc file): vimscript(用于您的.vimrc文件):

" 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM