While using Termdebug, occasionally it would be useful to pass extra arguments to gdb (for example, -x).

I've tried :Termdebug -x <my_file> <command_to_debug>, but that just seems to confuse the plugin. I've also tried the less convenient :let termdebugger = "gdb -x <my_file>" before invoking Termdebug, with similarly poor results.

Is there any way to do this?

  • 1
    Termdebug -x ... works fine for me, my script contains only run, the culprit might be something in your <my_file> ?
    – dedowsdi
    May 23, 2020 at 0:20
  • Well, it works when I run gdb -x <my_file> <command_to_debug> outside vim, and it works when I do source <my_file> inside the Termdebug window (which has been my workaround), so I think the file is okay. When I try Termdebug -x ..., it looks like it's going into Termdebug for a split second before immediately leaving, as if gdb might be exiting immediately. May 24, 2020 at 0:06
  • 1
    gdb argument support is added at patch 8.0.1713, make sure your vim is new enough.
    – dedowsdi
    May 24, 2020 at 1:08
  • Ah, that explains it. Thanks. May 24, 2020 at 1:47
  • I turned that comment into an answer, you may accept it if it solved your problem.
    – dedowsdi
    May 28, 2020 at 13:01

1 Answer 1


gdb argument support is added at patch 8.0.1713:

Termdebug [gdb-args] command

command argument support is added at patch 8.0.1725:

TermdebugCommand command [command-args]

Additionally, once TermDebug is loaded you may also pass any command from Vim to GDB since patch 8.1.0071 using a function:

call TermDebugSendCommand(gdb-command)

Examples for each of those with sourcing the script as asked in the question:

Termdebug -x <my_file> <command_to_debug>

Termdebug <command_to_debug>
call TermDebugSendCommand('source <my_file>')

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.