Sending multiple python lines with ConqueTerm

喜你入骨 提交于 2019-12-12 01:28:47

问题


I'm using vim with ConqueTerm and ipython (--pylab if it matters) on Ubuntu 14.04. When I select multiple lines and send them using F9, everything pastes in the same line, as in this question. I could try remapping as the poster did for that question, but I don't have this issue with matlab on the same machine or with ConqueTerm+ipython on mac. Is there a way to fix this so I can continue using F9? Thanks!


回答1:


The solution

It was my first experience using vimscript, but I was able to modify the plugin so it can send the selected lines properly.

I changed the send_selected function in the conque.vim(or another mirror)\autoload\conque_term.vim to this: https://gist.github.com/freencis/28e351e3bb267a8522e1dff53436fb8d

The function name is the same, just go there and replace it.

What I did

I will skip the "explaing what was wrong" part, mostly because I didn't fully grasp the original implementation.

So, after searching a bit on the internet about how I could access the file's text from a plugin, I ended up finding a way to get the text from specific lines from the file: using the getline function. Luckly there were already a Conque's function to send the line to the terminal and execute it (used by the 's send_file), so I just used it.

Then It was just a matter of knowing which lines were selected and get those. Which led me to the line function, which returns the line number in a different ways. One of these was by marker, in this case the '<, '> markers from the visual selection. Unfortunately I also don't know how to explain these, but calling line("'<") and line("'>") returned me the selection's start and end lines respectively.

And that was the vimscript programming part, the :help is really a life saver. The traditional programming was just looping through the line numbers, getting the text from those and sending them to the terminal.

Notes

It was my first ever experience with vimscript (I've only been using vim for a month), so I'm sure it might not the proper way to do it, plus I replaced a functionality, so I'm just sharing it as a quick hack. Any feedback is appreciated.

Props to http://learnvimscriptthehardway.stevelosh.com/, it helped me a lot with the language, I never expected it to be that accessible

And sorry for any bad English. peace



来源:https://stackoverflow.com/questions/33787975/sending-multiple-python-lines-with-conqueterm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!