:Rename (from vim-rename) fails with Python files in my current set up with the following error:
line 46:
E486: Pattern not found: \s\+$
if the file does not contain trailing whitespaces in at least one line, leading to the file being duplicated (with the new name and the old one).
Using the following file helloworld.py (note there are no trailing whitespaces):
print("Hello, world!")
If I attempt to use :Rename new_name.py it will spew out the previously-mentioned error, and I'll end up with two files (helloworld.py and new_name.py). If, however, I add whitespaces at the end of the line, the renaming will succeed and the trailing whitespaces are automatically removed.
This seems to be due to some sort of conflict between vim-rename and python-mode, since it only happens with Python files.
After debugging what happens on a write with :debug write, I can see that pymode#trim_whitespaces() is invoked by default by python-mode. If I disable it by let g:pymode_trim_whitespaces=0, the problem with vim-rename goes away. However, automatic trimming of trailing whitespaces is a feature I don't want to lose.
My questions, in order of importance:
- How can I fix this so that I can rename files and keep the automatic trimming of whitespaces?
- Why is the non-existence of whitespaces causing rename to fail?
I would prefer to keep vim-rename, although I'm willing to switch it for a more robust plugin if necessary. Fixing the code in vim-rename manually would also be acceptable.
If it is of any use, this is my complete vimrc file.
python-modeautomatically trims whitespaces on save. I am not sure why that would cause the deletion of the old file to fail, but it does. – user2891462 Sep 20 '17 at 09:28Renameas well (but please see README for difference betweenRenameandMove) – grodzik Sep 20 '17 at 09:45eflag to the substitute command will fix it. – Heptite Sep 20 '17 at 16:37