I want to map a key to the system command

`tmux set-buffer $var`

where $var is the value of @0 register. How do i insert the @0 value into the map command

map <leader>t :!tmux set-buffer @0

1 Answer 1


You can use :execute {expr1} to execute a string from evaluation of {expr1} as an Ex command.

:exec "!tmux set-buffer" getreg("0")

will first combine the string !tmux set-buffer with the results of getreg("0"), adding a space in between, and then execute the resulting command. Presumably you want this only in normal mode, so it is advisable to use nnoremap instead of map as well.

The mapping itself should be

nnoremap <leader>t :exec "!tmux set-buffer" getreg("0")<CR>
  • 3
    You can also just use @0 instead of the getreg() function. Jun 18, 2015 at 14:50

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.