|  | """""""" | 
						
						
							|  | " If error when loading about 'Unknown Command: ^M', run the following: | 
						
						
							|  | "   :w ++ff=unix | 
						
						
							|  | """""""" | 
						
						
							|  |  | 
						
						
							|  | " 00 - XDG Support | 
						
						
							|  |     if empty($MYVIMRC) | let $MYVIMRC = expand('<sfile>:p') | endif | 
						
						
							|  |  | 
						
						
							|  |     if empty($XDG_CACHE_HOME)  | let $XDG_CACHE_HOME  = $HOME."/.cache"       | endif | 
						
						
							|  |     if empty($XDG_CONFIG_HOME) | let $XDG_CONFIG_HOME = $HOME."/.config"      | endif | 
						
						
							|  |     if empty($XDG_DATA_HOME)   | let $XDG_DATA_HOME   = $HOME."/.local/share" | endif | 
						
						
							|  |     if empty($XDG_STATE_HOME)  | let $XDG_STATE_HOME  = $HOME."/.local/state" | endif | 
						
						
							|  |  | 
						
						
							|  |     set runtimepath^=$XDG_CONFIG_HOME/vim | 
						
						
							|  |     set runtimepath+=$XDG_DATA_HOME/vim | 
						
						
							|  |     set runtimepath+=$XDG_CONFIG_HOME/vim/after | 
						
						
							|  |  | 
						
						
							|  |     set packpath^=$XDG_DATA_HOME/vim,$XDG_CONFIG_HOME/vim | 
						
						
							|  |     set packpath+=$XDG_CONFIG_HOME/vim/after,$XDG_DATA_HOME/vim/after | 
						
						
							|  |  | 
						
						
							|  |     let g:netrw_home = $XDG_DATA_HOME."/vim" | 
						
						
							|  |     call mkdir($XDG_DATA_HOME."/vim/spell", 'p', 0700) | 
						
						
							|  |  | 
						
						
							|  |     set backupdir=$XDG_STATE_HOME/vim/backup | call mkdir(&backupdir, 'p', 0700) | 
						
						
							|  |     set directory=$XDG_STATE_HOME/vim/swap   | call mkdir(&directory, 'p', 0700) | 
						
						
							|  |     set undodir=$XDG_STATE_HOME/vim/undo     | call mkdir(&undodir,   'p', 0700) | 
						
						
							|  |     set viewdir=$XDG_STATE_HOME/vim/view     | call mkdir(&viewdir,   'p', 0700) | 
						
						
							|  |  | 
						
						
							|  |     if !has('nvim') " Neovim has its own special location | 
						
						
							|  |         set viminfofile=$XDG_STATE_HOME/vim/viminfo | 
						
						
							|  |     endif | 
						
						
							|  |  | 
						
						
							|  | " 01 - General | 
						
						
							|  |     filetype plugin on          " Enable filetype-specific plugins | 
						
						
							|  |  | 
						
						
							|  |     set foldenable              " Fold by default | 
						
						
							|  |     set foldmethod=indent | 
						
						
							|  |     set foldlevel=2             " Default fold levelss to leave open | 
						
						
							|  |     set modelines=0             " Dont need modelines and the potential security hazard | 
						
						
							|  |  | 
						
						
							|  |     set spell                   " Enable spellcheck (see keybindings for quick toggle) | 
						
						
							|  |  | 
						
						
							|  |     "set mouse=a                " Enable mouse control | 
						
						
							|  |     set mouse=                  " Disable mouse control | 
						
						
							|  |     set mousehide               " Hide the mouse cursor while typing | 
						
						
							|  |     set encoding=utf-8 | 
						
						
							|  |  | 
						
						
							|  |     set history=300             " Default is 20 | 
						
						
							|  |     set undolevels=300 | 
						
						
							|  |  | 
						
						
							|  |     set backspace=indent,eol,start  " Make backspace act like most other applications | 
						
						
							|  |  | 
						
						
							|  |     let g:netrw_dirhistmax=0    " Do not create the network history files | 
						
						
							|  |     let mapleader = ","         " Leader key (default: \) | 
						
						
							|  |  | 
						
						
							|  | " 02 - Plugin/Bundle Related | 
						
						
							|  |     runtime! macros/matchit.vim | 
						
						
							|  |  | 
						
						
							|  |     " Install vim-plug if doesn't exist | 
						
						
							|  |     let data_dir = '$XDG_CONFIG_HOME/vim' | 
						
						
							|  |     let plug_dir = data_dir . '/plugged' | 
						
						
							|  |     if empty(glob(data_dir . '/autoload/plug.vim')) | 
						
						
							|  |         silent execute '!curl -fsSLo '.data_dir.'/autoload/plug.vim --create-dirs  https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' | 
						
						
							|  |         autocmd VimEnter * PlugInstall --sync | source $MYVIMRC | 
						
						
							|  |     endif | 
						
						
							|  |  | 
						
						
							|  |     " Load Plugins | 
						
						
							|  |     silent! if plug#begin(plug_dir) | 
						
						
							|  |         Plug 'morhetz/gruvbox' | 
						
						
							|  |         Plug 'itchyny/lightline.vim' | 
						
						
							|  |         Plug 'preservim/nerdcommenter' | 
						
						
							|  |         Plug 'scrooloose/nerdtree' | 
						
						
							|  |         Plug 'vim-python/python-syntax' | 
						
						
							|  |         Plug 'godlygeek/tabular' | 
						
						
							|  |         Plug 'mzlogin/vim-markdown-toc' | 
						
						
							|  |         Plug 'tpope/vim-surround' | 
						
						
							|  |  | 
						
						
							|  |         " if v:version >= 703 | 
						
						
							|  |         " endif | 
						
						
							|  |         " | 
						
						
							|  |         call plug#end() | 
						
						
							|  |     endif | 
						
						
							|  |  | 
						
						
							|  |     " Plugin - lightline | 
						
						
							|  |         if isdirectory(expand(plug_dir . '/lightline.vim')) | 
						
						
							|  |             let g:lightline = { | 
						
						
							|  |                 \ 'active': { | 
						
						
							|  |                 \   'left': [ [ 'mode', 'paste' ], | 
						
						
							|  |                 \             [ 'readonly', 'filename', 'modified', 'charvaluehex' ] ] | 
						
						
							|  |                 \ }, | 
						
						
							|  |                 \ 'component': { | 
						
						
							|  |                 \   'charvaluehex': '0x%B' | 
						
						
							|  |                 \ }, | 
						
						
							|  |                 \ } | 
						
						
							|  |         endif | 
						
						
							|  |  | 
						
						
							|  |     " Plugin - NERDCommenter | 
						
						
							|  |         let g:NERDSpaceDelims = 1   " Add spaces after comment delimiters by default | 
						
						
							|  |         map - <plug>NERDCommenterToggle | 
						
						
							|  |         map _ <plug>NERDCommenterUncomment | 
						
						
							|  |  | 
						
						
							|  |     " Plugin - NERDTree related | 
						
						
							|  |         if isdirectory(expand(plug_dir . '/nerdtree')) | 
						
						
							|  |             " Open NERDTree when opening nothing (just vim) | 
						
						
							|  |             autocmd StdinReadPre * let s:std_in=1 | 
						
						
							|  |             autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif | 
						
						
							|  |  | 
						
						
							|  |             " Open NERDTree when opening directory | 
						
						
							|  |             autocmd StdinReadPre * let s:std_in=1 | 
						
						
							|  |             autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | endif | 
						
						
							|  |  | 
						
						
							|  |             map <leader>n :NERDTreeToggle<CR> | 
						
						
							|  |  | 
						
						
							|  |             let NERDTreeShowBookmarks=1 | 
						
						
							|  |             let NERDTreeIgnore=['\\.pyc', '\\\~$', '\\.swo$', '\\.swp$', '\\.git', '\\.hg', '\\.svn', '\\.bzr'] | 
						
						
							|  |         endif | 
						
						
							|  |  | 
						
						
							|  |     " Plugin - python-syntax | 
						
						
							|  |         let g:python_highlight_all = 1 | 
						
						
							|  |  | 
						
						
							|  |     " Plugin - Tabular | 
						
						
							|  |         if isdirectory(expand(plug_dir . '/tabular')) | 
						
						
							|  |             nmap <leader>a& :Tab /&<CR> | 
						
						
							|  |             vmap <leader>a& :Tab /&<CR> | 
						
						
							|  |             nmap <leader>a# :Tab /#<CR> | 
						
						
							|  |             vmap <leader>a# :Tab /#<CR> | 
						
						
							|  |             nmap <leader>a= :Tab /^[^=]*\zs=<CR> | 
						
						
							|  |             vmap <leader>a= :Tab /^[^=]*\zs=<CR> | 
						
						
							|  |             nmap <leader>a=> :Tab /=><CR> | 
						
						
							|  |             vmap <leader>a=> :Tab /=><CR> | 
						
						
							|  |             nmap <leader>a: :Tab /:<CR> | 
						
						
							|  |             vmap <leader>a: :Tab /:<CR> | 
						
						
							|  |             nmap <leader>a:: :Tab /:\zs<CR> | 
						
						
							|  |             vmap <leader>a:: :Tab /:\zs<CR> | 
						
						
							|  |             nmap <leader>a, :Tab /,<CR> | 
						
						
							|  |             vmap <leader>a, :Tab /,<CR> | 
						
						
							|  |             nmap <leader>a,, :Tab /,\zs<CR> | 
						
						
							|  |             vmap <leader>a,, :Tab /,\zs<CR> | 
						
						
							|  |             nmap <leader>a<Bar> :Tab /<Bar><CR> | 
						
						
							|  |             vmap <leader>a<Bar> :Tab /<Bar><CR> | 
						
						
							|  |         endif | 
						
						
							|  |  | 
						
						
							|  | " 03 - VIM UI | 
						
						
							|  |     syntax on               " Enable syntax highlighting | 
						
						
							|  |     match ErrorMsg '\s\+$'  " Highlight spaces (makes it obvious when trailing) | 
						
						
							|  |  | 
						
						
							|  |     colorscheme gruvbox | 
						
						
							|  |     set background=dark | 
						
						
							|  |     set cul          " Highlight the current line | 
						
						
							|  |     set ignorecase   " Case insensitive search | 
						
						
							|  |     set smartcase    " If a capital lever is included in search, make it case-sensitive | 
						
						
							|  |     set incsearch    " Show matches as you type | 
						
						
							|  |     set hlsearch     " Highlight search results | 
						
						
							|  |     set laststatus=2 " 0 to never show status line, 1 means only if >1 windows, 2 means always | 
						
						
							|  |     set number       " Enable line numbers | 
						
						
							|  |     set ruler        " Enable the ruler | 
						
						
							|  |     set scrolljump=5 " Lines to scroll when cursor leaves screen | 
						
						
							|  |     set scrolloff=3  " Always show two lines around the cursor when scrolling | 
						
						
							|  |     set noerrorbells | 
						
						
							|  |     set noerrorbells " Don't sound warning on error | 
						
						
							|  |     set visualbell   " Don't blink on error | 
						
						
							|  |     set t_vb=        " Disable visual blink | 
						
						
							|  |  | 
						
						
							|  |     " Allow for transparent consoles | 
						
						
							|  |     hi Normal guibg=NONE ctermbg=NONE | 
						
						
							|  |     hi NonText ctermbg=NONE | 
						
						
							|  |  | 
						
						
							|  |     set wildmenu      " visual autocomplete for command menu (below settings ignore this option for certain file types) | 
						
						
							|  |     set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all. | 
						
						
							|  |     set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*,*.bak,*.exe | 
						
						
							|  |     set wildignore+=*.pyc,*.DS_Store,*.db | 
						
						
							|  |  | 
						
						
							|  |     function! ToggleBG() | 
						
						
							|  |         let s:tbg = &background | 
						
						
							|  |         if s:tbg == "dark" | 
						
						
							|  |             set background=light | 
						
						
							|  |         else | 
						
						
							|  |             set background=dark | 
						
						
							|  |         endif | 
						
						
							|  |     endfunction | 
						
						
							|  |  | 
						
						
							|  | " 04 - Formatting Layout | 
						
						
							|  |     set autoindent      " Use indent of previous line after hitting enter to create a new line | 
						
						
							|  |     set copyindent      " Copy the previous indentation on autoindenting | 
						
						
							|  |     set expandtab       " Change tabs to spaces | 
						
						
							|  |     set shiftround      " use multiple of shiftwidth when indenting with '<' and '>' | 
						
						
							|  |     set smarttab        " Insert tabs on the start of a line according to shiftwidth, not tabstop | 
						
						
							|  |     set shiftwidth=4    " Number of spaces to use for autoindenting | 
						
						
							|  |     set softtabstop=4   " Let backspace delete indent | 
						
						
							|  |     set tabstop=4       " A tab is x spaces | 
						
						
							|  |     set textwidth=0 | 
						
						
							|  |     set wrapmargin=0 | 
						
						
							|  |  | 
						
						
							|  | " 05 - Keybindings | 
						
						
							|  |     " Modes - Prefex of map and remap (ie modes 'n' and 'o' for nomap) | 
						
						
							|  |     " * n: normal only | 
						
						
							|  |     " * v: visual and select | 
						
						
							|  |     " * o: operator-pending | 
						
						
							|  |     " * x: visual only | 
						
						
							|  |     " * s: select only | 
						
						
							|  |     " * i: insert | 
						
						
							|  |     " * c: command-line | 
						
						
							|  |     " * l: insert, command-line, regexp-search (and others. Collectively called 'Lang-Arg' pseudo-mode) | 
						
						
							|  |  | 
						
						
							|  |     " Don't remap the numpad | 
						
						
							|  |     inoremap <Esc>Oq 1 | 
						
						
							|  |     inoremap <Esc>Or 2 | 
						
						
							|  |     inoremap <Esc>Os 3 | 
						
						
							|  |     inoremap <Esc>Ot 4 | 
						
						
							|  |     inoremap <Esc>Ou 5 | 
						
						
							|  |     inoremap <Esc>Ov 6 | 
						
						
							|  |     inoremap <Esc>Ow 7 | 
						
						
							|  |     inoremap <Esc>Ox 8 | 
						
						
							|  |     inoremap <Esc>Oy 9 | 
						
						
							|  |     inoremap <Esc>Op 0 | 
						
						
							|  |     inoremap <Esc>On . | 
						
						
							|  |     inoremap <Esc>OQ / | 
						
						
							|  |     inoremap <Esc>OR * | 
						
						
							|  |     inoremap <Esc>Ol + | 
						
						
							|  |     inoremap <Esc>OS - | 
						
						
							|  |     inoremap <Esc>OM <Enter> | 
						
						
							|  |  | 
						
						
							|  |     cmap cwd lcd %:p:h " change working directory to current file | 
						
						
							|  |  | 
						
						
							|  |     nnoremap j gj       " Move to next line (not remapped line from wordwrap) | 
						
						
							|  |     nnoremap k gk       " Move to previous line (not remapped line from wordwrap) | 
						
						
							|  |     vnoremap Q gq       " Word wrap visually highlighted line | 
						
						
							|  |     nnoremap Q gqap     " Word wrap line | 
						
						
							|  |     vnoremap < <gv      " Retain visual selection when indenting | 
						
						
							|  |     vnoremap > >gv      " Retain visual selection when outdenting | 
						
						
							|  |     nnoremap n nzzzv    " Keep next search result in middle of view | 
						
						
							|  |     nnoremap N Nzzzv    " Keey previous search results in middle of view | 
						
						
							|  |  | 
						
						
							|  |     " Map <leader>f to toggle folds | 
						
						
							|  |     " If in visual mode, will create a fold | 
						
						
							|  |     " If capital F, will toggle ALL folds below cursor | 
						
						
							|  |     inoremap <leader>f <C-0>za | 
						
						
							|  |     nnoremap <leader>f za | 
						
						
							|  |     nnoremap <leader>F zA | 
						
						
							|  |     onoremap <leader>f <C-C>za | 
						
						
							|  |     vnoremap <leader>f zf | 
						
						
							|  |  | 
						
						
							|  |     nnoremap <silent><Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR> | 
						
						
							|  |     nnoremap <silent><Leader>- :exe "resize " . (winheight(0) * 2/3)<CR> | 
						
						
							|  |     nnoremap <silent><Leader>> :exe "vertical resize " . (winwidth(0) * 3/2)<CR> | 
						
						
							|  |     nnoremap <silent><Leader>< :exe "vertical resize " . (winwidth(0) * 2/3)<CR> | 
						
						
							|  |  | 
						
						
							|  |     nnoremap <leader><F2> :%s/\s\+$//<cr>:let @/=''<CR> " Remove trailing whitespace on lines | 
						
						
							|  |     nnoremap <leader><F3> :set invwrap wrap?<CR>        " Toggle wordwrap | 
						
						
							|  |     nnoremap <leader><F4> :source $MYVIMRC<CR>          " Reload .vimrc file | 
						
						
							|  |  | 
						
						
							|  |     noremap <leader>bg :call ToggleBG()<CR> " Toggle dark/light colors | 
						
						
							|  |     nnoremap <silent> <leader>q gwip        " format paragraph | 
						
						
							|  |     nmap <leader>h :nohl<CR>                " Toggle search hilight | 
						
						
							|  |     nmap <leader>p :set paste!<CR>          " Toggle paste mode | 
						
						
							|  |     nmap <leader>sh :split<CR>              " Split window horizontally | 
						
						
							|  |     nmap <leader>sv :vsplit<CR>             " Split window veritcally | 
						
						
							|  |     nmap <leader>sp :setlocal spell! spelllang=en_us<CR>  " Toggle spell check | 
						
						
							|  |     nmap <leader>i :IndentLinesToggle<CR>   " Toggle indent guides | 
						
						
							|  |     nmap <leader>t :tabn<CR>                " Next tab | 
						
						
							|  |     nmap <leader>T :tabp<CR>                " Previous tab | 
						
						
							|  |     nmap <leader>w <C-w>w                   " Cycle through splits | 
						
						
							|  |  | 
						
						
							|  |     " Display all occurences of word under cursor and allow quick navigation | 
						
						
							|  |     nmap ff [I:let nr = input("Which one: ")<Bar>exe "normal " . nr ."[\t"<CR> | 
						
						
							|  |  | 
						
						
							|  |     " Wrap line and word with delimiter (follow with [ similar delimiter) | 
						
						
							|  |     nmap <leader>d yss | 
						
						
							|  |     nmap <leader>D ysiw | 
						
						
							|  |  | 
						
						
							|  |     " Format Commands (start with f for format) | 
						
						
							|  |     " nnoremap <leader>j :%!python -m json.tool<CR>     " Use python for pretty printing json | 
						
						
							|  |     nnoremap <silent> <Leader>fj <Cmd>%!jq<CR>          " Use jq for pretty printing JSON file | 
						
						
							|  |     nnoremap <silent> <Leader>fcj <Cmd>%!jq --compact-output<CR> | 
						
						
							|  |     vnoremap <silent> <Leader>fj :'<,'>!jq<CR>          " Use jq for pretty printing JSON selection | 
						
						
							|  |     vnoremap <silent> <Leader>fcj :'<,'>!jq --compact-output<CR> | 
						
						
							|  |  | 
						
						
							|  | " 06 - Neovim LSPs | 
						
						
							|  | if has('nvim') | 
						
						
							|  |     "let g:loaded_python3_provider = 0 " Disable python plugins for now - :help provider-python | 
						
						
							|  |     let g:loaded_python3_provider = '/usr/bin/python3' | 
						
						
							|  |     let g:loaded_ruby_provider = 0    " Disable Ruby plugins | 
						
						
							|  |     let g:loaded_node_provider = 0    " Disable node plugins | 
						
						
							|  | endif
 |