This is a vim plugin to help you run a cpp file with a keystroke. It's designed to take input from a input.txt and put the output in output.txt in a local folder. This is especially helpful for competitive coding.
- A key is triggered.
- All the buffers are saved.
- The buffer with .cpp extension is passed on to a makefile.
- A template makefile is copied from the plugin directory to the local directory.
- The .cpp file is compiled by the makefile recipe.
- The run command is also invoked in the makefile.
- If there are no inputs in the program, it directly writes to the output.txt .
- vim-localrc. Any local-vimrc tool can be used. However, you can skip the above step if you are not acquainted with working with vim Plugins.
- rsync
Install using
sudo apt-get install rsync
for debian based. Look up the command for your distro. - vim-autoread For enabling autoread for all tabs in the buffer.
- vim-easy-align This outputs all the unecessary output commands in a virtual shell, saving the main screen from clutter.
- Using Plugin Manager
- Recommended to use Vundle
- add
Plugin 'suraj-2306/cc_vim'
to your vimrc
- Manual Installation
- Download the zip file and extract it to the ~/.vim directory. Merge the 'plugin' directory from the cc_vim plugina and the one in the .vim directory. Similarly merge the autoload directory, if it exists.
-
Install the above dependencies.
-
Using the local.vimrc
- Add the following command
autocmd VimEnter *.cpp :vsp input.txt |vertical resize 40| split output.txt
to your .local.vimrc or any other local vimrc Plugin you have used. - If you are comfortable working with buffers, ignore the above step
- Add the following command
-
If your are not using a local vimrc plugin,
- Add the following lines to your .vimrc
autocmd VimEnter *.cpp :vsp input.txt |vertical resize 40| split output.txt
. This basically splits your screen into 3 sections to accomadate output.txt, input.txt and the .cpp file buffers. The only disadvantage by adding this in the .vimrc folder over a local .vimrc is that, every time your're opening a .cpp file you will have the this congiguration
- Add the following lines to your .vimrc
-
Opening format
- Open a terminal window, navigate to your directory and type
vim example.cpp
. This setup must show up - If you're not using 2.a then use
vim example.cpp output.txt input.txt
to open the files as buffers.
- Open a terminal window, navigate to your directory and type
-
Press F9 key to trigger the plugin. It automatically compiles your example.cpp file and creates a example.out as an executable. This also run the .out file.
- It may show up an error if you have more than one cc_vim.makefile in your .vim directory. Delete the other copies and make sure you have only one copy.