Nishkarsh_Arora's blog

By Nishkarsh_Arora, history, 4 years ago, In English

Hello, Codeforces!! Many people ask for the best text editor for the programming contest. So, according to me vim is a great tool for competitive programming. It is not very comfortable to use it at first but after some time you will feel it is the best text editor ever made. So, I am going to help setup VIM(for windows) and make is ready to use for competitive programming.

WHY VIM??

I suggest, just try vim and you will get to know. But, if you are curious you can refer: https://medium.com/@fay_jai/what-is-vim-and-why-use-vim-54c67ce3c18e

You can download vim from https://www.vim.org/download.php, just download the Self-installing executable file, install it by keeping all the settings default.

Now, just launch Gvim from the start menu and you will enter a page where you would not be able to understand much but don't worry I am here to help you.

At the start, you will be in normal mode, just type :e ~\desktop\main.cpp, this will create a new file on your desktop(or if it already exists it will open it). To edit the document you have enter into insert mode(by pressing "i" key on your keyboard).

Initially, you will see a very ugly text.

But it can be improved an will look like this

For this, you have to make a _vimrc file in your home directory.

This is my _vimrc file, you can copy mine or can make your own...

syntax on
set noerrorbells
set tabstop=4 softtabstop=4
set smartindent
set smarttab
set autoindent
set cindent
set shiftwidth=4
set expandtab
set nu
set relativenumber
set ruler
set guifont=*
set backspace=indent,eol,start
set clipboard=unnamed
nnoremap <C-Right> :tabnext<CR>
nnoremap <C-Left> :tabprevious<CR>
autocmd filetype cpp nnoremap <F5> :w <bar> !g++ -std=c++17 -O2 -Wall % -o %:r && %:r.exe <CR>
set nocompatible              " be iMproved, required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'

" The following are examples of different formats supported.
" Keep Plugin commands between vundle#begin/end.
" plugin on GitHub repo
Plugin 'tpope/vim-fugitive'
" plugin from http://vim-scripts.org/vim/scripts.html
" Plugin 'L9'
" Git plugin not hosted on GitHub
Plugin 'git://git.wincent.com/command-t.git'
" git repos on your local machine (i.e. when working on your own plugin)
Plugin 'file:///home/gmarik/path/to/plugin'
" The sparkup vim script is in a subdirectory of this repo called vim.
" Pass the path to set the runtimepath properly.
Plugin 'rstacruz/sparkup', {'rtp': 'vim/'}
" Install L9 and avoid a Naming conflict if you've already installed a
" different version somewhere else.
" Plugin 'ascenator/L9', {'name': 'newL9'}
Plugin 'ycm-core/YouCompleteMe'
Plugin 'gruvbox-community/gruvbox'
Plugin 'vim-utils/vim-man'
Plugin 'sainnhe/gruvbox-material'
Plugin 'phanviet/vim-monokai-pro'
Plugin 'vim-airline/vim-airline'
Plugin 'flazz/vim-colorschemes'
Plugin 'ajh17/VimCompletesMe'
" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList       - lists configured plugins
" :PluginInstall    - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean      - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
let g:gruvbox_contrast_dark = 'hard'
if exists('+termguicolors')
    let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum"
    let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum"
endif
let g:gruvbox_invert_selection='0'

" --- The Greatest plugin of all time.  I am not bias
" let g:vim_be_good_floating = 0

" --- vim go (polyglot) settings.
let g:go_highlight_build_constraints = 1
let g:go_highlight_extra_types = 1
let g:go_highlight_fields = 1
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_operators = 1
let g:go_highlight_structs = 1
let g:go_highlight_types = 1
let g:go_highlight_function_parameters = 1
let g:go_highlight_function_calls = 1
let g:go_highlight_generate_tags = 1
let g:go_highlight_format_strings = 1
let g:go_highlight_variable_declarations = 1
let g:go_auto_sameids = 1

colorscheme gruvbox
set background=dark

Save this file by going into normal mode and typing :w, then type :source % and select your desired font.

You should also have git installed, to install plugins.

Now, you are almost done just follow some simple steps from this link(to install some useful plugins for visuals) https://github.com/VundleVim/Vundle.vim

Again type :source %, and you have the best setup for programming. Also, you can compile and run your file by just pressing F5.

You can also comment if you have any doubts. THANKS!!!

  • Vote: I like it
  • -16
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by Nishkarsh_Arora (previous revision, new revision, compare).

»
4 years ago, # |
Rev. 2   Vote: I like it -10 Vote: I do not like it

If you want to have some template loaded in a file every time you press some word, then you can do

nnoremap cpp :-1read FileLocation<CR> 

where "FileLocation" is the location of the file that holds your template on your PC. Then everytime that you type "cpp", then that template will be automatically loaded into that file.

Also if you want to preserve your last editing position inside a file paste

source $VIMRUNTIME/vimrc_example.vim

inside your vimrc

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Hey can you please help me with this template thing i am not able to do that.

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

How to run a c++ code in vim?

  • »
    »
    4 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    You have to add this command to your _vimrc file:

    autocmd filetype cpp nnoremap <F5> :w <bar> !g++ -std=c++17 -O2 -Wall % -o %:r && %:r.exe <CR>
    

    This map the compiling command to F5 key, now if you will press F5 in normal mode cmd will automatically open and you can enter your input.

»
4 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Where can I learn commands used in VIM ?

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

To use vim on Windows system I recommend installing it as part of Cygwin Cygwin is an environment for Windows systems which makes a lot of linux tools available. Among them vi of course, and gcc and bash.

»
2 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Nice! but, vim/vi is better in the terminal