Video: Setting Up Vim to Work with Python Applications

In this short video tutorial I demonstrate my Vim editor setup for working with Python applications.

Do you want to try this out? Download my .vimrc file! If your tagbar does not work, install Exuberant Ctags (use brew install ctags or sudo apt-get install ctags, or download from http://ctags.sourceforge.net/)


  • #1 Brandon said 2020-05-13T12:54:50Z

    Thanks for this! I've never heard of tagbar so I may start using it. One thing you might find useful is you can add this to your .vimrc:

    set updatetime=125

    This will update gitgutter almost instantly when you make changes to git files.

  • #2 Miguel Grinberg said 2020-05-14T10:04:58Z

    @Brandon: Hey, I hope you are doing well! Thanks for the tip.

  • #3 Ollie said 2020-05-17T13:34:04Z

    Thank you! To make your instruction work please note that curl and exuberant ctags need to be installed. Regards and Kudos for your work!

  • #4 GreatBahram said 2020-05-18T15:34:16Z

    Hey Miguel,

    Thanks for sharing your development stuff! I really like the part that automatically installs vim plug.

    Kudos to you!

  • #5 Damian said 2020-06-29T13:06:11Z

    Hello Miquel, Thanks for all your work. This is not related to this video but I was wondering if you can help with the Microflack app on this URL https://github.com/miguelgrinberg/microflack_admin. The users' pod keeps crashing and kubectl logs give the following errors. I know its 3 years and many things have changed. Please see if you can help to fix the issues. Thanks

    kubectl get logs users-5d658dff8b-8ch7s 0/1 CrashLoopBackOff 8 17m

    kubectl logs users-5d658dff8b-8ch7s

    Traceback (most recent call last): File "migrations/env.py", line 87, in <module> run_migrations_online() File "migrations/env.py", line 72, in run_migrations_online connection = engine.connect() File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2082, in connect return self._connection_cls(self, **kwargs) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 90, in __init__ if connection is not None else engine.raw_connection() File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2168, in raw_connection self.pool.unique_connection, _connection) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/base.py", line 2138, in _wrap_pool_connect return fn() File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 328, in unique_connection return _ConnectionFairy._checkout(self) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 766, in _checkout fairy = _ConnectionRecord.checkout(pool) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 516, in checkout rec = pool._do_get() File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 1229, in _do_get return self._create_connection() File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 333, in _create_connection return _ConnectionRecord(self) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 461, in __init__ self.__connect(first_connect_check=True) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/pool.py", line 651, in __connect connection = pool._invoke_creator(self) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/strategies.py", line 105, in connect return dialect.connect(*cargs, **cparams) File "/usr/local/lib/python3.6/site-packages/sqlalchemy/engine/default.py", line 393, in connect return self.dbapi.connect(*cargs, **cparams) File "/usr/local/lib/python3.6/site-packages/pymysql/__init__.py", line 90, in Connect return Connection(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 706, in __init__ self.connect() File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 931, in connect self._get_server_information() File "/usr/local/lib/python3.6/site-packages/pymysql/connections.py", line 1269, in _get_server_information self.server_charset = charset_by_id(lang).name File "/usr/local/lib/python3.6/site-packages/pymysql/charset.py", line 38, in by_id return self._by_id[id] KeyError: 255
  • #6 Miguel Grinberg said 2020-06-29T17:39:13Z

    @Damian: it's an issue with the pymsql package and MySQL 8. Use a newer version of pymysql.

  • #7 Scott said 2020-07-04T11:30:55Z

    To get this to work on windows, I installed vim-plug manually and removed the lines relating to vim-plug detection and initial plugin installation. (The need_to_install_plugin blocks)

    I tried to see if I could figure out how to modify it so that part would work but couldn't figure out how to do it. I think it's related to how the home directory is specified in windows. But the manual vim-plug installation steps above do work.

    Also, @Miguel -- I don't seem to get notified about comments here when my post goes up or a response is posted.

  • #8 Scott said 2020-07-04T14:14:57Z

    Also these guys need to be commented out otherwise weird characters will invade everywhere.

    let &t_SI .= "\<Esc>[?2004h" let &t_EI .= "\<Esc>[?2004l"

  • #9 Miguel Grinberg said 2020-07-04T14:57:45Z

    @Scott: This may not be what you want, but I have used vim under the WSL and Cygwin using the same configuration w/o any issues.

  • #10 James Gardiner said 2020-07-09T22:22:04Z


    Looks very useful -- what triggers the flake/pep test?


  • #11 Miguel Grinberg said 2020-07-10T08:48:23Z

    @James: the syntastic plugin does a syntax check on file save.

  • #12 Anthony said 2020-07-17T02:30:41Z

    Hi Miguel, Thanks once again for a very useful tutorial. I'm trying it out as I want to get better at using vim which I think is really cool. For some reason, it gives a syntax error when I use the new python string format using f"my string". Also how do we get vim to recognise the virtual environment we're in?

  • #13 Miguel Grinberg said 2020-07-18T14:03:35Z

    @Anthony: You may be using an old version of vim, or maybe a vim compiled for Python 2 instead of 3. Vim uses the activated virtualenv by default.

  • #14 Kevin Luo said 2020-09-26T22:27:09Z

    Thank you very much @Miguel Grinberg for the fantastical sharing. But in my environment, the tagbar does not work even thought I have installed the exuberant ctags~;(

  • #15 Miguel Grinberg said 2020-09-27T13:28:33Z

    @Kevin: I'm not sure how I can help. I suggest going over issues in the repository for the tagbar plugin, maybe someone else had the same issue.

  • #16 Chris Thompson said 2020-12-10T23:04:00Z

    Man, this is going to improve my workflow soooo much. I use Vim as my main editor but I only had tabs configured and Kite installed. The rest was all Vim shortcuts. Thank you for sharing!

Leave a Comment