:Rename (from vim-rename) fails with Python files in my current set up with the following error:
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):
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 (
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
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