From af4c1b8b0d7d4201bd100ddace3d10d2d6f1fccc Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Mon, 15 Aug 2016 22:37:12 -0400 Subject: [PATCH] Initial commit --- README.md | 11 +++++++++++ plugin/renamefile.vim | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 README.md create mode 100644 plugin/renamefile.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..9a2e2e9 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# renamefile.vim + +This function, ripped directly from [Gary Bernhardt's dotfiles](https://github.com/garybernhardt/dotfiles) +renames a file in place. + +## Usage + +This plugin adds the command `:RenameFile`. When called, it will prompt you for +a new file name. If the filename is blank or the same as the previous file +name, nothing will happen. If the new name is different, the file will be +saved as the new name and the old file will be delated. diff --git a/plugin/renamefile.vim b/plugin/renamefile.vim new file mode 100644 index 0000000..6a98e02 --- /dev/null +++ b/plugin/renamefile.vim @@ -0,0 +1,11 @@ +function! s:RenameFile() + let old_name = expand('%') + let new_name = input('New file name: ', expand('%'), 'file') + if new_name != '' && new_name != old_name + exec ':saveas ' . new_name + exec ':silent !rm ' . old_name + redraw! + endif +endfunction + +command! RenameFile call RenameFile()