Vi IMproved06 March 2014 · vim · text · editor Tweet
Vim is a text editor written by Bram
Moolenaar and first
released publicly in 1991. Based on
vi editor common to Unix-like
systems, it is designed for use both from a CLI and as a standalone
application in a GUI. However, I prefer the command line interface. It
is my weapon of choice for programming competitions and other everyday
stuff. Part of Vim's power is that it can be extensively customized.
Time is an important factor in programming competitions. Since I use C++
to code, it is difficult to write all the header files (although, we can
bits/stdc++.h) and other commonly used macros and functions again
and again. Too many ands. To overcome this, I've defined two files
.templatec.c for C and
.templatecpp.cpp for C++ in my
so that I can load them into a new *.c or *.cpp file using Vim.
The vimrc file contains optional runtime configuration settings to
initialize Vim when it starts. On Unix-based systems, the file is named
.vimrc. It is usually placed in the
$HOME folder. Here's mine.
autocmd! BufNewFile *.c silent! 0r /path/to/.templatec.c autocmd! BufNewFile *.cpp silent! 0r /path/to/.templatecpp.cpp set number set cindent set autoindent set expandtab set shiftwidth=4 set softtabstop=4 set pastetoggle=
set ruler set background=dark g:tex_flavor='latex' syntax on
The first two lines, as suggested earlier load the defined templates into a new file.
number: For displaying line number.
autoindent: For automatic indentation.
softtabstop: Define how much the cursor will jump on hitting the
F2key can be used to toggle the paste mode. Pasted code will retain it's indentation.
syntax on: For syntax highlighting.