Last active
January 5, 2020 15:57
-
-
Save ProteusCortex/1302f74ff2bfd4168249 to your computer and use it in GitHub Desktop.
An assembly of various hunks of .vimrc files, tailored to my preferences, kept as simple as possible. (see comment bellow)
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
" Modeline and Notes { | |
" vim: set sw=4 ts=4 et tw=78 foldmarker={{{,}}} foldlevel=0 foldmethod=marker spell: | |
" | |
" An assembly of various hunks of .vimrc files, tailored to my preferences | |
" and widely based on other people's .vimrc files, posts and guides. | |
" | |
" } | |
" Environment {{{ | |
" Identify platform {{{ | |
silent function! OSX() | |
return has('macunix') | |
endfunction | |
silent function! LINUX() | |
return has('unix') && !has('macunix') && !has('win32unix') | |
endfunction | |
silent function! WINDOWS() | |
return (has('win16') || has('win32') || has('win64')) | |
endfunction | |
" }}} | |
" Basics {{{ | |
set nocompatible " be iMproved, required in first line | |
if !WINDOWS() | |
set shell=/bin/sh | |
endif | |
" }}} | |
" Windows Compatible {{{ | |
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization | |
" across (heterogeneous) systems easier. | |
if WINDOWS() | |
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after | |
endif | |
" }}} | |
" }}} | |
" Vundle and plugins support {{{ | |
filetype off " required | |
" Set the runtime path to include Vundle and initialize | |
set rtp+=~/.vim/bundle/Vundle.vim | |
call vundle#begin() | |
" alternatively, pass a path where Vundle should install plugins | |
"call vundle#begin('~/some/path/here') | |
" Let Vundle manage Vundle, required | |
Plugin 'gmarik/Vundle.vim' | |
Plugin 'L9' | |
Plugin 'scrooloose/nerdtree' | |
Plugin 'morhetz/gruvbox' | |
Plugin 'bling/vim-airline' | |
Plugin 'bling/vim-bufferline' | |
Plugin 'mbbill/undotree' | |
Plugin 'Shougo/neocomplcache' | |
Plugin 'godlygeek/tabular' | |
Plugin 'rhowardiv/nginx-vim-syntax' | |
" All of your Plugins must be added before the following line | |
call vundle#end() " required | |
" Uncomment the following to have Vim load indentation rules and plugins | |
" according to the detected filetype. | |
if has("autocmd") | |
filetype plugin indent on | |
" Prevent auto-commenting | |
autocmd filetype * set formatoptions-=c formatoptions-=r formatoptions-=o | |
endif | |
" }}} | |
" General Preferences {{{ | |
set background=dark " Nobody uses a light terminal anymore | |
filetype plugin indent on " Automatically detect file types | |
syntax on " Turn syntax highlighing on | |
set mouse=a " Enable mouse usage (all modes) | |
set mousehide " Hide the mouse cursor while typing | |
scriptencoding utf-8 " In case somebody gets confused... | |
set ffs=unix,dos,mac " Use Unix as the standard file type | |
set autoread " Auto-read when a file is changed externally | |
"set autowrite " Automatically save before commands like :next and :make | |
" Return to the last edit position when opening files {{{ | |
if has("autocmd") | |
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif | |
endif | |
" }}} | |
" Instead of reverting the cursor to the last position in the buffer, we | |
" set it to the first line when editing a git commit message | |
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, 1, 0]) | |
set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter') | |
set viewoptions=folds,options,cursor,unix,slash " Better Unix / Windows compatibility | |
set virtualedit=onemore " Allow for cursor beyond last character | |
set history=1000 " How many lines of history to remember | |
set nospell " Spell checking off by default | |
set hidden " Allow buffer switching without saving | |
set iskeyword-=. " '.' is an end of word designator | |
set iskeyword-=# " '#' is an end of word designator | |
set iskeyword-=- " '-' is an end of word designator | |
" Setting up the directories {{{ | |
set backup " Backups are nice ... | |
if has('persistent_undo') | |
set undofile " So is persistent undo ... | |
set undolevels=1000 " Maximum number of changes that can be undone | |
set undoreload=10000 " Maximum number lines to save for undo on a buffer reload | |
endif | |
" }}} | |
" }}} | |
" Vim UI {{{ | |
" Personalised preferences for colorscheme | |
if filereadable(expand("~/.vimrc.colorscheme")) | |
source ~/.vimrc.colorscheme | |
endif | |
set tabpagemax=15 " Only show 15 tabs | |
set noshowmode " Don't display the current mode (Airline does this instead) | |
set cursorline " Highlight the current line | |
highlight clear SignColumn " SignColumn should match background | |
highlight clear LineNr " Current line number row will have same background color in relative mode | |
" Make the 81st column stand out | |
highlight ColorColumn ctermbg=magenta | |
call matchadd('ColorColumn', '\%81v', 100) | |
" April Fool's stuff... >:D {{{ | |
"highlight ColorColumn ctermbg=red ctermfg=blue | |
"exec 'set colorcolumn=' . join(range(2,80,3), ',') | |
" }}} | |
if has('cmdline_info') | |
set ruler " Show the ruler | |
set rulerformat=%30(%=\:b%n%y%m%r%w\ %l,%c%V\ %P%) " A ruler on steroids | |
set showcmd " Show partial commands in status line and | |
" Selected characters/lines in visual mode | |
endif | |
if has('statusline') | |
set laststatus=2 | |
" Broken down into easily includeable segments | |
set statusline=%<%f\ " Filename | |
set statusline+=%w%h%m%r " Options | |
set statusline+=%{fugitive#statusline()} " Git Hotness | |
set statusline+=\ [%{&ff}/%Y] " Filetype | |
set statusline+=\ [%{getcwd()}] " Current dir | |
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info | |
endif | |
set backspace=indent,eol,start " Backspace for dummies | |
set linespace=0 " No extra spaces between rows | |
set nu " Line numbers on | |
set showmatch " Show matching brackets/parenthesis | |
set incsearch " Find as you type search | |
set hlsearch " Highlight search terms | |
set winminheight=0 " Windows can be 0 line high | |
set ignorecase " Case insensitive search | |
set smartcase " Case sensitive when uc present | |
set wildmenu " Show list instead of just completing | |
set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all. | |
set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too | |
set scrolljump=5 " Lines to scroll when cursor leaves screen | |
set scrolloff=3 " Minimum lines to keep above and below cursor | |
set foldenable " Auto fold code | |
set list | |
set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace | |
set lazyredraw " Don't redraw while executing macros (performance) | |
set magic " For regular expressions turn magic on | |
" No annoying sound on errors | |
set noerrorbells | |
set novisualbell | |
set t_vb= | |
set tm=500 | |
" }}} | |
" Formatting {{{ | |
"set nowrap " Do not wrap long lines | |
set autoindent " Indent at the same level of the previous line | |
set shiftwidth=4 " Use indents of 4 spaces | |
"set expandtab " Tabs are spaces, not tabs | |
set smarttab " Be smart when using tabs ;) | |
set tabstop=4 " An indentation every four columns | |
set softtabstop=4 " Let backspace delete indent | |
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J) | |
set splitright " Puts new vsplit windows to the right of the current | |
set splitbelow " Puts new split windows to the bottom of the current | |
"set matchpairs+=<:> " Match, to be used with % | |
set pastetoggle=<F12> " pastetoggle (sane indentation on pastes) | |
" Remove trailing whitespaces and ^M chars | |
autocmd FileType c,cpp,java,go,php,javascript,puppet,python,rust,twig,xml,yml,perl,sql autocmd BufWritePre <buffer> if !exists('g:spf13_keep_trailing_whitespace') | call StripTrailingWhitespace() | endif | |
"autocmd FileType go autocmd BufWritePre <buffer> Fmt | |
autocmd BufNewFile,BufRead *.html.twig set filetype=html.twig | |
autocmd FileType haskell,puppet,ruby,yml setlocal expandtab shiftwidth=2 softtabstop=2 | |
" preceding line best in a plugin but here for now. | |
autocmd BufNewFile,BufRead *.coffee set filetype=coffee | |
" Workaround vim-commentary for Haskell | |
autocmd FileType haskell setlocal commentstring=--\ %s | |
" Workaround broken colour highlighting in Haskell | |
autocmd FileType haskell,rust setlocal nospell | |
" }}} | |
" Key (re)Mappings {{{ | |
" The default leader is '\', but many people prefer ',' as it's in a standard location. | |
"let mapleader=',' | |
" Easier moving in tabs and windows | |
" The lines conflict with the default digraph mapping of <C-K> | |
map <C-j> <C-W>j | |
map <C-k> <C-W>k | |
map <C-h> <C-W>h | |
map <C-l> <C-W>l | |
" Wrapped lines goes down/up to next row, rather than next line in file. | |
noremap j gj | |
noremap k gk | |
" Visual mode pressing * or # searches for the current selection | |
" Super useful! From an idea by Michael Naumann | |
vnoremap <silent> * :call VisualSelection('f')<CR> | |
vnoremap <silent> # :call VisualSelection('b')<CR> | |
" Stupid shift key fixes | |
if has("user_commands") | |
command! -bang -nargs=* -complete=file E e<bang> <args> | |
command! -bang -nargs=* -complete=file W w<bang> <args> | |
command! -bang -nargs=* -complete=file Wq wq<bang> <args> | |
command! -bang -nargs=* -complete=file WQ wq<bang> <args> | |
command! -bang Wa wa<bang> | |
command! -bang WA wa<bang> | |
command! -bang Q q<bang> | |
command! -bang QA qa<bang> | |
command! -bang Qa qa<bang> | |
endif | |
cmap Tabe tabe | |
" Yank from the cursor to the end of the line, to be consistent with C and D. | |
nnoremap Y y$ | |
" Code folding options | |
nmap <leader>f0 :set foldlevel=0<CR> | |
nmap <leader>f1 :set foldlevel=1<CR> | |
nmap <leader>f2 :set foldlevel=2<CR> | |
nmap <leader>f3 :set foldlevel=3<CR> | |
nmap <leader>f4 :set foldlevel=4<CR> | |
nmap <leader>f5 :set foldlevel=5<CR> | |
nmap <leader>f6 :set foldlevel=6<CR> | |
nmap <leader>f7 :set foldlevel=7<CR> | |
nmap <leader>f8 :set foldlevel=8<CR> | |
nmap <leader>f9 :set foldlevel=9<CR> | |
" Map <Space> to / (search) and Ctrl-<Space> to ? (backwards search) | |
"map <space> / | |
"map <c-space> ? | |
" Two different behaviours for everybody! | |
" Disable highlight when <leader><CR> is pressed | |
"map <silent> <leader><cr> :noh<cr> | |
" Clear search results when <leader><CR> is pressed | |
nmap <silent> <leader>/ :nohlsearch<CR> | |
" Find merge conflict markers | |
map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR> | |
" Shortcuts | |
" Change Working Directory to that of the current file | |
cmap cwd lcd %:p:h | |
cmap cd. lcd %:p:h | |
" Visual shifting (does not exit Visual mode) | |
vnoremap < <gv | |
vnoremap > >gv | |
" Close the current buffer | |
map <leader>ba :1, bd!<cr> | |
" Useful mappings for managing tabs | |
map <leader>tn :tabnew<cr> | |
map <leader>to :tabonly<cr> | |
map <leader>tc :tabclose<cr> | |
map <leader>tm :tabmove<cr> | |
" Allow using the repeat operator with a visual selection (!) | |
" http://stackoverflow.com/a/8064607/127816 | |
vnoremap . :normal .<CR> | |
" For when you forget to sudo.. Really Write the file. | |
cmap w!! w !sudo tee % >/dev/null | |
" Some helpers to edit mode | |
" http://vimcasts.org/e/14 | |
cnoremap %% <C-R>=fnameescape(expand('%:h')).'/'<cr> | |
map <leader>ew :e %% | |
map <leader>es :sp %% | |
map <leader>ev :vsp %% | |
map <leader>et :tabe %% | |
" Adjust viewports to the same size | |
map <Leader>= <C-w>= | |
" Map <Leader>ff to display all lines with keyword under cursor | |
" and ask which one to jump to | |
nmap <Leader>ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR> | |
" Easier horizontal scrolling | |
map zl zL | |
map zh zH | |
" Easier formatting | |
nnoremap <silent> <leader>q gwip | |
" Remap VIM 0 to first non-blank character | |
map 0 ^ | |
" Remap <:> to <;> (saves you the Shift) :P | |
nnoremap ; : | |
" }}} | |
" Plugin Preferences & stuff {{{ | |
" Misc {{{ | |
if isdirectory(expand("~/.vim/bundle/nerdtree")) | |
let g:NERDShutUp=1 | |
endif | |
" }}} | |
" OmniComplete {{{ | |
" To disable omni complete, uncomment the following line | |
" let g:no_omni_complete = 1 | |
if !exists('g:no_omni_complete') | |
if has("autocmd") && exists("+omnifunc") | |
autocmd Filetype * | |
\if &omnifunc == "" | | |
\setlocal omnifunc=syntaxcomplete#Complete | | |
\endif | |
endif | |
hi Pmenu guifg=#000000 guibg=#F8F8F8 ctermfg=black ctermbg=Lightgray | |
hi PmenuSbar guifg=#8A95A7 guibg=#F8F8F8 gui=NONE ctermfg=darkcyan ctermbg=lightgray cterm=NONE | |
hi PmenuThumb guifg=#F8F8F8 guibg=#8A95A7 gui=NONE ctermfg=lightgray ctermbg=darkcyan cterm=NONE | |
" Some convenient mappings | |
inoremap <expr> <Esc> pumvisible() ? "\<C-e>" : "\<Esc>" | |
if exists('g:map_cr_omni_complete') | |
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" | |
endif | |
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>" | |
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>" | |
inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>" | |
inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>" | |
" Automatically open and close the popup menu / preview window | |
au CursorMovedI,InsertLeave * if pumvisible() == 0|silent! pclose|endif | |
set completeopt=menu,preview,longest | |
endif | |
" }}} | |
" NerdTree {{{ | |
if isdirectory(expand("~/.vim/bundle/nerdtree")) | |
map <C-e> <plug>NERDTreeTabsToggle<CR> | |
map <leader>e :NERDTreeFind<CR> | |
nmap <leader>nt :NERDTreeFind<CR> | |
let NERDTreeShowBookmarks=1 | |
let NERDTreeIgnore=['\.py[cd]$', '\~$', '\.swo$', '\.swp$', '^\.git$', '^\.hg$', '^\.svn$', '\.bzr$'] | |
let NERDTreeChDirMode=0 | |
let NERDTreeQuitOnOpen=1 | |
let NERDTreeMouseMode=2 | |
let NERDTreeShowHidden=1 | |
let NERDTreeKeepTreeInNewTab=1 | |
let g:nerdtree_tabs_open_on_gui_startup=0 | |
endif | |
" }}} | |
" Tabularize {{{ | |
if isdirectory(expand("~/.vim/bundle/tabular")) | |
nmap <Leader>a& :Tabularize /&<CR> | |
vmap <Leader>a& :Tabularize /&<CR> | |
nmap <Leader>a= :Tabularize /=<CR> | |
vmap <Leader>a= :Tabularize /=<CR> | |
nmap <Leader>a=> :Tabularize /=><CR> | |
vmap <Leader>a=> :Tabularize /=><CR> | |
nmap <Leader>a: :Tabularize /:<CR> | |
vmap <Leader>a: :Tabularize /:<CR> | |
nmap <Leader>a:: :Tabularize /:\zs<CR> | |
vmap <Leader>a:: :Tabularize /:\zs<CR> | |
nmap <Leader>a, :Tabularize /,<CR> | |
vmap <Leader>a, :Tabularize /,<CR> | |
nmap <Leader>a,, :Tabularize /,\zs<CR> | |
vmap <Leader>a,, :Tabularize /,\zs<CR> | |
nmap <Leader>a<Bar> :Tabularize /<Bar><CR> | |
vmap <Leader>a<Bar> :Tabularize /<Bar><CR> | |
endif | |
" }}} | |
" neocomplcache {{{ | |
let g:acp_enableAtStartup = 0 | |
let g:neocomplcache_enable_at_startup = 1 | |
let g:neocomplcache_enable_camel_case_completion = 1 | |
let g:neocomplcache_enable_smart_case = 1 | |
let g:neocomplcache_enable_underbar_completion = 1 | |
let g:neocomplcache_enable_auto_delimiter = 1 | |
let g:neocomplcache_max_list = 15 | |
let g:neocomplcache_force_overwrite_completefunc = 1 | |
" Define dictionary. | |
let g:neocomplcache_dictionary_filetype_lists = { | |
\ 'default' : '', | |
\ 'vimshell' : $HOME.'/.vimshell_hist', | |
\ 'scheme' : $HOME.'/.gosh_completions' | |
\ } | |
" Define keyword. | |
if !exists('g:neocomplcache_keyword_patterns') | |
let g:neocomplcache_keyword_patterns = {} | |
endif | |
let g:neocomplcache_keyword_patterns._ = '\h\w*' | |
" Plugin key-mappings {{{ | |
inoremap <CR> <CR> | |
" <ESC> takes you out of insert mode | |
inoremap <expr> <Esc> pumvisible() ? "\<C-y>\<Esc>" : "\<Esc>" | |
" <CR> accepts first, then sends the <CR> | |
inoremap <expr> <CR> pumvisible() ? "\<C-y>\<CR>" : "\<CR>" | |
" <Down> and <Up> cycle like <Tab> and <S-Tab> | |
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>" | |
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>" | |
" Jump up and down the list | |
inoremap <expr> <C-d> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<C-d>" | |
inoremap <expr> <C-u> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<C-u>" | |
inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>" | |
" }}} | |
" Enable omni completion. | |
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS | |
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags | |
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS | |
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete | |
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags | |
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete | |
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc | |
" Enable heavy omni completion. | |
if !exists('g:neocomplcache_omni_patterns') | |
let g:neocomplcache_omni_patterns = {} | |
endif | |
let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::' | |
let g:neocomplcache_omni_patterns.perl = '\h\w*->\h\w*\|\h\w*::' | |
let g:neocomplcache_omni_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)' | |
let g:neocomplcache_omni_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::' | |
let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\h\w*\|\h\w*::' | |
let g:neocomplcache_omni_patterns.go = '\h\w*\.\?' | |
" }}} | |
" Normal Vim omni-completion {{{ | |
" To disable omni complete, add the following to your .vimrc.before.local file: | |
" let g:spf13_no_omni_complete = 1 | |
if !exists('g:spf13_no_omni_complete') | |
" Enable omni-completion. | |
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS | |
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags | |
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS | |
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete | |
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags | |
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete | |
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc | |
endif | |
" }}} | |
" UndoTree {{{ | |
if isdirectory(expand("~/.vim/bundle/undotree/")) | |
nnoremap <Leader>u :UndotreeToggle<CR> | |
" If undotree is opened, it is likely one wants to interact with it. | |
let g:undotree_SetFocusWhenToggle=1 | |
endif | |
" }}} | |
" vim-airline {{{ | |
" Set configuration options for the statusline plugin vim-airline. | |
" Use the powerline theme and optionally enable powerline symbols. | |
" To use the symbols , , , , , , and .in the statusline | |
" segments add the following to your .vimrc.before.local file: | |
" let g:airline_powerline_fonts=1 | |
" If the previous symbols do not render for you then install a | |
" powerline enabled font. | |
if has('gui_running') | |
let g:airline_powerline_fonts=1 | |
endif | |
" See `:echo g:airline_theme_map` for some more choices | |
" Default in terminal vim is 'dark' | |
if isdirectory(expand("~/.vim/bundle/vim-airline/")) | |
if !exists('g:airline_powerline_fonts') | |
" Use the default set of separators with a few customizations | |
"let g:airline_left_sep='›' " Slightly fancier than '>' | |
"let g:airline_right_sep='‹' " Slightly fancier than '<' | |
endif | |
let g:airline_detect_modified=1 | |
let g:airline_detect_paste=1 | |
let g:airline_detect_iminsert=0 | |
let g:airline_inactive_collapse=1 | |
let g:airline#extensions#bufferline#enabled=1 | |
let g:bufferline_echo=0 | |
endif | |
" }}} | |
" }}} | |
" GUI Settings {{{ | |
" GVIM- (here instead of .gvimrc) | |
if has('gui_running') | |
set guioptions-=T " Remove the toolbar | |
set guioptions+=e | |
set guitablabel=%M\ %t | |
set lines=55 " 55 lines of text instead of 24 | |
" (assuming that we all have tall screens) | |
autocmd! GUIEnter * set vb t_vb= " make sure that the audible bell is disabled | |
if !exists("g:spf13_no_big_font") | |
if LINUX() && has("gui_running") | |
set guifont=Menlo\ for\ Powerline\ 9,Andale\ Mono\ Regular\ 12,Menlo\ Regular\ 11,Consolas\ Regular\ 12,Courier\ New\ Regular\ 14 | |
elseif OSX() && has("gui_running") | |
set guifont=Menlo\ for\ Powerline,Andale\ Mono\ Regular:h12,Menlo\ Regular:h11,Consolas\ Regular:h12,Courier\ New\ Regular:h14 | |
elseif WINDOWS() && has("gui_running") | |
set guifont=Andale_Mono:h10,Menlo:h10,Consolas:h10,Courier_New:h10 | |
endif | |
endif | |
else | |
if &term == 'xterm' || &term == 'screen' | |
set t_Co=256 " Enable 256 colors to stop the CSApprox warning and make xterm vim shine | |
endif | |
"set term=builtin_ansi " Make arrow and other keys work | |
endif | |
" }}} | |
" Functions {{{ | |
" Initialize directories {{{ | |
function! InitializeDirectories() | |
let parent = $HOME | |
let prefix = 'vim' | |
let dir_list = { | |
\ 'backup': 'backupdir', | |
\ 'views': 'viewdir', | |
\ 'swap': 'directory' } | |
if has('persistent_undo') | |
let dir_list['undo'] = 'undodir' | |
endif | |
" To specify a different directory in which to place the vimbackup, | |
" vimviews, vimundo, and vimswap files/directories, add the following to | |
" your .vimrc.before.local file: | |
" let g:spf13_consolidated_directory = <full path to desired directory> | |
" eg: let g:spf13_consolidated_directory = $HOME . '/.vim/' | |
if exists('g:spf13_consolidated_directory') | |
let common_dir = g:spf13_consolidated_directory . prefix | |
else | |
let common_dir = parent . '/.' . prefix | |
endif | |
for [dirname, settingname] in items(dir_list) | |
let directory = common_dir . dirname . '/' | |
if exists("*mkdir") | |
if !isdirectory(directory) | |
call mkdir(directory) | |
endif | |
endif | |
if !isdirectory(directory) | |
echo "Warning: Unable to create backup directory: " . directory | |
echo "Try: mkdir -p " . directory | |
else | |
let directory = substitute(directory, " ", "\\\\ ", "g") | |
exec "set " . settingname . "=" . directory | |
endif | |
endfor | |
endfunction | |
call InitializeDirectories() | |
" }}} | |
" Initialize NERDTree as needed {{{ | |
function! NERDTreeInitAsNeeded() | |
redir => bufoutput | |
buffers! | |
redir END | |
let idx = stridx(bufoutput, "NERD_tree") | |
if idx > -1 | |
NERDTreeMirror | |
NERDTreeFind | |
wincmd l | |
endif | |
endfunction | |
" }}} | |
" Strip whitespace {{{ | |
function! StripTrailingWhitespace() | |
" Preparation: save last search, and cursor position. | |
let _s=@/ | |
let l = line(".") | |
let c = col(".") | |
" do the business: | |
%s/\s\+$//e | |
" clean up: restore previous search history, and cursor position | |
let @/=_s | |
call cursor(l, c) | |
endfunction | |
" }}} | |
" Shell command {{{ | |
function! s:RunShellCommand(cmdline) | |
botright new | |
setlocal buftype=nofile | |
setlocal bufhidden=delete | |
setlocal nobuflisted | |
setlocal noswapfile | |
setlocal nowrap | |
setlocal filetype=shell | |
setlocal syntax=shell | |
call setline(1, a:cmdline) | |
call setline(2, substitute(a:cmdline, '.', '=', 'g')) | |
execute 'silent $read !' . escape(a:cmdline, '%#') | |
setlocal nomodifiable | |
1 | |
endfunction | |
command! -complete=file -nargs=+ Shell call s:RunShellCommand(<q-args>) | |
" e.g. Grep current file for <search_term>: Shell grep -Hn <search_term> % | |
" }}} | |
" }}} |
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
if filereadable(expand("~/.vim/bundle/gruvbox/colors/gruvbox.vim")) | |
colorscheme gruvbox " Really nice colorscheme, readable everywhwere | |
endif |
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
#!/bin/sh | |
## SETUP PARAMETERS ## | |
[ -z "$APP_PATH" ] && APP_PATH="$HOME/.vimrc.d" | |
[ -z "$REPO_URI" ] && REPO_URI="https://gist.github.com/ProteusCortex/1302f74ff2bfd4168249.git" | |
[ -z "$REPO_BRANCH" ] && REPO_BRANCH="master" | |
[ -z "$VUNDLE_URI" ] && VUNDLE_URI="https://github.com/gmarik/vundle.git" | |
debug_mode='0' | |
## BASIC SETUP TOOLS ## | |
msg() { | |
printf '%b\n' "$1" >&2 | |
} | |
success() { | |
if [ "$ret" -eq '0' ]; then | |
msg "\33[32m[✔]\33[0m ${1}${2}" | |
fi | |
} | |
error() { | |
msg "\33[31m[✘]\33[0m ${1}${2}" | |
exit 1 | |
} | |
debug() { | |
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ]; then | |
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that." | |
fi | |
} | |
program_exists() { | |
local ret='0' | |
command -v $1 >/dev/null 2>&1 || { local ret='1'; } | |
# fail on non-zero return value | |
if [ "$ret" -ne 0 ]; then | |
return 1 | |
fi | |
return 0 | |
} | |
program_must_exist() { | |
program_exists $1 | |
# throw error on non-zero return value | |
if [ "$?" -ne 0 ]; then | |
error "You must have '$1' installed to continue." | |
fi | |
} | |
variable_set() { | |
if [ -z "$1" ]; then | |
error "You must have your HOME environmental variable set to continue." | |
fi | |
} | |
lnif() { | |
if [ -e "$1" ]; then | |
ln -sf "$1" "$2" | |
fi | |
ret="$?" | |
debug | |
} | |
## SETUP FUNCTIONS ## | |
do_backup() { | |
if [ -e "$1" ] || [ -e "$2" ] || [ -e "$3" ]; then | |
msg "Attempting to back up your original vim configuration." | |
today=`date +%Y%m%d_%s` | |
for i in "$1" "$2" "$3"; do | |
[ -e "$i" ] && [ ! -L "$i" ] && mv -v "$i" "$i.$today"; | |
done | |
ret="$?" | |
success "Your original vim configuration has been backed up." | |
debug | |
fi | |
} | |
sync_repo() { | |
local repo_path="$1" | |
local repo_uri="$2" | |
local repo_branch="$3" | |
local repo_name="$4" | |
msg "Trying to update $repo_name" | |
if [ ! -e "$repo_path" ]; then | |
mkdir -p "$repo_path" | |
git clone -b "$repo_branch" "$repo_uri" "$repo_path" | |
ret="$?" | |
success "Successfully cloned $repo_name." | |
else | |
cd "$repo_path" && git pull origin "$repo_branch" | |
ret="$?" | |
success "Successfully updated $repo_name" | |
fi | |
debug | |
} | |
create_symlinks() { | |
local source_path="$1" | |
local target_path="$2" | |
lnif "$source_path/.vimrc" "$target_path/.vimrc" | |
lnif "$source_path/.vimrc.colorshceme" "$target_path/.vimrc.colorscheme" | |
lnif "$source_path/.vim" "$target_path/.vim" | |
if program_exists "nvim"; then | |
lnif "$source_path/.vim" "$target_path/.config/nvim" | |
lnif "$source_path/.vimrc" "$target_path/.config/nvim/init.vim" | |
fi | |
touch "$target_path/.vimrc.local" | |
ret="$?" | |
success "Setting up vim symlinks." | |
debug | |
} | |
setup_vundle() { | |
local system_shell="$SHELL" | |
export SHELL='/bin/sh' | |
vim \ | |
-u "$1" \ | |
"+set nomore" \ | |
"+BundleInstall!" \ | |
"+BundleClean" \ | |
"+qall" | |
export SHELL="$system_shell" | |
success "Now updating/installing plugins using Vundle" | |
debug | |
} | |
## MAIN() ## | |
variable_set "$HOME" | |
program_must_exist "vim" | |
program_must_exist "git" | |
do_backup "$HOME/.vim" \ | |
"$HOME/.vimrc" \ | |
"$HOME/.gvimrc" | |
sync_repo "$APP_PATH" \ | |
"$REPO_URI" \ | |
"$REPO_BRANCH" \ | |
"$app_name" | |
create_symlinks "$APP_PATH" \ | |
"$HOME" | |
sync_repo "$HOME/.vim/bundle/Vundle.vim" \ | |
"$VUNDLE_URI" \ | |
"master" \ | |
"vundle" | |
setup_vundle "$APP_PATH/.vimrc" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires Git 1.7+ and Vim 7.3+
If you have a bash-compatible shell you can run the script directly: