" Taken from wuman " " Environment " " pathogen (must be placed in the beginning of this file) "runtime bundle/pathogen/autoload/pathogen.vim "call pathogen#infect('bundle/{}') "call pathogen#infect('bundle-external/{}') "call pathogen#helptags() if &term == "linux" set t_ve+=[?81;0;112c endif " " General " set nocompatible " not compatible with the old-fashion vi mode set history=100 " store 100 lines of history " open up to 100 documents with `vim -p` set tabpagemax=100 " " User Interface " set showmode " display the current mode set ruler " always show current position set scrolloff=7 " set scroll offset to 7 lines above/below cursor set autoread " auto read when file is changed from outside set nu " display line numbers set clipboard=unnamed " yank to the system register (*) by default set hid " hide abandon buffers in order to not lose undo history set showmatch " cursor shows matching ) and } set incsearch " incremental search set ignorecase " ignore case when searching set smartcase " ignore case if search pattern is all lowercase, case-sensitive otherwise set wildchar= " start wild expansion in the command line using set wildmenu " wild char completion menu " ignore these files while expanding wild chars set wildignore=*.o,*.class,*.pyc " allow backspacing over everything in insert mode set backspace=indent,eol,start set whichwrap+=<,>,b,s,h,l,[,] filetype on " enable filetype detection filetype indent on " enable filetype-specific indenting filetype plugin on " enable filetype-specific plugins " auto reload vimrc when editing it autocmd! BufWritePost .vimrc source ~/.vimrc " disable annoying sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " vimtip#80 restore cursor to file position in previous editing session set viminfo='10,\"100,:20,%,n~/.viminfo function! ResCur() if line("'\"") <= line("$") normal! g`" return 1 endif endfunction augroup resCur autocmd! autocmd BufWinEnter * call ResCur() augroup END " " Formatting " set autoindent " auto indentation set copyindent " copy the previous indentation on autoindenting set smarttab " insert tabs on line start according to context set tabstop=2 set softtabstop=2 set shiftwidth=2 " " Colors and Fonts " syntax on " enable syntax highlighting set hlsearch " highlight search results " highlight current line in the current window augroup CursorLine au! au VimEnter,WinEnter,BufWinEnter * setlocal cursorline au WinLeave * setlocal nocursorline augroup END set bg=dark " Setting dark mode let g:gruvbox_contrast_dark = 'hard' colorscheme gruvbox " " Formatting " nnoremap :set invpaste paste? set pastetoggle= " toggle paste mode set ffs=unix,dos,mac " use unix as standard file format " " Files " set nobackup " no *~ backup files if !isdirectory($HOME . "/.cache/vim") call mkdir($HOME . "/.cache/vim", "p") " :silent !install -dm700 ~/.cache/vim >/dev/null 2>&1 endif set directory=~/.cache/vim// " " Statusline " set laststatus=2 " " Encoding " set encoding=utf-8 set termencoding=utf-8 set fileencoding=utf-8 set fileencodings=ucs-bom,utf-8,big5,gb2312,latin1 fun! ViewUTF8() set encoding=utf-8 set termencoding=big5 endfun fun! UTF8() set encoding=utf-8 set termencoding=big5 set fileencoding=utf-8 set fileencodings=ucs-bom,big5,utf-8,latin1 endfun " set leader to , let mapleader="," let g:mapleader="," " move around splits map j_ " move to and maximize the below split map k_ " move to and maximize the above split nmap h " move to and maximize the left split nmap l " move to and maximize the right split set wmw=0 " set the min width of a window to 0 so we can maximize others set wmh=0 " set the min height of a window to 0 so we can maximize others " move around tabs " WARN: conflict with the original screen top/bottom, comment them out if you want the original H/L map gT " go to prev tab map gt " go to next tab map :tabnew " new tab map :tabclose " close tab nmap / :nohl " ,/ turns off search highlighting " bash like keys for the command line cnoremap cnoremap cnoremap " vim-autoformat: use sourcebeautify shortcut nmap sb :Autoformat " ,p toggles paste mode nmap p :set paste!set paste? " allow multiple indentation/deindentation in visual mode vnoremap < >gv " Enable omni completion. (Ctrl-X Ctrl-O) autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags autocmd FileType javascript setlocal omnifunc=nodejscomplete#CompleteJS autocmd FileType python setlocal omnifunc=pythoncomplete#Complete autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags autocmd FileType css set omnifunc=csscomplete#CompleteCSS autocmd FileType c set omnifunc=ccomplete#Complete autocmd FileType java set omnifunc=javacomplete#Complete " use syntax complete if nothing else available if has("autocmd") && exists("+omnifunc") autocmd Filetype * \ if &omnifunc == "" | \ setlocal omnifunc=syntaxcomplete#Complete | \ endif endif " enable function folding set foldmethod=syntax set foldlevelstart=10 set cot-=preview " disable doc preview in omnicomplete " md is markdown autocmd BufRead,BufNewFile *.md set filetype=markdown " " Plugins " " vim-airline set timeout timeoutlen=1000 ttimeoutlen=50 let g:airline_powerline_fonts = 1 let g:airline_theme = 'gruvbox' let g:airline#extensions#tabline#enabled = 1 " JSON.vim http://www.vim.org/scripts/script.php?script_id=1945 au! BufRead,BufNewFile *.json set filetype=json " NERDTree " open a NERDTree automatically when vim starts up if no files were specified "autocmd vimenter * if !argc() | NERDTree | endif " close vim if the only window left open is a NERDTree autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif " toggle nerdtree drawer nnoremap d :NERDTreeToggle " open nerdtree to the current file nnoremap f :NERDTreeFind " YouCompleteMe " disable use of tab let g:ycm_key_list_select_completion=[] let g:ycm_key_list_previous_completion=[] let g:ycm_global_ycm_extra_conf = "~/.vim/ycm_extra_conf.py" nnoremap :Hexmode inoremap :Hexmode vnoremap :Hexmode " taken from bene set ls=2 set nostartofline " ex command for toggling hex mode - define mapping if desired command -bar Hexmode call ToggleHex() " helper function to toggle hex mode function ToggleHex() " hex mode should be considered a read-only operation " save values for modified and read-only for restoration later, " and clear the read-only flag for now let l:modified=&mod let l:oldreadonly=&readonly let &readonly=0 let l:oldmodifiable=&modifiable let &modifiable=1 if !exists("b:editHex") || !b:editHex " save old options let b:oldft=&ft let b:oldbin=&bin " set new options setlocal binary " make sure it overrides any textwidth, etc. let &ft="xxd" " set status let b:editHex=1 " switch to hex editor %!xxd else " restore old options let &ft=b:oldft if !b:oldbin setlocal nobinary endif " set status let b:editHex=0 " return to normal editing %!xxd -r endif " restore values for modified and read only state let &mod=l:modified let &readonly=l:oldreadonly let &modifiable=l:oldmodifiable endfunction