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!
: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 :-)