Python Debugging in Vim & VS Code Made Easy

It’s as simple as using this mapping: noremap <LEADER>p oprint(f"<ESC>pa: {<ESC>pa}")<ESC>

Then, whenever I want to debug something, I yank the name of the variable (usually via ye), then type <LEADER>p, which makes a print statement for me:

Note: that’s an old animation when before I changed the mapping to make use of Python 3’s f-Strings.

My leader is the spacebar. I use https://github.com/machakann/vim-highlightedyank to highlight my yanks.

Edit January 2022: I have moved to VS Code. To achieve the same with the Vim plugin, I have the following added to my vim.normalKeyBindings:

       { "before": ["<LEADER>", "p"], "after": ["o", "p", "r", "i", "n", "t", "(", "f", "'", ":", " ", "{", "}", "<ESC>", "P", "^", "f", "'", "p", "^"]},

Leave a comment