Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Minimal .vimrc for C/C++ developers
" VIM Configuration File
" Description: Optimized for C/C++ development, but useful also for other things.
" Author: Gerhard Gappmeier
"
" set UTF-8 encoding
set enc=utf-8
set fenc=utf-8
set termencoding=utf-8
" disable vi compatibility (emulation of old bugs)
set nocompatible
" use indentation of previous line
set autoindent
" use intelligent indentation for C
set smartindent
" 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 expandtab " expand tabs to spaces
" wrap lines at 120 chars. 80 is somewaht antiquated with nowadays displays.
set textwidth=120
" turn syntax highlighting on
set t_Co=256
syntax on
" colorscheme wombat256
" turn line numbers on
set number
" highlight matching braces
set showmatch
" intelligent comments
set comments=sl:/*,mb:\ *,elx:\ */
" 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="John Doe <john@doe.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 <F12> <C-]>
" in diff mode we use the spell check keys for merging
if &diff
diff settings
map <M-Down> ]c
map <M-Up> [c
map <M-Left> do
map <M-Right> dp
map <F9> :new<CR>:read !svn diff<CR>:set syntax=diff buftype=nofile<CR>gg
else
" spell settings
:setlocal spell spelllang=en
" set the spellfile - folders must exist
set spellfile=~/.vim/spellfile.add
map <M-Down> ]s
map <M-Up> [s
endif
@wiekern

This comment has been minimized.

Copy link

@wiekern wiekern commented Apr 25, 2013

Which is the best background color with this config?

@Dex-Electronics

This comment has been minimized.

Copy link

@Dex-Electronics Dex-Electronics commented Sep 17, 2013

Many thanks!

@tommymcdonald

This comment has been minimized.

Copy link

@tommymcdonald tommymcdonald commented Mar 10, 2014

Wonderful setup, thanks for this!

@BarronKane

This comment has been minimized.

Copy link

@BarronKane BarronKane commented Jan 21, 2015

The simplicity is wonderful... @yefeiyan, ignoring the fact that this is a necro reply, and as solarized is over-hyped imo, I use jellybeans or Monokai.

@syddo

This comment has been minimized.

Copy link

@syddo syddo commented Sep 28, 2015

I'm having an error during loading saying unknown option spell.

@utkjad

This comment has been minimized.

Copy link

@utkjad utkjad commented Nov 2, 2015

Thanks. This is a good start!

@sxu2583

This comment has been minimized.

Copy link

@sxu2583 sxu2583 commented Sep 5, 2016

I like it nice

@snaami

This comment has been minimized.

Copy link

@snaami snaami commented Apr 13, 2017

great work , i really like it , thanks ! :)

@miladbazisaz

This comment has been minimized.

Copy link

@miladbazisaz miladbazisaz commented May 1, 2017

i love it

@jflopezfernandez

This comment has been minimized.

Copy link

@jflopezfernandez jflopezfernandez commented Jun 5, 2017

Awesome, works great, thank you very much

@mark-lvl

This comment has been minimized.

Copy link

@mark-lvl mark-lvl commented Jun 16, 2017

Useful setup for all, specifically for C programmers. Thanks.

@aasutossh

This comment has been minimized.

Copy link

@aasutossh aasutossh commented Jul 27, 2017

It feels awesome, thanks for the work.

@0xnandhi

This comment has been minimized.

Copy link

@0xnandhi 0xnandhi commented Aug 2, 2017

Thanks :)

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Mar 22, 2018

Thanks :)

@fonkamloic

This comment has been minimized.

Copy link

@fonkamloic fonkamloic commented May 13, 2018

Many Thanks 👍

@j3rg

This comment has been minimized.

Copy link

@j3rg j3rg commented Sep 7, 2018

Thanks buddy!!

@ReflectionDesire

This comment has been minimized.

Copy link

@ReflectionDesire ReflectionDesire commented Sep 16, 2018

Thanks a lot

@gozeloglu

This comment has been minimized.

Copy link

@gozeloglu gozeloglu commented Nov 14, 2018

How can I setup on my Linux computer? I do not want to make any mistake

@hao-lee

This comment has been minimized.

Copy link

@hao-lee hao-lee commented Nov 21, 2018

This is awesome! Thanks!

@mruthyunjayam

This comment has been minimized.

Copy link

@mruthyunjayam mruthyunjayam commented Dec 29, 2019

Thanks.. its Very nice.

@rajatkumarv

This comment has been minimized.

Copy link

@rajatkumarv rajatkumarv commented Jan 15, 2020

Thanks.
It helps. It is working without any issue on WSL linux 18.04 LTS.

@im-vicky

This comment has been minimized.

Copy link

@im-vicky im-vicky commented Mar 9, 2020

Thanks a lot

@anisyanka

This comment has been minimized.

Copy link

@anisyanka anisyanka commented Nov 9, 2020

Awesome!
Thank you!

P.S.
It seems there is small typo in 20th line: somewaht --> somewhat

@abhishekk06

This comment has been minimized.

Copy link

@abhishekk06 abhishekk06 commented Feb 18, 2021

Hi

Any idea how can I disable highlight (I only want my searched pattern to get highlighted). For some reason, few keywords in my code are getting highlight by default.

@wesleymesquita

This comment has been minimized.

Copy link

@wesleymesquita wesleymesquita commented Mar 14, 2021

Thank you! Simplicity is the key! Regards

@sachinites

This comment has been minimized.

Copy link

@sachinites sachinites commented Apr 5, 2021

Hi

Any idea how can I disable highlight (I only want my searched pattern to get highlighted). For some reason, few keywords in my code are getting highlight by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment