2

When I have multiple files in the argument list, can I rearrange the order of the list?

For example

:args
 [A.md] B.md C.md D.md E.md F.md

is there a command/series of commands that gives me

:args
 [A.md] F.md C.md D.md E.md B.md

Why is ask I have a key binding for :next and :prev and it would be used full to move the files next to each other so I don't have to press the keybinding mutiple times.

2
$ touch {A,B,C,D,E,F}.md
$ vim *.md
:redir => current_args
:silent args
:redir END
:let current_args =  substitute(current_args, 'F', 'B', '')
:let current_args =  substitute(current_args, 'B', 'F', '')
:exe "args ".substitute(current_args, '[\n\r[\]]', '', 'g')

First you can use :args to retrieve the current list of arguments, and :redir to capture it to a variable. After you manipulate the variable contents, use :args {arglist} to set the modified arglist.

Note that the output of :args contains square brackets and newlines, which must be removed before it is used set the new arglist.

| improve this answer | |
  • 1
    In case you do not want to use :redir, you can use something like map(range(argc()), 'argv(v:val)') to get the arglist as list. – Peter Rincker Dec 1 '15 at 17:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.