I'm using this plugin to rename files, but I was wondering if it's possible to just specify a name change. For example, if I rename a file that's not in the :pwd
and I don't specify its path, it will get moved to the current dir.
I'm using this mapping: nnoremap <F6> :Rename
So maybe I can put some variable after the :Rename command that will place the current file's relative path and name?
Thanks!
:!mv <oldname> <newname>
. In fact, in your case you could execute:!mv % %:h/newname
and Vim would expand%
to the current file name and%:h
to the parent directory of the current file name when the command is executed. See:help filename-modifiers
.<C-R>%:n
just appears to take % into account and :n is printed literally.%:h
(that's anh
, not ann
) before the command is executed, use<C-R>=expand("%:h")<CR>
. The=
refers to the expression register (See:help c_CTRL-R_=
) which prompts for an expression. An expression may be a function call;expand()
is a function that expands its argument. (See:help expand()
.) The<CR>
terminates the expression so that its value is placed where you typed theCtrl-R
. Your mapping could then be something likennoremap <F6> :!mv % <C-R>=expand("%:h")<CR>/
. Note that I chose to not expand the first%
until the command is executed.