At the beginning of the summer, I configured my vim environment for Python development, including being able to compile my code within the editor. Today, I pulled up some old files and couldn’t remember how to run it anymore…
I looked in my vimrc file and it looks like this:
" Set makeprg to compile current Python file
set makprg=python\ %
set noswapfile
" Map keys to compile Python scripts
:nnoremap <S-b> :b1 <bar> :w <bar> :1,1000bd! <bar>
:b1 <bar> :botright vnew <bar>
:read !python lol.py -m json.tool <CR>
What is this ugliness?! It looks like hitting Shift+B results in the following:
- Loads the first buffer (presumably where my code is)
- Writes the file (saves it)
- Closes buffers 1 through 1000 (essentially closes all buffers). I assume the exclamation forces this action without saving the other buffers.
- Reloads the first buffer
- Opens a new vertical buffer in the bottom right part of vim
- Runs the shell command
python lol.py
and reads the output into a new buffer - Runs the Python module, json.tool
- Hits enter
Ignoring the fact that I apparently hardcoded a build sequence for one file, the output doesn’t look too bad. The results look like this: