For setting breakpoints, I was wondering if there is any way to copy the location of a line in a file opened in vim, to gdb rather than typing the whole file path and linenumber in the gdb shell?
Good, since you're using
tmux then you can use
send), a tmux command for inputting text into a different pane than the current one. You can call it from Vim using whatever data you need from there. For current (full) path and line number that would be
The following command will send those two strings (separated by
:) to the terminal in pane 3. The combined string will not be submitted (i.e. carriage return is not sent).
:exe "!tmux send -t 3 '" . expand("%:p") . ":" . line(".") . "'"
So with, for example, a file /tmp/foo.txt and line number 33 the tmux command that will be executed from the shell is:
tmux send -t 3 '/tmp/foo.txt:33'
If you want to submit the sent string in the target pane (i.e. by sending a carriage return) you just need to replace the last
-t param to
- In its simplest form, takes the target pane index as argument.
- If you are sending your command to another pane in the same window that's the only form we need to know. (Otherwise read the man page and/or ask me.)
- You can display pane indexes in the current window with tmux-prefix +
Obviously, if you're going to use this a lot you'll want to put it in a mapping and/or function. A mapping-only solution:
nnoremap XX :<C-U>exe "!tmux send -t " . v:count . " '" . expand("%:p") . " " . line(".") . "'"<CR>
XX with whatever unused key or key combo you want. Determine the target pane index (used by
-t) and, from Normal mode, type that number and then your
Though a little hard to read, the RHS of this isn't much more than the original
exe command plus:
- Insertion of the variable
v:countis a built-in variable that contains any number entered right before entering command-line mode (here that means the number entered before the the mapped key(s) are pressed).
<C-U>triggers Ctrl-U in order to clear the command line before we populate it. (Because when a number is entered right before entering command-line mode (
:) the command-line is prepopulated with a line range and we don't want that here.)
Alternatively, you could prompt the user for a pane index with a function+mapping. Something like:
func! BufferInfoToPane() let l:pidx = ...prompt code here... exe "!tmux send -t ".l:pidx." '".expand("%:p")." ".line(".")."'"<CR> endfunc
With the mapping:
nnoremap XX :call BufferInfoToPane()<CR>