How should I rename my current file in Vim?
For example:
person.html_erb_spec.rbperson
Vim does have a rename function, but unfortunately it does not retain the history.
The easiest OS agnostic way to rename a file without losing the history would be:
:saveas new_file_name
:call delete(expand('#:p'))
expand('#:p') returns the full path of the older file.
Use :bd # if you also want to delete the older file from the buffer list.
If you want to use a quick command to rename the file, add a new file under ~/.vim/plugin with the following contents:
function! s:rename_file(new_file_path)
execute 'saveas ' . a:new_file_path
call delete(expand('#:p'))
bd #
endfunction
command! -nargs=1 -complete=file Rename call rename_file()
The command Rename will help you to quickly rename a file.