Renaming the current file in Vim

前端 未结 21 686
轻奢々
轻奢々 2021-01-29 17:15

How should I rename my current file in Vim?

For example:

  • I am editing person.html_erb_spec.rb
  • I would like it renamed to person
21条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 17:54

    I'd recommend :Rename from tpope's eunuch for this.

    It also includes a bunch of other handy commands.

    The Rename command is defined as follows therein currently (check the repo for any updates!):

    command! -bar -nargs=1 -bang -complete=file Rename :
      \ let s:file = expand('%:p') |
      \ setlocal modified |
      \ keepalt saveas  |
      \ if s:file !=# expand('%:p') |
      \   call delete(s:file) |
      \ endif |
      \ unlet s:file
    

提交回复
热议问题