Last active
July 15, 2022 19:35
-
-
Save atkvishnu/b79410db58d5ea5e645b29dff0a84325 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" VIM Configuration File | |
" Description: Optimized for C/C++ development for now. | |
" Author: Vishnu | |
" | |
" disable vi compatibility (emulation of old bugs - it's better to be safe than sorry) | |
set nocompatible | |
" use indentation of previous line | |
set autoindent | |
" use intelligent indentation for C | |
set smartindent | |
set smarttab | |
set encoding=utf-8 | |
" automatically write files when changing when multiple files opwn | |
set autowrite | |
" configure tabwidth and insert spaces instead of tabs | |
set tabstop=4 " tab width is 4 spaces | |
set shiftwidth=4 " indent also with 4 spaces | |
" set mouse+=a | |
" WSL yank support | |
let s:clip = '/mnt/c/Windows/System32/clip.exe' " change this path according to your mount point | |
if executable(s:clip) | |
augroup WSLYank | |
autocmd! | |
autocmd TextYankPost * if v:event.operator ==# 'y' | call system(s:clip, @0) | endif | |
augroup END | |
endif | |
" The following two lines solve the BCE issue described here: https://sunaku.github.io/vim-256color-bce.html | |
set term=screen-256color | |
set t_ut= | |
set background=dark | |
syntax on | |
" turn line numbers on | |
set number | |
" turn col and row position on in bottom right | |
set ruler | |
" highlight matching braces | |
set showmatch | |
" intelligent comments | |
set comments=sl:/*,mb:\ *,elx:\ */ | |
" disable relative line numbers, remove no to sample it | |
set norelativenumber | |
" highlight search hits | |
set hlsearch | |
set incsearch " incremental search: searches as you type( after /) | |
set linebreak | |
" Shows the keys being pressed on bottom right | |
set showcmd | |
au BufNewFile,BufRead,BufEnter *.cpp,*.hpp set omnifunc=omni#cpp#complete#Main | |
" Install OmniCppComplete like described on http://vim.wikia.com/wiki/C++_code_completion | |
" This offers intelligent C++ completion when typing ‘.’ ‘->’ or <C-o> | |
" Load standard tag files | |
set tags+=~/.vim/tags/cpp | |
" set tags+=~/.vim/tags/gl | |
" set tags+=~/.vim/tags/sdl | |
" set tags+=~/.vim/tags/qt4 | |
" Install DoxygenToolkit from http://www.vim.org/scripts/script.php?script_id=987 | |
let g:DoxygenToolkit_authorName="K Vishnu <atkumarvishnu@gmail.com>" | |
" Enhanced keyboard mappings | |
" | |
" in normal mode F2 will save the file | |
nmap <F2> :w<CR> | |
" in insert mode F2 will exit insert, save, enters insert again | |
imap <F2> <ESC>:w<CR>i | |
" switch between header/source with F4 | |
map <F4> :e %:p:s,.h$,.X123X,:s,.cpp$,.h,:s,.X123X$,.cpp,<CR> | |
" recreate tags file with F5 | |
map <F5> :!ctags -R –c++-kinds=+p –fields=+iaS –extra=+q .<CR> | |
" create doxygen comment | |
map <F6> :Dox<CR> | |
" build using makeprg with <F7> | |
map <F7> :make<CR> | |
" build using makeprg with <S-F7> | |
map <S-F7> :make clean all<CR> | |
" goto definition with F12 | |
map <C-F12> :!ctags -R --sort=yes --c++-kinds=+pl --fields=+iaS --extra=+q .<CR> | |
" <F9> to build and run | |
autocmd filetype python nnoremap <F4> :w <bar> exec '!python '.shellescape('%')<CR> | |
autocmd filetype c nnoremap <F9> :w <bar> exec '!gcc '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR> | |
autocmd filetype cpp nnoremap <F9> :w <bar> exec '!g++ '.shellescape('%').' -o '.shellescape('%:r').' && ./'.shellescape('%:r')<CR> | |
" Polyglot Individual language packs can be disabled from here! | |
" let g:polyglot_disabled = ['markdown'] | |
function! BuildYCM(info) | |
" info is a dictionary with 3 fields | |
" - name: name of the plugin | |
" - status: 'installed', 'updated', or 'unchanged' | |
" - force: set on PlugInstall! or PlugUpdate! | |
if a:info.status == 'installed' || a:info.force | |
!./install.py | |
endif | |
endfunction | |
" Specify a directory for plugins | |
" only load plugins if Plug detected | |
if filereadable(expand("~/.vim/autoload/plug.vim")) | |
" github.com/junegunn/vim-plu | |
call plug#begin('~/.local/share/vim/plugins') | |
" Polyglot is a collection of language packs for Vim | |
Plug 'sheerun/vim-polyglot' | |
" vim-pandoc provides pandoc document converter, allows us to work with documents written in its markdown variant | |
Plug 'vim-pandoc/vim-pandoc' | |
" plug for github | |
Plug 'tpope/vim-fugitive' | |
" a code-completion engine for Vim https://vimawesome.com/plugin/youcompleteme | |
Plug 'valloric/youcompleteme', { 'do': function('BuildYCM') } | |
" NERDTree is a file system explorer for the Vim editor https://vimawesome.com/plugin/nerdtree-red | |
Plug 'scrooloose/nerdtree' | |
" syntax checking hacks https://vimawesome.com/plugin/syntastic | |
" check if it's same as polyglot | |
Plug 'scrooloose/syntastic' | |
" Lean & mean status/tabline https://vimawesome.com/plugin/vim-airline-superman | |
Plug 'vim-airline/vim-airline' | |
" Comment functions so powerful—no comment necessary. https://vimawesome.com/plugin/the-nerd-commenter | |
Plug 'scrooloose/nerdcommenter' | |
" a class outline viewer https://vimawesome.com/plugin/tagbar | |
Plug 'majutsushi/tagbar' | |
" Seamless navigation between tmux panes and vim splits | |
Plug 'christoomey/vim-tmux-navigator' | |
" fuzzy finder https://vimawesome.com/plugin/fzf | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
" themes | |
Plug 'morhetz/gruvbox' | |
call plug#end() | |
" pandoc | |
let g:pandoc#formatting#mode = 'h' " A' | |
let g:pandoc#formatting#textwidth = 72 | |
else | |
autocmd vimleavepre *.go !gofmt -w % " backup if fatih fails | |
endif | |
let mapleader = "," | |
nnoremap <leader>n :NERDTreeFocus<CR> | |
nnoremap <C-n> :NERDTree<CR> | |
nnoremap <C-t> :NERDTreeToggle<CR> | |
nnoremap <C-f> :NERDTreeFind<CR> | |
nmap <F8> :TagbarToggle<CR> | |
" | |
set statusline+=%#warningmsg# | |
set statusline+=%{SyntasticStatuslineFlag()} | |
set statusline+=%* | |
let g:syntastic_always_populate_loc_list = 1 | |
let g:syntastic_auto_loc_list = 1 | |
let g:syntastic_check_on_open = 1 | |
let g:syntastic_check_on_wq = 0 | |
let g:syntastic_cpp_checkers = ['clang_check', 'gcc'] | |
" | |
" OmniCppComplete | |
let OmniCpp_NamespaceSearch = 1 | |
let OmniCpp_GlobalScopeSearch = 1 | |
let OmniCpp_ShowAccess = 1 | |
let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters | |
let OmniCpp_MayCompleteDot = 1 " autocomplete after . | |
let OmniCpp_MayCompleteArrow = 1 " autocomplete after -> | |
let OmniCpp_MayCompleteScope = 1 " autocomplete after :: | |
let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"] | |
" automatically open and close the popup menu / preview window | |
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif | |
set completeopt=menuone,menu,longest,preview | |
au BufLeave ~/.vimrc :source ~/.vimrc | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment