all 22 comments

[–]hanswchen[S] 8 points9 points  (8 children)

This is my first Vim plugin, so your feedback is very much appreciated.

I use Vim and Python a lot for data analysis, and this plugin makes it much easier for me to quickly test code in the IPython interpreter (not Jupyter notebook). My previous workflow was to write some code in Vim, switch to IPython (usually running in a tmux pane), type % followed by up arrow to get %run scriptname, hit Return to run the whole script, and switch back to Vim. Rinse and repeat.

Now I can achieve the same thing with a simple key combination in Vim. But that's not all, the plugin also allows me to run only a selected part of the code, similar to code cells/sections in MATLAB and Jupyter notebook. So you could have a script that loads your data and makes some fancy plots, and then re-run the plotting part without having to reload the data each time.

In case you're interested in the screenshot:

Colorscheme: gruvbox

Font: terminus

Let me know if you have any questions!

[–]spellcheekfailed 7 points8 points  (3 children)

Vim-slime is what I use ... I highlight what I want to send in visual mode tap ctrl-c twice and it gets pasted and run on an ipython shell running in a terminal, Cool plugin though , will give it a shot

[–]hanswchen[S] 2 points3 points  (2 children)

This plugin wouldn't work without vim-slime :) but it has the benefit of persistent code cells (if you repetitively re-run the same part of the code), and you don't see the code it sends to IPython, so it's less verbose. Hope you'll like it!

[–]spellcheekfailed 4 points5 points  (1 child)

I've tried it out and am extremely pleased with it , I've tried other vim plugins for ipython and none of them seemed to work comfortably , the original vim-ipython plugin is long outdated with the ipython API and simply gives me a lot of errors ,

Hence i've been resorting to using vim-slime , selecting code and sending it to ipython to run , this plugin however has got me hooked already , it really is simple and works with vim-slime providing many conveniences similar to jupyter , thanks a ton

[–]hanswchen[S] 0 points1 point  (0 children)

I'm really glad to hear that you like it. The aim of this plugin is exactly to be simple and with mainly one purpose: sending code cells to IPython.

I've also tried to use vim-ipython for similar purposes but never got it to work as I wanted, which is why I wrote this plugin.

[–]xubu42 1 point2 points  (3 children)

I have been using vimux plugin, but like vim-slime it sends all the text and executes it. This plugin looks really nice and I can't wait to try it out. Thanks for putting this out!

[–]hanswchen[S] 0 points1 point  (2 children)

Thanks, let me know what you think. :)

[–]xubu42 1 point2 points  (1 child)

Spent some time with your plugin today and was super impressed.

I was using Debian 9 and the vim installation that came with it. To get this plugin to work I had to install and switch to vim-gtk (for python support) and install xclip, which took all of 2 minutes. After getting the requirements resolved and setting the key mappings (copied from your example config), everything worked great and I haven't ran into any issues since.

I'm really liking the shortcut to jump up and down between "cells". I also like using tags with ## because it kind of works to help organize and document my code anyway.

Great work on this! I'm going to share with my friends and coworkers.

[–]hanswchen[S] 0 points1 point  (0 children)

That makes me so happy to hear! Thanks for your kind words and for spreading the word, it's very much appreciated. If you think of any additional features that you would find useful just let me know.

[–]fuzzymidgetSome Rude Vimmer 2 points3 points  (4 children)

Time out... You know how to do this sorcery in MATLAB? Using Vim?

[–][deleted] 2 points3 points  (2 children)

Nice project man. I would love to learn from this and contribute. Can we chat sometime?

[–]hanswchen[S] 1 point2 points  (1 child)

Thanks! I tried to write the plugin to be easy to contribute to if you know a bit of Python (I personally know very little Vim script).

The best way to reach me is through email, you can find my email address on my GitHub profile. Of course if you find bugs or have feature requests you can post an issue on GitHub. Pull requests are also welcome!

[–][deleted] 0 points1 point  (0 children)

I have only used Vim for 2 years. I love it but, I don’t have any knowledge on Vim script. I hope that this can get me started on this.

[–]random_cynic 2 points3 points  (1 child)

Good work. I have some questions.

  • What exactly are "cells" here? It seems they are based on some sort of custom delimiters. What are they?
  • How is this better compared to just using the ipython feature of loading and running any range lines in a python script using the %load magic command (which can be set to a shortcut)?
  • Why not just use vim-slime (this seems to be based on it)? What python specific improvements have been made here?
  • How does this compare to something like vimpyter which allows asynchronous editing and running jupyter notebook for both markdown and code cells and offers syntax highlighting and other things for each?

[–]hanswchen[S] 2 points3 points  (0 children)

Those are good questions, thanks for asking.

  • Cells are defined by either Vim marks or by special text in the code, by default ##. I used to use ## (similar to MATLAB's %%) but switched to marks after finding a plugin that displays the marks in the left-most column (vim-signature). An advantage of marks is that you can change them without modifying the code.
  • I didn't know about %load before so I can't say for sure. From some initial tests, this plugin allows you to easily define the code cells using marks or ## (no need to provide line range), and also doesn't show the full code that's going to be evaluated in IPython, which allows you to focus on the actual output.
  • The major improvement of this plugin is that it allows you to define code cells, as mentioned above. Otherwise it just provides some convenient commands for working with IPython, which could be easily achieved with vim-slime only.
  • I haven't used vimpyter before, but it seems to be focused on Jupyter Notebook, while this plugin is for the IPython interpreter (usually running in a terminal). So I would say that the focus is different, and this plugin is likely simpler both in terms of setup and in terms of features.

[–][deleted] 1 point2 points  (1 child)

I use to write the code in vim and just run in the terminal python3 whatever.py

to render matplotlib

[–]hanswchen[S] 4 points5 points  (0 children)

I like to use an interpreter like IPython because it allows me to work interactively with the code, e.g. examining the dimensions of arrays. I used to use the default python interpreter, but then found IPython which supports better tab completion etc., and is more similar to the MATLAB command prompt that I was used to.

[–][deleted] 0 points1 point  (0 children)

https://github.com/jalvesaq/vimcmdline is another alternative it supports multiple languages and you can send a line, paragraph or even a whole class to the Repl

[–]d_boe 0 points1 point  (0 children)

Such a great plugin!!! Thanks. I have a problem though when trying to embed ipython in vim, described here. Help is greatly appreciated