I'd like to write commands that work with :tab and :vert. Say I have a command that opens a new split window as shown below

function! FooSplit()
    let l:message="hello world"
    put! =l:message
command! -complete=command Foo call FooSplit()

I'd like it to make it so that :tab Foo and :vert Foo will open in a new tab and vertical split respectively.

1 Answer 1


You can use :h <mods> to do this, it expands to modifier or nothing. It's added at patch 7.4.1898

command Foo call FooSplit(<q-mods>)

function FooSplit(mods)
  exe a:mods 'new'

Above example use <q-mods> instead of <mods>, as you need it as a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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