Skip to content

Instantly share code, notes, and snippets.

@shreewatsa
Created February 23, 2023 04:57
Show Gist options
  • Save shreewatsa/872e75bd78c70497fe137fb9f8f82ff6 to your computer and use it in GitHub Desktop.
Save shreewatsa/872e75bd78c70497fe137fb9f8f82ff6 to your computer and use it in GitHub Desktop.
Competitive Programming Essentials

VIM Configuration :

Requirements: $brew install g++ gdb coreutils;

map <C-s>       = :w<cr>                                           " save file  
map <S-Left>    = :!gdb ./%:r <CR>                                 " Debug  
map <S-Down>    = :!g++-12 -std=c++14 -g % -o %:r<CR>              " build only  
map <S-Up>      = :!./%:r <CR>                                     " run only.  
map <S-Right>   = :!g++-12 -std=c++14 -g % -o %:r && gtimeout 4s ./%:r <CR>                             " build and run.  
" map <S-Right> = :!g++-12 -std=c++14 -g % -o %:r && gtimeout 4s ./%:r < input.txt > output.txt <CR>    " build and run.  

Debugging workflow using gdb :

$gdb ./a.out;

break 10 <CR>  : puts breakpoint at line 10.
Usage:
  break [filename]:line_number
  break [filename]:function_name

run [args]


c     : continue
n     : next / step over
s     : step in
p     : print, Usage: p <variable name> , …..
l     : list (print the source code) Usage: l <linenumber> , l <function name>
ENTER : execute previous command again.
bt    : backtrace ie print backtrace of all stack frames
help <topicname>
quit <CR>

Untested :

Load template in vim: autocmd BufNewFile *.cpp execute "0r ~/.vim/template/".input("Template name: ").".cpp"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment