set fde=getline(v\:lnum)=~'^\"\"'?'>'.(matchend(getline(v\:lnum),'\"\"*')-2)\:'=' set encoding=utf-8 " set UTF-8 encoding set fenc=utf-8 set termencoding=utf-8 " 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 " c++ autocmd filetype cpp nnoremap :w !g++ -std=c++11 % -o %:r -Wl,--stack,268435456 autocmd filetype cpp nnoremap :!%:r autocmd filetype cpp nnoremap :s/^\(\s*\)/\1\/\/ :s/^\(\s*\)\/\/\/\//\1 $ autocmd filetype cpp nnoremap :w !C:\\Borland\\BCC55\Bin\\bcc32 % " vim customized shortcut imap jk if has('gui_running') set guifont=Source\ Code\ Pro\ for\ Powerline:h15:cANSI set t_Co=256 set guioptions-=m "remove menu bar set guioptions-=T "remove toolbar set guioptions-=r "remove right-hand scroll bar set guioptions-=L "remove left-hand scroll bar colorscheme molokai let g:airline_theme = 'luna' set cursorline hi CursorLine cterm=NONE ctermbg=lightyellow hi CursorColumn cterm=NONE ctermbg=lightyellow nnoremap c :set cursorline! cursorcolumn! set lines=22 columns=70 autocmd GUIEnter * set vb t_vb= endif :cd F:\code\ " -- bootstrap ----------------------------------------------------------------- set encoding=utf-8 " set vim encoding to UTF-8 set nocompatible " the future is now, use vim defaults instead of vi ones set nomodeline " disable mode lines (security measure) set history=1000 " boost commands and search patterns history set undolevels=1000 " boost undo levels if exists("+shellslash") set shellslash " expand filenames with forward slash endif set timeoutlen=500 " time in milliseconds for a key sequence to complete let mapleader="," " change leader key to , let maplocalleader="," " change local leader key to , " ev edits .vimrc nnoremap ev :vsplit $MYVIMRC " sv sources .vimrc nnoremap sv :source $MYVIMRC:redraw:echo $MYVIMRC 'reloaded' " -- ConEmu integration -------------------------------------------------------- if !empty($CONEMUBUILD) set term=xterm set t_Co=256 let &t_AB="\e[48;5;%dm" let &t_AF="\e[38;5;%dm" endif " -- tmux integration ---------------------------------------------------------- " make arrow keys, home/end/pgup/pgdown, and function keys work when inside tmux if exists('$TMUX') && (system("tmux show-options -wg xterm-keys | cut -d' ' -f2") =~ '^on') " tmux will send xterm-style keys when its xterm-keys option is on " add 'setw -g xterm-keys on' to your ~/.tmux.conf execute "set =\e[1;*A" execute "set =\e[1;*B" execute "set =\e[1;*C" execute "set =\e[1;*D" execute "set =\e[1;*H" execute "set =\e[1;*F" execute "set =\e[2;*~" execute "set =\e[3;*~" execute "set =\e[5;*~" execute "set =\e[6;*~" execute "set =\e[1;*P" execute "set =\e[1;*Q" execute "set =\e[1;*R" execute "set =\e[1;*S" execute "set =\e[15;*~" execute "set =\e[17;*~" execute "set =\e[18;*~" execute "set =\e[19;*~" execute "set =\e[20;*~" execute "set =\e[21;*~" execute "set =\e[23;*~" execute "set =\e[24;*~" endif " -- backup and swap files " -----------------------------------------------------{ set backup " enable backup files set writebackup " enable backup files set swapfile " enable swap files (useful when loading huge files) let s:vimdir=$HOME . "/.vim" let &backupdir=s:vimdir . "/backup" " backups location let &directory=s:vimdir . "/tmp" " swap location if exists("*mkdir") if !isdirectory(s:vimdir) call mkdir(s:vimdir, "p") endif if !isdirectory(&backupdir) call mkdir(&backupdir, "p") endif if !isdirectory(&directory) call mkdir(&directory, "p") endif endif set backupskip+=*.tmp " skip backup for *.tmp if has("persistent_undo") let &undodir=&backupdir set undofile " enable persistent undo endif let &viminfo=&viminfo . ",n" . s:vimdir . "/.viminfo" " viminfo location " -- file type detection ------------------------------------------------------- filetype on " /!\ doesn't play well with compatible mode filetype plugin on " trigger file type specific plugins filetype indent on " indent based on file type syntax " -- command mode -------------------------------------------------------------- set wildmenu " enable tab completion menu set wildmode=longest:full,full " complete till longest common string, then full set wildignore+=.git " ignore the .git directory set wildignore+=*.DS_Store " ignore Mac finder/spotlight crap if exists ("&wildignorecase") set wildignorecase endif " sudo then write cabbrev w!! w !sudo tee % >/dev/null " CTRL+A moves to start of line in command mode cnoremap " CTRL+E moves to end of line in command mode cnoremap " CTRL+C closes the command window if has("autocmd") augroup command autocmd! autocmd CmdwinEnter * noremap :q augroup END endif " -- display ------------------------------------------------------------------- set title " change the terminal title set lazyredraw " do not redraw when executing macros set report=0 " always report changes set cursorline " highlight current line if has("autocmd") augroup vim autocmd! autocmd filetype vim set textwidth=80 augroup END augroup windows autocmd! autocmd VimResized * :wincmd = " resize splits when the window is resized augroup END endif if has("gui_running") set cursorcolumn " highlight current column endif if exists("+relativenumber") if v:version >= 400 set number endif set relativenumber " show relative line numbers set numberwidth=3 " narrow number column " cycles between relative / absolute / no numbering if v:version >= 400 function! RelativeNumberToggle() if (&number == 1 && &relativenumber == 1) set nonumber set relativenumber relativenumber? elseif (&number == 0 && &relativenumber == 1) set norelativenumber set number number? elseif (&number == 1 && &relativenumber == 0) set norelativenumber set nonumber number? else set number set relativenumber relativenumber? endif endfunc else function! RelativeNumberToggle() if (&relativenumber == 1) set number number? elseif (&number == 1) set nonumber number? else set relativenumber relativenumber? endif endfunc endif nnoremap n :call RelativeNumberToggle() else " fallback set number " show line numbers " inverts numbering nnoremap n :set number! number? endif set nolist " hide unprintable characters if has("multi_byte") " if multi_byte is available, set listchars=eol:¬,tab:▸\ ,trail:⌴ " use pretty Unicode unprintable symbols else " otherwise, set listchars=eol:$,tab:>\ ,trail:. " use ASCII characters endif " temporarily disable unprintable characters when entering insert mode if has("autocmd") augroup list autocmd! autocmd InsertEnter * let g:restorelist=&list | :set nolist autocmd InsertLeave * let &list=g:restorelist augroup END endif " inverts display of unprintable characters nnoremap l :set list! list? set noerrorbells " shut up set visualbell t_vb= " use visual bell instead of error bell set mousehide " hide mouse pointer when typing if exists("+showtabline") set showtabline=1 " only if there are at least two tabs (default) endif if has("statusline") function! StatusLineUTF8() try let p = getpos('.') redir => utf8seq sil normal! g8 redir End call setpos('.', p) return substitute(matchstr(utf8seq, '\x\+ .*\x'), '\<\x\x', '0x\U&', 'g') catch return '?' endtry endfunction function! StatusLineFileEncoding() return has("multi_byte") && strlen(&fenc) ? &fenc : '' endfunction function! StatusLineUTF8Bomb() return has("multi_byte") && &fenc == 'utf-8' && &bomb?'+bomb' : '' endfunction function! StatusLineCWD() let l:pwd = exists('$PWD') ? $PWD : getcwd() return substitute(fnamemodify(l:pwd, ':~'), '\(\~\?/[^/]*/\).*\(/.\{20\}\)', '\1...\2', '') endfunction set laststatus=2 " always show a status line " set exact status line format set statusline= set statusline+=%#Number# set statusline+=❐\ %02n " buffer number set statusline+=\ \|\ " separator set statusline+=%* set statusline+=%#Identifier# set statusline+=%f " file path relative to CWD set statusline+=%* set statusline+=%#Special# set statusline+=%m " modified flag set statusline+=%#Statement# set statusline+=%r " readonly flag set statusline+=%h " help buffer flag set statusline+=%w " preview window flag set statusline+=%#Type# set statusline+=[%{&ff}] " file format set statusline+=[ set statusline+=%{StatusLineFileEncoding()} " file encoding set statusline+=%#Error# set statusline+=%{StatusLineUTF8Bomb()} " UTF-8 bomb alert set statusline+=%#Type# set statusline+=] set statusline+=%y " type of file set statusline+=\ \|\ " separator set statusline+=%* set statusline+=%#Directory# set statusline+=%{StatusLineCWD()} " current working directory set statusline+=\ " separator set statusline+=%* set statusline+=%= " left / right items separator set statusline+=%#Comment# set statusline+=%{v:register} " current register in effect set statusline+=\ " separator set statusline+=%#Statement# set statusline+=[U+\%04B] " Unicode code point set statusline+=[%{StatusLineUTF8()}] " UTF8 sequence set statusline+=\ \|\ " separator set statusline+=%#Comment# set statusline+=line\ %5l/%L\ " line number / number of lines set statusline+=●\ %02p%%,\ " percentage through file set statusline+=col\ %3v " column number endif set showcmd " show partial command line (default) set cmdheight=1 " height of the command line set shortmess=astT " abbreviate messages set shortmess+=I " disable the welcome screen if (&t_Co > 2 || has("gui_running")) && has("syntax") syntax on " turn syntax highlighting on, when terminal has colors or in GUI endif if has("gui_running") " GUI mode set guioptions-=T " remove useless toolbar set guioptions+=c " prefer console dialogs to popups endif " ease reading in GUI mode by inserting space between lines set linespace=2 if has("folding") set foldenable " enable folding set foldmethod=syntax " fold based on syntax highlighting set foldlevelstart=99 " start editing with all folds open " filetype settings --- {{{ " Vimscript file settings ---------------------- {{{ augroup filetype_vim autocmd! autocmd FileType vim setlocal foldmethod=marker softtabstop=2 shiftwidth=2 expandtab augroup END " }}} " toggle folds nnoremap za vnoremap za set foldtext=FoldText() function! FoldText() let l:lpadding = &fdc redir => l:signs execute 'silent sign place buffer='.bufnr('%') redir End let l:lpadding += l:signs =~ 'id=' ? 2 : 0 if exists("+relativenumber") if (&number) let l:lpadding += max([&numberwidth, strlen(line('$'))]) + 1 elseif (&relativenumber) let l:lpadding += max([&numberwidth, strlen(v:foldstart) + strlen(v:foldstart - line('w0')), strlen(v:foldstart) + strlen(line('w$') - v:foldstart)]) + 1 endif else if (&number) let l:lpadding += max([&numberwidth, strlen(line('$'))]) + 1 endif endif " expand tabs let l:start = substitute(getline(v:foldstart), '\t', repeat(' ', &tabstop), 'g') let l:end = substitute(substitute(getline(v:foldend), '\t', repeat(' ', &tabstop), 'g'), '^\s*', '', 'g') let l:info = ' (' . (v:foldend - v:foldstart) . ')' let l:infolen = strlen(substitute(l:info, '.', 'x', 'g')) let l:width = winwidth(0) - l:lpadding - l:infolen let l:separator = ' … ' let l:separatorlen = strlen(substitute(l:separator, '.', 'x', 'g')) let l:start = strpart(l:start , 0, l:width - strlen(substitute(l:end, '.', 'x', 'g')) - l:separatorlen) let l:text = l:start . ' … ' . l:end return l:text . repeat(' ', l:width - strlen(substitute(l:text, ".", "x", "g"))) . l:info endfunction endif " highlight SCM merge conflict markers match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' " -- buffers ------------------------------------------------------------------- set nobomb " don't clutter files with Unicode BOMs set hidden " enable switching between buffers without saving set switchbuf=usetab " switch to existing tab then window when switching buffer set autoread " auto read files changed only from the outside of ViM if has("persistent_undo") && (&undofile) set autowriteall " auto write changes if persistent undo is enabled endif set fsync " sync after write set confirm " ask whether to save changed files if has("autocmd") augroup trailing_spaces autocmd! "autocmd BufWritePre * :%s/\s\+$//e " remove trailing spaces before saving augroup END augroup restore_cursor " restore cursor position to last position upon file reopen autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | execute "normal! g`\"" | endif augroup END endif " cd to the directory of the current buffer nnoremap cd :cd %:p:h " switch between last two files nnoremap " w writes the whole buffer to the current file nnoremap w :w! inoremap w :w! " W writes all buffers nnoremap W :wa! inoremap W :wa! " -- navigation ---------------------------------------------------------------- " scroll slightly faster nnoremap 2 nnoremap 2 map map set startofline " move to first non-blank of the line when using PageUp/PageDown " scroll by visual lines, useful when wrapping is enabled nnoremap j gj nnoremap gj nnoremap k gk nnoremap gk set scrolljump=1 " minimal number of lines to scroll vertically set scrolloff=4 " number of lines to keep above and below the cursor " typing zz sets current line at the center of window set sidescroll=1 " minimal number of columns to scroll horizontally set sidescrolloff=4 " minimal number of columns to keep around the cursor if has("vertsplit") " split current window vertically nnoremap _ vl set splitright " when splitting vertically, split to the right endif if has("windows") " split current window horizontally nnoremap - s set splitbelow " when splitting horizontally, split below endif " window navigation nnoremap h nnoremap j nnoremap k nnoremap l " move cursor wihout leaving insert mode try redir => s:backspace silent! execute 'set ' 't_kb?' redir END if s:backspace !~ '\^H' inoremap h inoremap j inoremap k inoremap l endif finally redir END endtry " switch between windows by hitting twice nnoremap w " window resizing map < map - map + map > " q quits the current window nnoremap q :q inoremap q :q " create a new tab nnoremap t :tabnew " next/previous buffer navigation nnoremap :bnext nnoremap :bprev set whichwrap=b,s,<,> " allow cursor left/right key to wrap to the " previous/next line " omit [,] as we use virtual edit in insert mode " disable arrow keys " nnoremap :echo "arrow keys disabled, use h" " nnoremap :echo "arrow keys disabled, use l" " nnoremap :echo "arrow keys disabled, use k" " nnoremap :echo "arrow keys disabled, use j" " move to the position where the last change was made noremap gI `. " by default, 'a jumps to line marked with ma " while `a jumps to line AND column marked with ma " swap ' and ` nnoremap ' ` nnoremap ` ' " -- editing ------------------------------------------------------------------- set showmode " always show the current editing mode set nowrap " don't wrap lines set linebreak " yet if enabled break at word boundaries if has("multi_byte") " if multi_byte is available, set showbreak=↪ " use pretty Unicode marker else " otherwise, set showbreak=> " use ASCII character endif set nojoinspaces " insert only one space after '.', '?', '!' when joining lines set showmatch " briefly jumps the cursor to the matching brace on insert set matchtime=4 " blink matching braces for 0.4s set matchpairs+=<:> " make < and > match runtime macros/matchit.vim " enable extended % matching set virtualedit=insert " allow the cursor to go everywhere (insert) set virtualedit+=onemore " allow the cursor to go just past the end of line set virtualedit+=block " allow the cursor to go everywhere (visual block) set backspace=indent,eol,start " allow backspacing over everything (insert) set expandtab " insert spaces instead of tab, CTRL-V+Tab inserts a real tab set tabstop=2 " 1 tab == 2 spaces set softtabstop=2 " number of columns used when hitting TAB in insert mode set smarttab " insert tabs on the start of a line according to shiftwidth if has("autocmd") augroup makefile autocmd! " don't expand tab to space in Makefiles autocmd filetype make setlocal noexpandtab augroup END endif set autoindent " enable autoindenting set copyindent " copy the previous indentation on autoindenting set shiftwidth=2 " indent with 2 spaces set shiftround " use multiple of shiftwidth when indenting with '<' and '>' " make Y consistent with C and D by yanking up to end of line noremap Y y$ " CTRL-S saves file nnoremap :w " inverts paste mode nnoremap pp :set paste! paste? " same in insert mode set pastetoggle=pp function! Preserve(command) let l:search=@/ let l:line = line(".") let l:col = col(".") execute a:command let @/=l:search call cursor(l:line, l:col) endfunction " rt retabs the file, preserve cursor position nnoremap rt :call Preserve(":retab") " s removes trailing spaces noremap s :call Preserve("%s/\\s\\+$//e") " $ fixes mixed EOLs (^M) noremap $ :call Preserve("%s///e") " use d to delete a line without adding it to the yanked stack nnoremap d "_d vnoremap d "_d " use c to replace text without yanking replaced text nnoremap c "_c vnoremap c "_c " yank/paste to/from the OS clipboard noremap y "+y noremap Y "+Y noremap p "+p noremap P "+P " paste without yanking replaced text in visual mode vnoremap p "_dP vnoremap P "_dp " always share the OS clipboard set clipboard+=unnamed " autofix typos iabbrev teh the " reselect last selection after indent / un-indent in visual and select modes vnoremap < >gv vmap > vmap < set cpoptions+=$ " display $ at the end of the replacement zone instead of " deleting text with 'cw' and alike set formatoptions-=t " don't auto-wrap text using textwidth set formatoptions+=c " auto-wrap comments using textwidth set formatoptions+=r " auto-insert current comment leader, C-u to undo " exit from insert mode without cursor movement inoremap jk `^ " quick insertion of newline in normal mode with if has("autocmd") nnoremap :put='' augroup newline autocmd! autocmd BufReadPost quickfix nnoremap autocmd CmdwinEnter * nnoremap augroup END endif " remap U to for easier redo nnoremap U " preserve cursor position when joining lines nnoremap J :call Preserve("normal! J") " split line and preserve cursor position nnoremap S :call Preserve("normal! i\r") " select what was just pasted nnoremap v V`] " triggers completion in insert mode inoremap if !has("gui_running") inoremap endif set completeopt=longest,menuone,preview " better completion " move current line down noremap - :m+ " move current line up noremap _ :m-2 " move visual selection down vnoremap - :m '>+1gv=gv " move visual selection up vnoremap _ :m '<-2gv=gv " change cursor to vertical bar in insert mode when using iTerm2 if $TERM_PROGRAM == 'iTerm.app' if exists('$TMUX') let &t_SI = "\Ptmux;\\]50;CursorShape=1\x7\\\" let &t_EI = "\Ptmux;\\]50;CursorShape=0\x7\\\" else let &t_SI = "\]50;CursorShape=1\x7" let &t_EI = "\]50;CursorShape=0\x7" endif endif nnoremap Q " make dot work in visual mode vnoremap . :normal . " make v enter blockwise visual mode, and CTRL-V enter visual mode nnoremap v nnoremap v vnoremap v vnoremap v " -- searching ----------------------------------------------------------------- set wrapscan " wrap around when searching set incsearch " show match results while typing search pattern if (&t_Co > 2 || has("gui_running")) set hlsearch " highlight search terms endif " temporarily disable highlighting when entering insert mode if has("autocmd") augroup hlsearch autocmd! autocmd InsertEnter * let g:restorehlsearch=&hlsearch | :set nohlsearch autocmd InsertLeave * let &hlsearch=g:restorehlsearch augroup END endif set ignorecase " case insensitive search set smartcase " case insensitive only if search pattern is all lowercase " (smartcase requires ignorecase) set gdefault " search/replace globally (on a line) by default " temporarily disable search highlighting nnoremap :nohlsearch:match none:2match none:3match none " highlight all instances of the current word where thecursor is positioned nnoremap hs :setl hls:let @/="\\<\\>" " use h1, h2, h3 to highlight words in different colors nnoremap h1 :highlight Highlight1 ctermfg=0 ctermbg=226 guifg=Black guibg=Yellow :execute 'match Highlight1 /\<\>/' nnoremap h2 :highlight Highlight2 ctermfg=0 ctermbg=51 guifg=Black guibg=Cyan :execute '2match Highlight2 /\<\>/' nnoremap h3 :highlight Highlight3 ctermfg=0 ctermbg=46 guifg=Black guibg=Green :execute '3match Highlight3 /\<\>/' " very magic search patterns " everything but '0'-'9', 'a'-'z', 'A'-'Z' and '_' has a special meaning "nnoremap / /\v "vnoremap / /\v "nnoremap ? ?\v "vnoremap ? ?\v "cnoremap %s/ %s/\v " replace word under cursor nnoremap ; :%s/\<\>// function! BlinkMatch(t) let [l:bufnum, l:lnum, l:col, l:off] = getpos('.') let l:current = '\c\%#'.@/ let l:highlight = matchadd('IncSearch', l:current, 1000) redraw exec 'sleep ' . float2nr(a:t * 1000) . 'm' call matchdelete(l:highlight) redraw endfunction " center screen on next/previous match, blink current match noremap n nzzzv:call BlinkMatch(0.2) noremap N Nzzzv:call BlinkMatch(0.2) function! GetVisualSelection() let [l:l1, l:c1] = getpos("'<")[1:2] let [l:l2, l:c2] = getpos("'>")[1:2] let l:selection = getline(l:l1, l:l2) let l:selection[-1] = l:selection[-1][: l:c2 - 1] let l:selection[0] = l:selection[0][l:c1 - 1:] return join(l:selection, "\n") endfunction " search for visually selected areas xnoremap * /=substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g") xnoremap # ?=substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g") " prepare search based on visually selected area xnoremap / /=substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g") " prepare substitution based on visually selected area xnoremap & :%s/=substitute(escape(GetVisualSelection(), '\/.*$^~[]'), "\n", '\\n', "g")/ " -- spell checking ------------------------------------------------------------ set spelllang=en " English only set nospell " disabled by default if has("autocmd") augroup spell autocmd! "autocmd filetype vim setlocal spell " enabled when editing .vimrc augroup END endif " FINDING FILES: " Search down into subfolders " Provides tab-completion for all file-related tasks set path+=** " Display all matching files when we tab complete set wildmenu " NOW WE CAN: " - Hit tab to :find by partial match " - Use * to make it fuzzy " THINGS TO CONSIDER: " - :b lets you autocomplete any open buffer