I'm new to vim and I'm trying to setup my environment for c++ development, and I want to configure vim in a way that like vscode, if I push f5 key, It would compile the program in the existing tmux pane in same window. Thanks!

1 Answer 1


Using :make is the standard way to compile stuff in Vim; you can map that to e.g. F5 with something like:

nnoremap <F5> :silent! :wa<CR>:make<CR>

I personally like to write all the files first; adjust according to preferences (I actually have it mapped to MM, which is a bit more convenient IMO).

You can call tmux from this as well, if you want:

:let &makeprg = "tmux send-keys -t '=myproj:=make.2' make Enter"

Although, arguably, using :make with tmux like that doesn't make too much sense, since there will never be any compiler errors to show in the quickfix window, so you can also just map it:

:nnoremap <F5> :!tmux send-keys -t 'myproj:make.2' make Enter<CR>

I'm not going to go in details on how tmux scripting works; tmux(1) is very useful, and I also wrote a small Scripting tmux article a while ago which may be of interest.

I would recommend looking in to :make though, since you get the quickfix window so you can easily jump to errors and the like.

Note that Vim also comes with :terminal now, which may be preferable over tmux panes. There are also many plugins which enhance :make with all sorts of things, and there probably is a tmux plugin or the like as well. This is just a simple non-automagic solution :-)

  • 1
    Fun facts: Dispatch has a Make command which runs the build in a separate tmux pane but correctly loads the quickfix list
    – D. Ben Knoble
    Mar 26, 2020 at 12:46
  • Hi! That's perfect! But when I push f5 it says: error connecting to /tmp/tmux-1000/default (No such file or directory) shell returned 1 Press ENTER or type command to continue
    – Aidin
    Apr 11, 2020 at 8:21
  • Looks like tmux isn't running yet @Aidin? Apr 11, 2020 at 9:08

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.