Skip to main content
save, then delete.
Source Link
Jake Grossman
  • 1.7k
  • 1
  • 5
  • 16

Use <args> when referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1. 

I would also recommend saving the new file and then deleting the old file, just to be safe. You can do this by using # (the alternate file name) instead of % (the current file name) inside expand(). WhenAfter using saveas:saveas, the alternate file name is set to the the old file name.

command! -nargs=1 Move :saveas <args> | call delete(expand('#'))

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :saveas<bang> <args> | call delete(expand('#'))

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :saveas
:h :_#
:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

Use <args> when referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1. I would also recommend saving the new file and then deleting the old file, just to be safe. You can do this by using # instead of % inside expand(). When using saveas, the alternate file name is set to the the old file name.

command! -nargs=1 Move :saveas <args> | call delete(expand('#'))

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :saveas<bang> <args> | call delete(expand('#'))

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :saveas
:h :_#
:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

Use <args> when referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1. 

I would also recommend saving the new file and then deleting the old file, just to be safe. You can do this by using # (the alternate file name) instead of % (the current file name) inside expand(). After using :saveas, the alternate file name is set to the the old file name.

command! -nargs=1 Move :saveas <args> | call delete(expand('#'))

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :saveas<bang> <args> | call delete(expand('#'))

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :saveas
:h :_#
:h :command-nargs
:h <args>
:h :command-bang
:h <bang>
save, then delete.
Source Link
Jake Grossman
  • 1.7k
  • 1
  • 5
  • 16

To refer to the arguments you should useUse <args> insteadwhen referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1. I would also recommend saving the new file and then deleting the old file, just to be safe. You can do this by using # instead of % inside expand(). When using saveas, the alternate file name is set to the the old file name.

command! -nargs=1 Move :saveas <args> | call delete(expand('%''#')) | saveas <args>

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :saveas<bang> <args> | call delete(expand('%''#')) | saveas<bang> <args>

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :saveas
:h :_#
:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

To refer to the arguments you should use <args> instead. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1.

command! -nargs=1 Move :call delete(expand('%')) | saveas <args>

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :call delete(expand('%')) | saveas<bang> <args>

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

Use <args> when referencing command arguments. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1. I would also recommend saving the new file and then deleting the old file, just to be safe. You can do this by using # instead of % inside expand(). When using saveas, the alternate file name is set to the the old file name.

command! -nargs=1 Move :saveas <args> | call delete(expand('#'))

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :saveas<bang> <args> | call delete(expand('#'))

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :saveas
:h :_#
:h :command-nargs
:h <args>
:h :command-bang
:h <bang>
added 19 characters in body
Source Link
Jake Grossman
  • 1.7k
  • 1
  • 5
  • 16

To refer to the arguments you should use <args> instead. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1 instead.

command! -nargs=1 Move :call delete(expand('%')) | saveas <args>
 

YouOptionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :call delete(expand('%')) | saveas<bang> <args>

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

To refer to the arguments you should use <args> instead. Also, because you always want to pass one argument to your command (the new filename) you should use -nargs=1 instead.

command! -nargs=1 Move :call delete(expand('%')) | saveas <args>

You could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :call delete(expand('%')) | saveas<bang> <args>

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :command-nargs
:h <args>
:h :command-bang
:h <bang>

To refer to the arguments you should use <args> instead. <args> will expand to the arguments passed to the command. Also, while not strictly required, because you always want to pass one argument to your command (the new filename) you should probably use -nargs=1.

command! -nargs=1 Move :call delete(expand('%')) | saveas <args>
 

Optionally, you could expand this to use a ! in a way that is analogous to :w! (forcefully write) with the -bang option:

command! -nargs=1 -bang Move :call delete(expand('%')) | saveas<bang> <args>

In this case, <bang> will be expanded to ! if the command was executed with !, otherwise it will expand to nothing.


Relevant help:

:h :command-nargs
:h <args>
:h :command-bang
:h <bang>
Source Link
Jake Grossman
  • 1.7k
  • 1
  • 5
  • 16
Loading