davidhalter / jedi-vim

Using the jedi autocompletion library for VIM.
MIT License
5.27k stars 370 forks source link

Add a keyboard mapping to rename variables/functions/classes without deleting the word under the cursor #1097

Closed jamescherti closed 1 year ago

jamescherti commented 1 year ago

This pull request adds the key mapping <Leader>R (upper case R) to rename variables/functions/classes without deleting the word under the cursor:

Bug fix: This pull request also adds the support for set selection=exclusive to the function rename_visual()

davidhalter commented 1 year ago

So that would just not delete the word under the cursor initially, but otherwise work pretty much the same? Because we have been discussing internally to have two different ways of doing renames anyway.

jamescherti commented 1 year ago

That is right, @davidhalter . The behavior is the same as before, but if you set g:jedi#rename_command_reuse_name or b:jedi_rename_command_reuse_name to 1, the rename command will not delete the word under the cursor anymore. It will move the cursor to the end of the word and switch to insert mode instead, which allows the user to edit it.

This pull request will make it easier for the user to edit long variable, function or class names.

jamescherti commented 1 year ago

FYI: I just added the support for set selection=exclusive to the function rename_visual() (bug fix).

davidhalter commented 1 year ago

Hmmm I feel like we should probably have a different command for what you are trying to accomplish. Currently the default is <leader>r for rename and I feel like we should do something like a <leader>R to do what you want. Because I agree with what you are trying to achieve, I would just prefer a different command entirely.

What do you think?

jamescherti commented 1 year ago

Good idea, @davidhalter . Please check the latest commit.

davidhalter commented 1 year ago

Tested and looks good to me, thanks a lot!

jamescherti commented 1 year ago

Thank you for merging!