Rename Python Variables with nvim

waylonwalker

Waylon Walker

Posted on January 16, 2022

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
šŸ’– šŸ’Ŗ šŸ™… šŸš©
waylonwalker
Waylon Walker

Posted on January 16, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related