
Using Vim as a Python IDE - liuchengxu
http://www.liuchengxu.org/posts/use-vim-as-a-python-ide/
======
therealmarv
Yesterday I've downloaded VSCode and
[https://github.com/DonJayamanne/pythonVSCode](https://github.com/DonJayamanne/pythonVSCode)
(seriously, look at the GIFs in this repo!) for first time and I had
autocompletion (with IntelliSense and documentation lookup), refactoring and
code define jumping for Python code out of the box working within 10 minutes
in a VirtualEnv. VSCode + one plugin (all opensource) and I had something
similar to PyCharm and fast. (nothing against vim, just want to mention how
impressed I was)

~~~
general_ai
VSCode/Atom are great, but for most folks on UNIX they are worthless, since
you have to use something else when ssh-d into another machine. So folks build
these elaborate Vim and EMACS set-ups so that they could use the same editor
and the same config on all of their machines, whether they're local or remote.
Vim is an acquired taste, but once acquired, it's pretty awesome.

~~~
therealmarv
Well this is your use case. I use Linux every day but I never touch python
code directly on remote systems (it's getting automatically or manually
deployed). All my python code lives in virtualenv locally here. But I
understand when people work for many projects they maybe want to encapsulate
it more (vagrant etc.).

~~~
general_ai
I prefer console in general, for everything. I've been doing this for 20+
years, and you can pry it from my cold, dead hands.

~~~
dotancohen
I've only been coding for 11 years professionally, but also as a hobby before
that. Only in 2016 did I move most of my work out of VIM into an IDE: the
Jetbrains family. That mostly started for better interactive debugging, but
with IDEAVim handling 95% of my VIMisms I find that I'm simply coding in
PyCharm and PhpStorm by default now.

The base editor is open source but you can get the full PyCharm for $99 per
year. Worth every cent.

~~~
Arizhel
I've used PyCharm. The editing feature is beyond useless to me, because it
does not have vim key bindings. How am I supposed to cut and paste code when
commands like "y}" don't work? You actually expect me to use a _mouse_ to
select things or move the cursor? Ridiculous.

The only thing I've found PyCharm good for is doing other functions, like
linting, not for the actual code editing. No IDE is any good for that.
Luckily, PyCharm works just fine when the code it's working with changes on
the filesystem below it because of the use of an external editor.

~~~
xbrother
There is VIM plug-in for Intellij family IDEs. It covers the great part of VIM
functionality. It even supports some sort of VIM configs. "y}" works fine, as
well as "yi{".

------
wry_discontent
Emacs comes configured with a command called "send-region-to-shell" that will
take the current region and send it to a python interpreter. It makes for a
great development experience that I haven't seen replicated with other tools
and I'm not sure why there's not a bigger interest in it.

~~~
fredsir
If I'm not mistaken, that's one of the features of Tslime[1], which is a Vim
plugin that allows Vim to communicate with Tmux.

[1]:
[https://github.com/jgdavey/tslime.vim/](https://github.com/jgdavey/tslime.vim/)

~~~
leblancfg
Yup! There are in fact quite a few similar vim plug-ins that do the same.

This is one of the longest-standing line in my vimrc so far:

    
    
        Plug 'epeli/slimux'
    

Works best for what I do.

------
jzelinskie
Hadn't heard of w0rp/ale, but it looks like an improvement over Neomake. I
feel like I've done a pretty good job at enabling a lot of features with only
~200LOC vimrc[0]. I also avoid dependencies that need to be compiled or depend
on a scripting language installed to the system. My .zshrc these days even
parallels my vimrc style[1].

[0]:
[https://github.com/jzelinskie/dotfiles/blob/master/.vimrc](https://github.com/jzelinskie/dotfiles/blob/master/.vimrc)

[1]:
[https://github.com/jzelinskie/dotfiles/blob/master/.zshrc](https://github.com/jzelinskie/dotfiles/blob/master/.zshrc)

~~~
thatmiddleway
Same here, I'd never heard of it. I switched over to check it out, and am very
pleased with how much more responsive it is than neomake. It's marking things
while I'm still in insert mode, and not waiting till I save the file, quite
useful. It's probably going to stick around and be my new go too!

Even though I write ruby and javascript all day, I still like to go and read
how others are using vim. I usually walk away with a keybinding or plugin that
makes my life better.

------
MooMooMilkParty
The one thing I'd love to see, as a vim user and a scientist, is something
like Matlab/RStudio/Spyder where you can explore variables that exist within a
session. Maybe it could hook up to an ipython session and you could display it
in a separate terminal and send commands with vim-slime to be updated in real
time.

For the most part, when I need this, I revert to Rodeo (since it has vim
bindings like RStudio's), but if I could ditch it that would be amazing.
Nothing against Rodeo or other editors, but vim habits are hard to break.

~~~
ice109
pycharm let's you do this! this is the only thing I missed from MATLAB. you
can set a breakpoint in a script and open up the debug console and see all the
live variables and run code. it works perfectly and you get Python + pycharm.
I'm spoiled now and anticipate having trouble moving to another language.

~~~
c06n
It's been a while that I have used it, but I used to do that in Matlab all the
time. The shortcut in the IDE was F9, I think.

------
no_wizard
I want to give a shout out to spacemacs.org which let's you do so many of
these things and really does feel like the best of Emacs and Vim together. I
will say I am a new convert so I can't comment so much in the plugin
infrastructure but raw coding is really good and it's very configurable like
emacs but without all of emacs overhead

~~~
Synroc
did you have experience beforehand in using emacs? I've been using spacemacs
for a couple of weeks, but I'm having trouble getting past the most basic
usage, and partially it's because I feel like I don't have much experience
with emacs.

~~~
no_wizard
I did not in any real sense. I did the tutorial and chose the sane defaults
recommended (so called Evil Mode) which gives you some great controls and a
nice tutorial you can walk through if you type :tutor at the main screen.

I admit I have never used Vim or Emacs but the tutorial was enough to do
movement and I also read this wonderful documentation as well: First this here
which gives a wonderful overview of the whole philosophy behind SpaceMacs:

[http://spacemacs.org/doc/DOCUMENTATION](http://spacemacs.org/doc/DOCUMENTATION)

Then I took a look at this just to get some better idea of how to do certain
things with the layers since it's very dependent on a layering system:

[http://spacemacs.org/doc/LAYERS.html](http://spacemacs.org/doc/LAYERS.html)

And for good measure since Evil mode emulates Vim I thought it might be nice
to see what this had to say:

[http://spacemacs.org/doc/VIMUSERS.html](http://spacemacs.org/doc/VIMUSERS.html)

It took me like a week to be efficient but now I'm flying so much faster than
I was with VS Code or Atom. I still use Sublimr Text for some things because I
like it but this is a great editor and has a lot of potential and is extremely
extensible with Emacs lisp and I believe they already have a way to bridge in
Vim plugins too

------
empath75
I keep seeing tmux mentioned recently. Can someone eli5 what it does and why
it's useful?

~~~
sidmitra
Most of the other comments mention that you can split your screen into tabs
and panes. But by far the most important feature of gnu-screen or tmux is the
ability to have a shell session running even when you're not logged in. So you
can use tmux to start a shell session and run a script(say a command line IRC
client) and leave it running. Next you'll just 'detach' from your tmux session
and can logout. Your irc client or any number of scripts you started from your
tmux session will still be running. You can relogin later and 'attach' to that
session and you'll continue where you left off. Infact you can start a tmux
session on the server in the office, detach/logout and go home and attach to
the same exact screen from home, that you left in the office.

Not to mention you can share your command line shell session/screen with other
people!!

~~~
wsha
This is the best feature of tmux. It's worth pointing out here though (in a
post about making the terminal act like an IDE), that you can split the
terminal into two panes so you can have an editor and a REPL open at the same
time similar to many IDE's. There are even some projects that make it easy to
pass code between the editor and the REPL in the other pane, though I have
never gotten them to work very well.

~~~
groovy2shoes
vim (and emacs) can do that without the need for a terminal multiplexer
(though in vim you need to use a "plugin" for it, or, at least, you used to,
and I'm sure the new async functionality in vim 8 has improved the experience
quite a bit)

------
superquest
Nice post.

I also really like you "space-vim" project. Another similarly named project —
"SpaceVim" [http://spacevim.org/](http://spacevim.org/) — was posted recently.
"SpaceVim" was really upsetting because it missed so many of the important
ideas of Spacemacs, such as pneumonic keybindings. "SpaceVim" is a garden
variety vim distribution coopting the "Spacemacs" name, but you stayed true to
the "Spacemacs" principles. Nice work!

~~~
matthewbauer
This threw me for a second but its "mnemonic" not "pneumonic".

~~~
StavrosK
Until I read your comment I was trying to figure out why they called them air-
propelled keybindings, not finding any obvious analogies...

------
scardine
I would love to download a config file with a curated list of plugins that
turns vim into a good Python IDE.

~~~
gravypod
Let me augment that with this: I would love to donate to a project that uses
${INSERT_TERMINAL_TEXT_EDITOR} and turns it into a general IDE.

I'm talking the full shebang.

    
    
       * Autocomplete/Autoimporting (Static Analysis backed by compiler output)
       * Formatting
       * Linting
       * Fast or able to run over a slow SSH connection. 
       * Default error resolutions (if test() throws an exception generate a try { })
       * Global refactoring
       * The idea of a project (Creating, building, export/importing, libraries, dependencies)
       * Automatically generated & maintained building system at the click of a run button
       * Documentation at a single click or on hover if possible
       * Integrated console for running a project
       * File and source manager that should be easy to use
       * Binding profiles for Eclipse, NetBeans, JetBrains, VS20XX, ReSharper
    

Optionally these would be nice:

    
    
       * Formal Method Verification? 
       * Coloring/styling of the entire TUI
       * Simple to interact with menus
       * Rust, Go, JavaScript (Browser & Node), Java, Scala, C, C++, PHP, Python support 
       * Pluggable language support that allows the plugin to provide static analysis & compiler data
    

If that can all be provided that could easily sell for $25 to $50 per user and
I'd be happy, happy!, to pay every last dollar of it. It'll never happen. The
world will never be that kind to software developers.

~~~
base698
I have almost all of this in both emacs and vim and it only took me 5 years to
get it just right.

~~~
Asooka
Can you elaborate on how you handle the project thing? I really miss having
the concept of "solution" and "project" in Vim from VS. Not just to have my
files grouped logically in a $Project/{source,include}/blah.{h,cpp} tree, but
also to be able to apply per-project settings like clang-complete options,
etc. Right now I don't see a way to have e.g. three different projects that
all build from the same files, but use different build options (mainly third-
party sdk versions) and thus should give me different completions and code
navigation.

~~~
base698
Part of why I switched to emacs was something called helm:
[https://tuhdo.github.io/helm-intro.html](https://tuhdo.github.io/helm-
intro.html) It fuzzy matches almost anything: files, function names, or
commands

Project grouping in the traditional sense can be done with projectile and
NeoTree.
[http://projectile.readthedocs.io/en/latest/](http://projectile.readthedocs.io/en/latest/)
[https://github.com/jaypei/emacs-
neotree/blob/dev/README.md](https://github.com/jaypei/emacs-
neotree/blob/dev/README.md)

I think what you are describing in the second half can be handled with company
mode and triggering a major/minor mode off a file extension.
[https://www.gnu.org/software/emacs/manual/html_node/emacs/Ma...](https://www.gnu.org/software/emacs/manual/html_node/emacs/Major-
Modes.html)

[http://company-mode.github.io](http://company-mode.github.io)

If that's not it it's possible Googling will find exactly what you describe.
People tend to port anything useful from any editor to emacs.

------
IgorPartola
I would love to replace Syntastic with ale, but (1) is there a way to have it
just highlight the line with the error instead of using the gutter? And (2) is
there a way to get it to use pyflakes instead? pylint is a little too
aggressive: it complains about modules it can't import which is by design in
my working environment.

~~~
mezuzza
Alternatively, add the following to your `~/.pylintrc`. Granted pylint just
stops checking those particular modules, but it's better than nothing.

    
    
        [TYPECHECK]
        ignored-modules = ssl,pyodbc

------
machbio
Autocomplete with Conda has got no support - if anyone has any idea other
than; [https://github.com/cjrh/vim-conda](https://github.com/cjrh/vim-conda)

~~~
gogoengie
Well, if you genuinely want a braindead alternative to `vim-conda`, you're
welcome to this brittle hack I use. (For my purposes, fast-and-dirty has been
an efficient solution, but I don't actually _recommend_ this to anyone.)

Add it to your `ftplugin/python.vim`. Requires you to have activated the Conda
environment before opening the Python file, uses hard-coded Python versions,
doesn't work with multiple environments, doesn't bother with `os.path.join` so
no Windows compatibility, etc etc. Like I said: a hack.

    
    
      " Cheap trick to use the Conda environment with omnicompletion
      python3 << EOF
      import os
      import sys
      cenv = os.environ.get('CONDA_PREFIX')
      if cenv is not None:
          # Taken from `sys.path` as reported by ipython
          sys.path.insert(0, cenv + '/lib/python3.5/site-packages')
          sys.path.insert(0, cenv + '/lib/python3.5/lib-dynload')
          sys.path.insert(0, cenv + '/lib/python3.5/plat-linux')
          sys.path.insert(0, cenv + '/lib/python3.5')
          sys.path.insert(0, cenv + '/lib/python35.zip')
          sys.path.insert(0, cenv + '/bin')
      EOF
      set omnifunc=python3complete#Complete
    

edit: mentioned `os.path.join` to warn Windows users and fixed in-place
bugfix.

------
tamatsyk
I have been using vim as my primary IDE for small projects for more than a
year till previous month. Everything was fine, even optimizing slow plugins
was OK for me. The best plugin I used was a YCM, the best autocomplete I've
seen in console world, and there were so many problems with it.

Finally I gave up and moved to NeoVim and have no issues with my vim anymore.
Maybe later I will give another try to spacevim or emacs. Maybe. So far,
keeping my fingers safe :D

------
theRhino
this look s ok but i don't see a section on pdb integration - i'd say thats
key. I'm still looking for a sensible description of how to develop python in
emacs. I'm amazed that there doesn't seem to be a de facto way to do it..

------
agounaris
Seriously people this is 2017! We have the technology. Learn vi in order to
have the same editing experience everywhere but honestly when it comes to
IDEs, there are just really good software packages out there with 0
configuration hassle.

~~~
ageofwant
You imply that vim is somehow technological inferior to some other tool. I
take issue with that. I don't use vim because I have to or some silly 'vim
everywhere' argument. I use it because it is a demonstrably superior text
editing appliance.

Every so often when vim irritates me I try out PyCharm or vm-whatsit, and
while IDE's do have better viz for some use cases, the actual act of
manipulating code in-buffer never comes close to speaking vim. And I always
add the vim plugin, without them the tool would be of no use to me whatsoever.

I hope someday some tool will eclipse (no) vim, but that's simply not the case
in 2017.

~~~
falcolas
I'm in the same boat. Local development only, my terminal is still my IDE.
Other editing tools I've attempted and jumped back out of:

PyCharm - No good vim emulation for editing

Spacemacs - Soft locks, Ctrl-] doesn't follow the same word boundaries as
Meta-. (which matches Vim's implementation)

Sublime Text - Closest fit (enough that I own a personal license), but again,
the vim emulation is pretty bad.

Atom - Slow. Even at its fastest, it's noticeably slower than Vim

VSCode - Slow (though faster than Atom), no good vim emulation.

Yes, most of my criticisms form around the lack of good vim emulation - my
muscle memory is very well established. I've just yet to find a good,
responsive, and comfortable editing scheme from a non-Vim editor.

~~~
WildUtah
I'm trying Neovim and it's the only editor I've ever tried that I like as much
as Vim. Every other substitute has been inadequate.

------
Siecje
How do you jump to definition?

~~~
gogoengie
If you are editing files inside a package, you can generate a tags file for
definitions inside that package.

More useful, IMHO, is the general solution of jumping to the definition that
would be resolved by the python interpreter, regardless of location. For that,
the key binding will depend on the plugin. For `jedi-vim`, you use `<leader>d`
[0].

Incidentally, if you're new to using VIM as a python IDE, also note the value
of `jedi-vim` providing Python docstrings via the standard VIM keybinding `K`.
This is also mentioned in [0].

[0] [https://github.com/davidhalter/jedi-
vim#features](https://github.com/davidhalter/jedi-vim#features)

------
xs
Can vim do multi-cursor editing? Like how sublime text can?

~~~
shriek
It can but it's not robust as sublime's multi-cursor editing.
[https://github.com/terryma/vim-multiple-
cursors](https://github.com/terryma/vim-multiple-cursors)

------
fattymagoo
100010000000100001010100101000001001001010100101000010010100001010101010010101010010011100010101110010101010101010101010010101010101010101010101010101001001010019010101010010100101010101101000101010101010101000001110+

------
vgy7ujm
Love vim, not so sure about that snake..

------
qwexvf
could you share the dotfiles please?

~~~
liuchengxu
Here is the true vim configuration shown in the post:
[https://github.com/liuchengxu/space-vim](https://github.com/liuchengxu/space-
vim)

------
fattymagoo
hi

