Reminder: in case of any technical issues, you can use the lightweight website m1.codeforces.com, m2.codeforces.com, m3.codeforces.com. ×

### dkp1024's blog

By dkp1024, history, 2 years ago, ,

If you are using vim for some time, maybe it will be helpful for new coders like me to know your .vimrc file?
Peace.

• +12

»
2 years ago, # |
+10

### standard vimrc

from /usr/share/vim/vimrc.

### mapping(copy current buffer)

nmap <leader>y ggVG"+y''

### useful plugins:

vim-surround (deal with parenthesis)

ultisnips and vim-snippets (code snippets)

 » 2 years ago, # |   +5 Open a new cpp file filled with a template of your choice . autocmd BufNewFile *.cpp -r ~/cp/template.cpp Autocomplete curly brackets inoremap { {}iki
•  » » 2 years ago, # ^ |   0 This does the wrong indentation, if you define a new global function. inoremap { {}O fixes and simplifies the command. (btw filetype indent on should be set for either commands to work).
 » 2 years ago, # |   +10 My .vimrc configuration.F5 — CompileF9 — Run
•  » » 2 years ago, # ^ |   0 Mine is F5 compile and run :) autocmd filetype cpp nnoremap :w !g++-4.8 -ulimit -Wall -Wno-unused-result -std=c++11 -O2 % -o %:r && ./%:r syntax on set nu set clipboard=unnamedplus set mouse=a set tabstop=2 set autoindent set shiftwidth=2 set softtabstop=2 set smarttab set expandtab set smartcase set t_Co=256 set background=dark colorscheme monokai autocmd filetype java nnoremap :w !javac % && java -enableassertions %:r autocmd filetype python nnoremap :w !python % autocmd filetype perl nnoremap :w !perl % autocmd filetype go nnoremap :w !go build % && ./%:r 
•  » » » 11 months ago, # ^ | ← Rev. 2 →   0 That looks really nice. I edited my .vimrc and took some ideas from yours, as well as those from above.You can check it out here.
•  » » » 3 months ago, # ^ |   0 i configured it by i. set tabstop=4 ii. set shiftwidth=4 iii. set expandtab but after submitting code in codeforces it still remains tab size 8. which command works to fix this problem?
•  » » » » 3 months ago, # ^ |   0 Maybe you wrote your template in another text editor or before you had configure vim spacing ?
 » 2 years ago, # | ← Rev. 4 →   +13 Actually there is not really much related to competitive programming in my vimrc. The only mentionable things are my plugins. YouCompleteMe: intelligent code completion, besides completing variable names, it will also complete functions from the STL and much more. E.g. writing v.pu and hitting tab will complete it to v.push_back if v is a vector, or to v.push if v is a stack. Besides completion, ycm will also check your code for errors and report them to you. So usually you won't get any compile errors, because you seen and corrected them already while writing the code. ultisnips: lots of short code snippets to make my life easier, my template, some long algorithms, ... E.g. inserting my codeforces template can be done with writing cf. Or reading four integers from stdin can be done with readin, m, k, test and ultisnips will expand it to int n, m, k, test; and cin >> n >> m >> k >> test; (Demonstration)vim-commentary: comment/uncomment linesConque-GDB: gdb inside vim. I'm not completely happy with it, and most of the time I just use the regular gdb. But that's probably only because so far I was too lazy to adjust a few settings for it.For my other setup (which might be interesting if you use linux): I additionally use tmux in combination with a few scripts. I've written a start script, that will download all test inputs/outputs of a specific codeforces problem, opens a special tmux session with vim inside. For this session I added a few commands, e.g. prefix t will open another pane, compiles my program, and runs it with each test input and compares the results with the outputs. So checking if my code works only takes one seconds. Here's a short demonstration.
•  » » 15 months ago, # ^ |   0 Can you share those scripts?
•  » » » 15 months ago, # ^ |   0 Sorry, but I don't think that I have the original scripts anymore.Nowadays I'm just using this vim plugin: cfparser.vim. It basically does the exact same things. E.g. you can download the test cases, compile and run the tests, and even submit the solution.The only change I made is, that I use this script for compiling and running the tests, as it gives a better overview over the tests and the results. To run this script with the default key combination, I created the file ~/.vim/after/plugin/cftest.sh with the line nnoremap cft :terminal cftest.sh %.
»
15 months ago, # |
0

#### Compile/Run C++

Save the document, clear console screen, show compile time, redirect compile errors to a file, show runtime, redirect stdin/stdout/stderr from file

nnoremap gb :w<CR>:!printf "\033c" && printf "================\n  Compiling...\n================\n" && time g++ -g -std=c++17 -Wall -Wextra -Wno-unused-result -D LOCAL -O2 %:r.cpp -o %:r 2>&1 \| tee %:r.cerr && printf "\n================\n   Running...\n================\n" && time ./%:r < %:r.in > %:r.out 2> %:r.err && printf "\n\n\n\n"<CR>


#### Some manual brace autocomplete

inoremap {[ {<CR>}<Esc>O
inoremap {; {<CR>};<Esc>O
inoremap {{ {<CR>}<CR><Esc>kO


#### Behave like Windows

CTRL+A selects all, CTRL+C and CTRL+V copy/paste to system clipboard, if +clipboard is enabled in Vim compile flags.

source \$VIMRUNTIME/mswin.vim
behave mswin

 » 11 months ago, # |   -6 Hi everyone, how to write default templates for C++ on Vim. Please help me I tried to google a lot on this, all I could find is https://github.com/tibabit/vim-templates which I am finding difficult to understand. Can someone guide me on this? Also if possible share some scripts for increasing efficiency while using Vim, and learning Vim fast :pThank you.
•  » » 11 months ago, # ^ | ← Rev. 2 →   -11 Also, I have tried this but I think it's outdated as I am not able to access my template in new files.
•  » » » 11 months ago, # ^ |   0 The beauty of CF. If I would have posted some meme there would have been lots of upvotes and responses. Here, a valid problem and there comes the downvotes. Keep it up CF!!
•  » » 6 months ago, # ^ |   0 If you still have this issue, here is how I do it. As someone mentioned before, you place this in your .vimrc file in your home folder. autocmd BufNewFile *.cpp -r /path/to/template.cpp You can change /path/to/template.cpp to wherever your template is stored on your drive.