DEV Community

Cover image for Rename Python Variables with nvim
Waylon Walker
Waylon Walker

Posted on β€’ Originally published at waylonwalker.com

6 2

Rename Python Variables with nvim

I don't use refactoring tools as much as I probably should. mostly because I work with small functions with unique names, but I recently had a case where a variable name m was everywhere and I wanted it named better. This was not possible with find and replace, because there were other m's in this region.

I first tried the nvim lsp rename, and it failed, Then I pip installed rope, a refactoring tool for python, and it just worked!

pip install rope
Enter fullscreen mode Exit fullscreen mode

Once you have rope installed you can call rename on the variable.

:lua vim.lsp.buf.rename()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Jetbrains image

Build Secure, Ship Fast

Discover best practices to secure CI/CD without slowing down your pipeline.

Read more

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay