Last active
July 5, 2017 15:31
-
-
Save AhmedAKhan/da9a08ad97ff1259b1cc0da6a17a857d to your computer and use it in GitHub Desktop.
this is my vimrc file
This file contains hidden or 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
| set nocompatible " be iMproved, required | |
| filetype off " required | |
| "" Vundle Plugin { | |
| " 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 'VundleVim/Vundle.vim' | |
| Plugin 'tpope/vim-fugitive' " git integeration | |
| Plugin 'majutsushi/tagbar' " f2, tags of functions | |
| Plugin 'christoomey/vim-tmux-navigator' " tmux config | |
| Plugin 'godlygeek/tabular' " aligns text for you | |
| Plugin 'rking/ag.vim' " silver search in vim | |
| Plugin 'tpope/vim-surround' " cs = surround | |
| Plugin 'tpope/vim-commentary' " gcc = generates comment | |
| " -- UI plugins --- | |
| Plugin 'vim-airline/vim-airline' " bottom visual bar | |
| Plugin 'altercation/vim-colors-solarized' " ehhh useless color scheme | |
| Plugin 'spf13/vim-colors' | |
| " All of your Plugins must be added before the following line | |
| call vundle#end() " required | |
| filetype plugin indent on " required | |
| "" } | |
| "" Pythogen {" | |
| execute pathogen#infect() | |
| syntax on | |
| filetype plugin indent on | |
| "" } | |
| """ config variable { | |
| set nospell " turns off spelling mistakes | |
| set hidden " sets buffer switching without saving | |
| set history=1000 " store alot more history | |
| set nu " line numbers | |
| set rnu " relative line numbers | |
| set cursorline " hightlight the current line | |
| set hlsearch " highlights search | |
| set showmatch " show matching brackets | |
| set linespace=0 | |
| set ignorecase " ignore case when searching | |
| set smartcase " smart case when uc present | |
| set wildmenu " show case 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 backup " backups are nice :) | |
| if has('persistent_undo') | |
| set undofile " persistent undo so you can exit and come back to the file | |
| set undolevels=1000 " max num of changes that can be undone | |
| set undoreload=10000 " max num lines to save for undo | |
| endif | |
| set nowrap " Do not wrap long lines | |
| set autoindent " Indent at the same level of the previous line | |
| set shiftwidth=2 " Use indents of 4 spaces | |
| set expandtab " Tabs are spaces, not tabs | |
| set tabstop=2 " An indentation every four columns | |
| set softtabstop=2 " 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) | |
| set foldmethod=indent " other fold methods include syntax,custom,.. | |
| " remove trailing whitespaces | |
| 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 | |
| "" } | |
| "" key bindings { | |
| let mapleader = ',' | |
| noremap j gj | |
| noremap k gk | |
| " Yank from the cursor to the end of the line, yanks the text not the new line | |
| nnoremap Y y$ | |
| let g:spf13_no_wrapRelMotion = 1 | |
| " End/Start of line motion keys act relative to row/wrap width in the | |
| " presence of `:set wrap`, and relative to line for `:set nowrap`. | |
| " Default vim behaviour is to act relative to text line in both cases | |
| " If you prefer the default behaviour, add the following to your | |
| " .vimrc.before.local file: | |
| " let g:spf13_no_wrapRelMotion = 1 | |
| if !exists('g:spf13_no_wrapRelMotion') | |
| " Same for 0, home, end, etc | |
| function! WrapRelativeMotion(key, ...) | |
| let vis_sel="" | |
| if a:0 | |
| let vis_sel="gv" | |
| endif | |
| if &wrap | |
| execute "normal!" vis_sel . "g" . a:key | |
| else | |
| execute "normal!" vis_sel . a:key | |
| endif | |
| endfunction | |
| " Map g* keys in Normal, Operator-pending, and Visual+select | |
| noremap $ :call WrapRelativeMotion("$")<CR> | |
| noremap <End> :call WrapRelativeMotion("$")<CR> | |
| noremap 0 :call WrapRelativeMotion("0")<CR> | |
| noremap <Home> :call WrapRelativeMotion("0")<CR> | |
| noremap ^ :call WrapRelativeMotion("^")<CR> | |
| " Overwrite the operator pending $/<End> mappings from above | |
| " to force inclusive motion with :execute normal! | |
| onoremap $ v:call WrapRelativeMotion("$")<CR> | |
| onoremap <End> v:call WrapRelativeMotion("$")<CR> | |
| " Overwrite the Visual+select mode mappings from above | |
| " to ensure the correct vis_sel flag is passed to function | |
| vnoremap $ :<C-U>call WrapRelativeMotion("$", 1)<CR> | |
| vnoremap <End> :<C-U>call WrapRelativeMotion("$", 1)<CR> | |
| vnoremap 0 :<C-U>call WrapRelativeMotion("0", 1)<CR> | |
| vnoremap <Home> :<C-U>call WrapRelativeMotion("0", 1)<CR> | |
| vnoremap ^ :<C-U>call WrapRelativeMotion("^", 1)<CR> | |
| endif | |
| " Find merge conflict markers | |
| map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR> | |
| " clear search when searching for something new | |
| nmap <silent> <leader>/ :nohlsearch<CR> | |
| " Visual shifting (does not exit Visual mode) | |
| vnoremap < <gv | |
| vnoremap > >gv | |
| " 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 | |
| " maps tab and shift tab for next and previous buffer | |
| nnoremap <Tab> :bnext<CR> | |
| nnoremap <S-Tab> :bprevious<CR> | |
| " f5 will let you write a buffer and go to it | |
| nnoremap <f5> :buffers<CR>:buffer<Space> | |
| " will show you the methods and functions in file | |
| nmap <f2> :TagbarToggle<CR> | |
| " saves the file and goes to the previous state | |
| nmap <f9> :w<CR> | |
| imap <f9> <ESC>:w<CR>i | |
| vmap <f9> <ESC>:w<CR>v | |
| " will remove the highlights | |
| map <f11> :noh<CR> | |
| " unmaps f1 to help | |
| imap <f1> <nop> | |
| nmap <f1> <nop> | |
| vmap <f1> <nop> | |
| " change nerd tree mapping | |
| nmap <silent> <f1> <ESC>:NERDTreeToggle<CR> | |
| " allows tmux + vim navigation | |
| nnoremap <silent> <C-h> :TmuxNavigationLeft<CR> | |
| nnoremap <silent> <C-l> :TmuxNavigationRight<CR> | |
| nnoremap <silent> <C-k> :TmuxNavigationUp<CR> | |
| nnoremap <silent> <C-j> :TmuxNavigationDown<CR> | |
| nnoremap <silent> <C-j> :TmuxNavigationDown<CR> | |
| "" map f2 to tagbar | |
| nmap <f2> :TagbarToggle<CR> | |
| "" } | |
| "Plugins Configuration{ | |
| " Ctags { | |
| set tags=./tags;/,~/.vimtags | |
| " Make tags placed in .git/tags file available in all levels of a repository | |
| let gitroot = substitute(system('git rev-parse --show-toplevel'), '[\n\r]', '', 'g') | |
| if gitroot != '' | |
| let &tags = &tags . ',' . gitroot . '/.git/tags' | |
| 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")) | |
| map <Leader>a :Tabularize | |
| 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 /:<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 | |
| " } | |
| " | |
| " JSON { | |
| nmap <leader>jt <Esc>:%!python -m json.tool<CR><Esc>:set filetype=json<CR> | |
| let g:vim_json_syntax_conceal = 0 | |
| " } | |
| " ctrlp { | |
| if isdirectory(expand("~/.vim/bundle/ctrlp.vim/")) | |
| let g:ctrlp_working_path_mode = 'ra' | |
| nnoremap <silent> <D-t> :CtrlP<CR> | |
| nnoremap <silent> <D-r> :CtrlPMRU<CR> | |
| let g:ctrlp_custom_ignore = { | |
| \ 'dir': '\.git$\|\.hg$\|\.svn$', | |
| \ 'file': '\.exe$\|\.so$\|\.dll$\|\.pyc$' } | |
| if executable('ag') | |
| let s:ctrlp_fallback = 'ag %s --nocolor -l -g ""' | |
| elseif executable('ack-grep') | |
| let s:ctrlp_fallback = 'ack-grep %s --nocolor -f' | |
| elseif executable('ack') | |
| let s:ctrlp_fallback = 'ack %s --nocolor -f' | |
| " On Windows use "dir" as fallback command. | |
| elseif WINDOWS() | |
| let s:ctrlp_fallback = 'dir %s /-n /b /s /a-d' | |
| else | |
| let s:ctrlp_fallback = 'find %s -type f' | |
| endif | |
| if exists("g:ctrlp_user_command") | |
| unlet g:ctrlp_user_command | |
| endif | |
| let g:ctrlp_user_command = { | |
| \ 'types': { | |
| \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'], | |
| \ 2: ['.hg', 'hg --cwd %s locate -I .'], | |
| \ }, | |
| \ 'fallback': s:ctrlp_fallback | |
| \ } | |
| if isdirectory(expand("~/.vim/bundle/ctrlp-funky/")) | |
| " CtrlP extensions | |
| let g:ctrlp_extensions = ['funky'] | |
| "funky | |
| nnoremap <Leader>fu :CtrlPFunky<Cr> | |
| endif | |
| endif | |
| "} | |
| " indent_guides { | |
| if isdirectory(expand("~/.vim/bundle/vim-indent-guides/")) | |
| let g:indent_guides_start_level = 2 | |
| let g:indent_guides_guide_size = 1 | |
| let g:indent_guides_enable_on_vim_startup = 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. | |
| " See `:echo g:airline_theme_map` for some more choices | |
| " Default in terminal vim is 'dark' | |
| if isdirectory(expand("~/.vim/bundle/vim-airline-themes/")) | |
| 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 | |
| " } | |
| " | |
| " Syntastic { | |
| set statusline+=%#warningmsg# | |
| set statusline+=%{SyntasticStatuslineFlag()} | |
| set statusline+=%* | |
| let g:syntastic_always_populate_loc_list = 1 | |
| let g:syntastic_auto_loc_list = 1 | |
| let g:syntastic_check_on_open = 1 | |
| let g:syntastic_check_on_wq = 0 | |
| " } | |
| " Functions { | |
| " Initialize directories { | |
| function! InitializeDirectories() | |
| let parent = $HOME . "/.vimTempFiles" | |
| 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 | |
| " } | |
| " } | |
| "} | |
| "" UI { | |
| if has('statusline') | |
| set laststatus=2 | |
| " Broken down into easily includeable segments | |
| set statusline=%<%f\ " Filename | |
| set statusline+=%w%h%m%r " Options | |
| if !exists('g:override_spf13_bundles') | |
| 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 | |
| "" } | |
| " Use local vimrc if available { | |
| if filereadable(expand("~/.vimrc.local")) | |
| source ~/.vimrc.local | |
| endif | |
| " } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment