If suppose my source code file name is "foo.c".
While editing and debugging i always execute this command:-
:!gcc -g foo.c -o foo;gdb foo
Can I add a custom command to Vim such that If i type ":debug" then the above command executes?
How do I achieve that?
Yes. Vim documentation, section 40.2, Command-line mappings:
Put that line in your
~/.vimrc(minus the inital
:of course) and it will be defined every time you start vim. Also, use
%:tto make reference to the file being edited (writing
! gcc %:tgets replaced by
! gcc foo.c).
If you'd only like it to be defined for the one file, or for certain files, you want an autocommand.