VimpyKid
This is gonna be a short one.
While I was writing my bachelor thesis, it was the first time that I worked with neural networks. I mean I have written a neural net before using Tensorflow but it was just following an example from their docs trying to classify cats ands dogs or something like that.
When I was working with neural networks (in ptyhon ofc. like everybody else either tensorflow or pytorch; I used tensorflow), I found myself writing a lot of print statements for debugging purposes. So I was pretty much writing a variable representing a tensor or a constant and wanting to print the value of it with its variable name. I was doing something like this the whole time:
Oh yeah, I was doing f-strings in Python the whole time, and I was writing this manually.
What I wanted to have is to be able to just write print(my_constant)
and when I enter
a Vim key combination while my cursor is standing on the statement,
Vim transforms the print statement to an f-string print statement using the
variable name. Like this: print(f"my_constant: {my_constant}")
.
So I searched how I can modify Vim’s behaviour and found out that I can write plugins. So I wrote one called VimpyKid. Using VimpyKid, if you are in a Python file and if your cursor is standing on a valid print statement. When you enter the key combination <leader>fs, Vim transforms the print statement to an f-string for you. If you do not know, <leader> is a character that you can specify in your .vimrc file, and that character will be used in Vim maps. My Vim <leader> is a space.
After some while I figured out that Python 3 has a similar functionality built-in. If you write the print statement like below, it prints an f-string (the variable with its value).
So to this day, I still heavily use my plugin for little Python scripts or whenever I want a quick debug. You can check the plugin’s Github repository here: VimpyKid. You can also use the plugin by adding it to your .vimrc. Add the below to your .vimrc using your favourite plugin manager. Set your <leader>. Install it, and enjoy.