If you are using vim for some time, maybe it will be helpful for new coders like me to know your .vimrc file?
Peace.
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 150 |
Name |
---|
standard vimrc
from /usr/share/vim/vimrc.
mapping(copy current buffer)
nmap <leader>y ggVG"+y''
useful plugins:
vim-surround
(deal with parenthesis)ultisnips
andvim-snippets
(code snippets)Open a new cpp file filled with a template of your choice .
autocmd BufNewFile *.cpp -r ~/cp/template.cpp
Autocomplete curly brackets
inoremap {<CR> {<CR>}<Esc>i<CR><Esc>ki<Tab><Tab>
This does the wrong indentation, if you define a new global function.
inoremap {<CR> {<CR>}<ESC>O
fixes and simplifies the command. (btwfiletype indent on
should be set for either commands to work).My .vimrc configuration.
F5 — Compile
F9 — Run
Mine is F5 compile and run :)
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?
Maybe you wrote your template in another text editor or before you had configure vim spacing ?
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. writingv.pu
and hitting tab will complete it tov.push_back
ifv
is a vector, or tov.push
ifv
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 writingcf<C-J>
. Or reading four integers from stdin can be done withreadi<C-J>n, m, k, test<C-J>
and ultisnips will expand it toint n, m, k, test;
andcin >> 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.Can you share those scripts?
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 linennoremap <Leader>cft :terminal cftest.sh %<CR>
.hey can you please share how to read multiple inputs like this using ultisnips?
https://pastebin.com/taThf3vr
Besides reading multiple inputs, it additionally supports autocompletion for common types like
int
,long long
, or evenpair<long long, long long>
. E.g. you can pressread<C-J>pair<l<C-J>a, b<C-J>
and it expands topair<long long, long long> a, b; cin >> a.first >> a.second >> b.first >> b.second;
. It will actually show you the possible completions in real time, once there is only one completion, it you can press<C-J>
to accept it.If you don't need the completion or the support for pairs, you can probably get rid of most of the code, and just use a transformation that converts
,
into>>
. Something like the following (note: I haven't tested it): https://pastebin.com/1P1Ayy6jCompile/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
Some manual brace autocomplete
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.
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 :p
Thank you.
Also, I have tried this but I think it's outdated as I am not able to access my template in new files.
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!!
I upvoted you ...don't cry
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.
You can change
/path/to/template.cpp
to wherever your template is stored on your drive.Vim like VSCode Got inspired during lockdown and I learnt vim during this time. Here is a link to my neovim config files and you can see the finished config is something really close to VSCode. I spent 2 days learning and making this for NeoVim. If anyone is interested check it out on the given link. https://github.com/AnmolTomer/vim
If you like vscode just use vscode! lol