Skip to content

Instantly share code, notes, and snippets.

@abinashmeher999
Last active February 11, 2016 11:23
Show Gist options
  • Select an option

  • Save abinashmeher999/ecb3e8b280ed23e6b158 to your computer and use it in GitHub Desktop.

Select an option

Save abinashmeher999/ecb3e8b280ed23e6b158 to your computer and use it in GitHub Desktop.
My current vimrc
call plug#begin('~/.vim/plugged')
"
" always enabled
Plug 'junegunn/goyo.vim'
Plug 'tpope/vim-fugitive'
Plug 'scrooloose/syntastic'
Plug 'bling/vim-airline'
Plug 'scrooloose/nerdcommenter'
Plug 'xolox/vim-misc'
Plug 'docunext/closetag.vim'
Plug 'Lokaltog/vim-easymotion'
Plug 'altercation/vim-colors-solarized'
Plug 'tomtom/quickfixsigns_vim'
Plug 'nathanaelkane/vim-indent-guides'
Plug 'Valloric/YouCompleteMe', {'do': './install.py --clang-completer'}
Plug 'AndrewRadev/splitjoin.vim'
Plug 'tpope/vim-repeat'
Plug 'godlygeek/tabular'
Plug 'Shougo/unite.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'tpope/vim-surround'
Plug 'othree/html5.vim'
Plug 'mattn/gist-vim'
Plug 'tpope/vim-endwise'
Plug 'jiangmiao/auto-pairs'
Plug 'Valloric/MatchTagAlways'
Plug 'majutsushi/tagbar'
Plug 'kien/ctrlp.vim'
Plug 'PProvost/vim-markdown-jekyll'
" I added
Plug 'vim-ruby/vim-ruby'
Plug 'vim-airline/vim-airline-themes'
Plug 'tpope/vim-bundler'
Plug 'amiorin/vim-project'
Plug 'Chiel92/vim-autoformat'
Plug 'vim-scripts/taglist.vim'
" on-demand loading
Plug 'sjl/gundo.vim', {'on': 'GundoToggle'}
Plug 'scrooloose/nerdtree', {'on': 'NERDTreeToggle'}
Plug 'xolox/vim-notes', {'on': 'Notes'}
Plug 'chrisbra/NrrwRgn', {'on': 'NrrwRgn'}
Plug 'mtth/scratch.vim', {'on': 'Scratch'}
" filetype specific plugins
Plug 'othree/javascript-libraries-syntax.vim', {'for': ['javascript']}
Plug 'pangloss/vim-javascript', {'for': ['javascript']}
Plug 'itspriddle/vim-jquery', {'for': ['javascript']}
Plug 'bitc/vim-hdevtools', {'for': 'haskell'}
Plug 'fs111/pydoc.vim', {'for': 'python'}
call plug#end()
" General {
filetype plugin on
filetype plugin indent on
" Added by me
" let g:autoformat_autoindent = 0
let g:formatterpath = ['/usr/bin']
let g:formatdef_my_custom_cpp = '"astyle --style=java --style=attach --indent-switches --indent-namespaces --break-blocks --align-pointer=type --add-brackets --indent=spaces -A2 --pad-oper -p"'
let g:formatters_c = ['my_custom_cpp']
let g:formatters_cpp = ['my_custom_cpp']
set mouse=a
set mousehide
set shortmess+=filmnrxoOtT
set ttyfast
" set timeout timeoutlen=500 ttimeoutlen=1
au FocusLost * silent! wa
scriptencoding utf-8
if !exists('g:no_autochdir')
autocmd BufEnter * if bufname("") !~ "^\[A-Za-z0-9\]*://" | lcd %:p:h | endif
" Always switch to the current file directory
endif
if filereadable(expand("~/.vim/plugged/vim-colors-solarized/colors/solarized.vim"))
let g:solarized_termcolors=256
let g:solarized_contrast="normal"
let g:solarized_visibility="normal"
color solarized
set bg=dark
endif
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
if isdirectory(expand("~/.vim/plugged/vim-fugitive"))
set statusline+=%{fugitive#statusline()} " Git Hotness
endif
set statusline+=\ [%{&ff}/%Y] " Filetype
set statusline+=\ [%{getcwd()}] " Current dir
set statusline+=%=%-14.(%l,%c%V%)\ %p%% " Right aligned file nav info
endif
highlight clear SignColumn " SignColumn should match background
highlight clear LineNr " Current line number row will have same background color in relative mode
" Instead of these two options, we can set a single directory for all
" backups and temporary buffers. This is a better solution in case we don't
" want our current buffer to be destroyed due to any IOError.
"
" set backupdir=~/.vimtmp
" set directory=~/.vimtmp
set nobackup
set nowritebackup " Writes the buffer to the same file
set noswapfile
set list listchars=tab:▸\ ,trail:·
set tags=./tags;/
set mps+=<:>
set backspace=2
set smartcase
set confirm
set autoread
set showmatch
set smarttab
set showcmd
set incsearch
set nu
set visualbell t_vb=
" set t_RV=
set title
set cursorline
set viminfo='20,\"500
set hidden
set history=100
set clipboard=unnamedplus
set scrolloff=10
set foldenable
" }
" Formatting {
"
set autowrite
set expandtab
set shiftwidth=4
set tabstop=4
set softtabstop=4
set nojoinspaces
set shiftround
set splitright
set splitbelow
set wrap
augroup vimrcEx
autocmd!
autocmd FileType text setlocal spell
autocmd FileType haskell,puppet,ruby,yml,html setlocal expandtab shiftwidth=2 softtabstop=2
" When editing a file, always jump to the last known cursor position.
" Don't do it for commit messages, when the position is invalid, or when
" inside an event handler (happens when dropping a file on gvim).
autocmd BufReadPost *
\ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
" Set syntax highlighting for specific file types
autocmd BufRead,BufNewFile *.md set filetype=markdown
" Set spell for markdown files
autocmd BufRead,BufNewFile *.md setlocal spell
augroup END
let g:omni_complete=1
set wildchar=<Tab> wildmenu wildmode=full
set complete=.,w,t
"
"set wildmenu
"set wildmode=list:longest
set wildignore+=.hg,.git,.svn " Version Controls"
set wildignore+=*.aux,*.out,*.toc "Latex Indermediate files"
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg "Binary Imgs"
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest "Compiled Object files"
set wildignore+=*.spl "Compiled speolling world list"
set wildignore+=*.sw? "Vim swap files"
set wildignore+=*.DS_Store "OSX SHIT"
set wildignore+=*.luac "Lua byte code"
set wildignore+=migrations "Django migrations"
set wildignore+=*.pyc "Python Object codes"
set wildignore+=*.orig "Merge resolution files"
" }
" Key (re)mapping {
"
let mapleader=','
set pastetoggle=<F2>
" Windows like movements for long lines with wrap enabled:
noremap j gj
noremap k gk
" Allow saving of files as sudo when I forget to start vim using sudo.
cmap w!! :w !sudo tee > /dev/null %
" Do not leave visual mode after visually shifting text
vnoremap < <gv
vnoremap > >gv
" Tab control
nmap <Leader>tt :tabnew<cr>
nmap <Leader>tn :tabnext<cr>
nmap <Leader>tp :tabprevious<cr>
nmap <Leader>tc :tabclose<cr>
noremap <leader>ss :call StripWhitespace()<CR>
" }
" Functions {
"
" Strip trailing whitespace (<leader>ss)
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
function! ClearGutters()
highlight clear SignColumn
highlight clear LineNr
endfunction
if exists("+spelllang")
set spelllang=en_us
endif
set spellfile=~/.vim/spell/en.utf-8.add
if has('gui_running')
" Remove toolbar, scrollbar and any noise from GUI
set guioptions-=T
set guioptions-=r
set guioptions-=L
set guioptions-=m
set guioptions+=a
set guifont=Droid\ Sans\ Mono\ 9
set lines=40
endif
if exists('g:omni_complete')
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 ruby setlocal omnifunc=rubycomplete#Complete
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
endif
" }
" Plugins specific settings {
" nerdTree {
if isdirectory(expand("~/.vim/plugged/nerdtree"))
nnoremap <F9> :NERDTreeToggle<cr>
let NERDTreeIgnore=['\~$', '\.swp$', '\.git', '\.vim$', '\~$', '\.pyc$']
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
endif
" }
" vim-airline {
if isdirectory(expand("~/.vim/plugged/vim-airline"))
let g:airline#extensions#tabline#enabled = 1
" let g:airline_powerline_fonts=1
endif
" }
" syntastic {
if isdirectory(expand("~/.vim/plugged/syntastic"))
" To close the error window when using :bdelete command
nnoremap <silent> <C-d> :lclose<CR>:bdelete<CR>
cabbrev <silent> bd lclose\|bdelete
let g:syntastic_python_python_exec = '/usr/bin/python3' " use python3
let g:syntastic_python_checkers = ['flake8']
let g:syntastic_javascript_checkers = ['jshint']
let g:syntastic_ruby_checkers = ['rubocop']
let g:syntastic_cpp_compiler = 'clang++'
let g:syntastic_cpp_compiler_options = ' -std=c++11 -stdlib=libc++'
endif
" }
" vim-notes {
"
let g:notes_title_sync = 'rename_file'
" }
" unite {
if isdirectory(expand("~/.vim/plugged/unite.vim"))
let g:unite_kind_file_vertical_preview = 1
" Use the fuzzy matcher for everything
call unite#filters#matcher_default#use(['matcher_fuzzy'])
" Start in insert mode
let g:unite_enable_start_insert = 1
" Enable history yank source
let g:unite_source_history_yank_enable = 1
" Map space to the prefix for Unite
nnoremap [unite] <Nop>
nmap <space> [unite]
" Quick file search
nnoremap <silent> [unite]f :<C-u>Unite -buffer-name=files file_rec/async file/new<CR>
" Quick grep from cwd
nnoremap <silent> [unite]g :<C-u>Unite -buffer-name=grep grep:.<CR>
" Quick yank history
nnoremap <silent> [unite]y :<C-u>Unite -buffer-name=yanks history/yank<CR>
" Set up some custom ignores
call unite#custom_source('file_rec,file_rec/async,file_mru,file,buffer,grep',
\ 'ignore_pattern', join([
\ '\.git/',
\ 'git5/.*/review/',
\ 'tmp/',
\ 'node_modules/',
\ 'bower_components/',
\ 'dist/',
\ '.pyc',
\ ], '\|'))
" Quick line
nnoremap <silent> [unite]l :<C-u>Unite -buffer-name=search_file line<CR>
" Quick commands
nnoremap <silent> [unite]c :<C-u>Unite -buffer-name=commands command<CR>
" Quick search buffers
nnoremap <silent> [unite]b :<C-u>Unite -quick-match buffer<CR>
endif
" }
" vim-hdevltools {
if isdirectory(expand("~/.vim/plugged/vim-hdevtools"))
au FileType haskell nnoremap <buffer> <Leader>ht :HdevtoolsType<CR>
au FileType haskell nnoremap <buffer> <silent> <Leader>hc :HdevtoolsClear<CR>
au FileType haskell nnoremap <buffer> <silent> <Leader>hi :HdevtoolsInfo<CR>
endif
" }
" gundo {
if isdirectory(expand("~/.vim/plugged/gundo.vim"))
nnoremap <F5> :GundoToggle<CR>
endif
" }
" vim-airline {
if isdirectory(expand("~/.vim/plugged/vim-airline"))
if !exists('g:airline_theme')
let g:airline_theme = 'solarized'
endif
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
endif
" }
" YouCompleteMe {
if isdirectory(expand("~/.vim/plugged/YouCompleteMe"))
" global configuration file for C like languages
let g:ycm_global_ycm_extra_conf = '~/.ycm_extra_conf.py'
let g:ycm_filetype_blacklist = {'notes' : 1, 'markdown' : 1, 'text' : 1, 'unite' : 1}
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_confirm_extra_conf = 0
let g:ycm_goto_buffer_command='vertical-split'
" let g:ycm_cache_omnifunc = 1
endif
" }
" MatchTagAlways {
"
let g:mta_filetypes = {
\ 'html' : 1,
\ 'xhtml' : 1,
\ 'xml' : 1,
\ 'jinja' : 1,
\ 'erb' : 1,
\}
" }
" Tagbar {
if isdirectory(expand("~/.vim/plugged/tagbar"))
nmap <leader>tt :TagbarToggle<CR>
endif
" }
" vim-indent-guides {
let g:indent_guides_start_level = 2
let g:indent_guides_guide_size = 1
" }
"
" Goyo {
function! s:goyo_enter()
if has('gui_running')
set fullscreen
set background=light
set linespace=1
set nu
ClearGutters()
elseif exists('$TMUX')
silent !tmux set status off
endif
endfunction
function! s:goyo_leave()
if has('gui_running')
set nofullscreen
set background=dark
ClearGutters()
elseif exists('$TMUX')
silent !tmux set status on
endif
endfunction
autocmd User GoyoEnter nested call <SID>goyo_enter()
autocmd User GoyoLeave nested call <SID>goyo_leave()
" }
" }
"
" vim-project
# This file is NOT licensed under the GPLv3, which is the license for the rest
# of YouCompleteMe.
#
# Here's the license text for this file:
#
# This is free and unencumbered software released into the public domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
# For more information, please refer to <http://unlicense.org/>
import os
import ycm_core
# These are the compilation flags that will be used in case there's no
# compilation database set (by default, one is not set).
# CHANGE THIS LIST OF FLAGS. YES, THIS IS THE DROID YOU HAVE BEEN LOOKING FOR.
flags = [
'-Wall',
'-Wextra',
'-Werror',
'-Wc++98-compat',
'-Wno-long-long',
'-Wno-variadic-macros',
'-fexceptions',
'-DNDEBUG',
# You 100% do NOT need -DUSE_CLANG_COMPLETER in your flags; only the YCM
# source code needs it.
'-DUSE_CLANG_COMPLETER',
# THIS IS IMPORTANT! Without a "-std=<something>" flag, clang won't know which
# language to use when compiling headers. So it will guess. Badly. So C++
# headers will be compiled as C headers. You don't want that so ALWAYS specify
# a "-std=<something>".
# For a C project, you would set this to something like 'c99' instead of
# 'c++11'.
'-std=c++11',
# ...and the same thing goes for the magic -x option which specifies the
# language that the files to be compiled are written in. This is mostly
# relevant for c++ headers.
# For a C project, you would set this to 'c' instead of 'c++'.
'-x',
'c++',
'-isystem',
'../BoostParts',
'-isystem',
# This path will only work on OS X, but extra paths that don't exist are not
# harmful
'/System/Library/Frameworks/Python.framework/Headers',
'-isystem',
'../llvm/include',
'-isystem',
'../llvm/tools/clang/include',
'-I',
'.',
'-I',
'./ClangCompleter',
'-isystem',
'./tests/gmock/gtest',
'-isystem',
'./tests/gmock/gtest/include',
'-isystem',
'./tests/gmock',
'-isystem',
'./tests/gmock/include',
'-lfl',
'-I.'
]
# Set this to the absolute path to the folder (NOT the file!) containing the
# compile_commands.json file to use that instead of 'flags'. See here for
# more details: http://clang.llvm.org/docs/JSONCompilationDatabase.html
#
# You can get CMake to generate this file for you by adding:
# set( CMAKE_EXPORT_COMPILE_COMMANDS 1 )
# to your CMakeLists.txt file.
#
# Most projects will NOT need to set this to anything; you can just change the
# 'flags' list of compilation flags. Notice that YCM itself uses that approach.
compilation_database_folder = ''
if os.path.exists( compilation_database_folder ):
database = ycm_core.CompilationDatabase( compilation_database_folder )
else:
database = None
SOURCE_EXTENSIONS = [ '.cpp', '.cxx', '.cc', '.c', '.m', '.mm' ]
def DirectoryOfThisScript():
return os.path.dirname( os.path.abspath( __file__ ) )
def MakeRelativePathsInFlagsAbsolute( flags, working_directory ):
if not working_directory:
return list( flags )
new_flags = []
make_next_absolute = False
path_flags = [ '-isystem', '-I', '-iquote', '--sysroot=' ]
for flag in flags:
new_flag = flag
if make_next_absolute:
make_next_absolute = False
if not flag.startswith( '/' ):
new_flag = os.path.join( working_directory, flag )
for path_flag in path_flags:
if flag == path_flag:
make_next_absolute = True
break
if flag.startswith( path_flag ):
path = flag[ len( path_flag ): ]
new_flag = path_flag + os.path.join( working_directory, path )
break
if new_flag:
new_flags.append( new_flag )
return new_flags
def IsHeaderFile( filename ):
extension = os.path.splitext( filename )[ 1 ]
return extension in [ '.h', '.hxx', '.hpp', '.hh' ]
def GetCompilationInfoForFile( filename ):
# The compilation_commands.json file generated by CMake does not have entries
# for header files. So we do our best by asking the db for flags for a
# corresponding source file, if any. If one exists, the flags for that file
# should be good enough.
if IsHeaderFile( filename ):
basename = os.path.splitext( filename )[ 0 ]
for extension in SOURCE_EXTENSIONS:
replacement_file = basename + extension
if os.path.exists( replacement_file ):
compilation_info = database.GetCompilationInfoForFile(
replacement_file )
if compilation_info.compiler_flags_:
return compilation_info
return None
return database.GetCompilationInfoForFile( filename )
def FlagsForFile( filename, **kwargs ):
if database:
# Bear in mind that compilation_info.compiler_flags_ does NOT return a
# python list, but a "list-like" StringVec object
compilation_info = GetCompilationInfoForFile( filename )
if not compilation_info:
return None
final_flags = MakeRelativePathsInFlagsAbsolute(
compilation_info.compiler_flags_,
compilation_info.compiler_working_dir_ )
# NOTE: This is just for YouCompleteMe; it's highly likely that your project
# does NOT need to remove the stdlib flag. DO NOT USE THIS IN YOUR
# ycm_extra_conf IF YOU'RE NOT 100% SURE YOU NEED IT.
try:
final_flags.remove( '-stdlib=libc++' )
except ValueError:
pass
else:
relative_to = DirectoryOfThisScript()
final_flags = MakeRelativePathsInFlagsAbsolute( flags, relative_to )
return {
'flags': final_flags,
'do_cache': True
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment