"""""""" " If error when loading about 'Unknown Command: ^M', run the following: " :w ++ff=unix """""""" " 00 - XDG Support if empty($MYVIMRC) | let $MYVIMRC = expand(':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 - NERDCommenterToggle map _ 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 n :NERDTreeToggle 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 a& :Tab /& vmap a& :Tab /& nmap a# :Tab /# vmap a# :Tab /# nmap a= :Tab /^[^=]*\zs= vmap a= :Tab /^[^=]*\zs= nmap a=> :Tab /=> vmap a=> :Tab /=> nmap a: :Tab /: vmap a: :Tab /: nmap a:: :Tab /:\zs vmap a:: :Tab /:\zs nmap a, :Tab /, vmap a, :Tab /, nmap a,, :Tab /,\zs vmap a,, :Tab /,\zs nmap a :Tab / vmap a :Tab / 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 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 Oq 1 inoremap Or 2 inoremap Os 3 inoremap Ot 4 inoremap Ou 5 inoremap Ov 6 inoremap Ow 7 inoremap Ox 8 inoremap Oy 9 inoremap Op 0 inoremap On . inoremap OQ / inoremap OR * inoremap Ol + inoremap OS - inoremap OM 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 outdenting nnoremap n nzzzv " Keep next search result in middle of view nnoremap N Nzzzv " Keey previous search results in middle of view " Map f to toggle folds " If in visual mode, will create a fold " If capital F, will toggle ALL folds below cursor inoremap f za nnoremap f za nnoremap F zA onoremap f za vnoremap f zf nnoremap + :exe "resize " . (winheight(0) * 3/2) nnoremap - :exe "resize " . (winheight(0) * 2/3) nnoremap > :exe "vertical resize " . (winwidth(0) * 3/2) nnoremap < :exe "vertical resize " . (winwidth(0) * 2/3) nnoremap :%s/\s\+$//:let @/='' " Remove trailing whitespace on lines nnoremap :set invwrap wrap? " Toggle wordwrap nnoremap :source $MYVIMRC " Reload .vimrc file noremap bg :call ToggleBG() " Toggle dark/light colors nnoremap q gwip " format paragraph nmap h :nohl " Toggle search hilight nmap p :set paste! " Toggle paste mode nmap sh :split " Split window horizontally nmap sv :vsplit " Split window veritcally nmap sp :setlocal spell! spelllang=en_us " Toggle spell check nmap i :IndentLinesToggle " Toggle indent guides nmap t :tabn " Next tab nmap T :tabp " Previous tab nmap w w " Cycle through splits " Display all occurences of word under cursor and allow quick navigation nmap ff [I:let nr = input("Which one: ")exe "normal " . nr ."[\t" " Wrap line and word with delimiter (follow with [ similar delimiter) nmap d yss nmap D ysiw " Format Commands (start with f for format) " nnoremap j :%!python -m json.tool " Use python for pretty printing json nnoremap fj %!jq " Use jq for pretty printing JSON file nnoremap fcj %!jq --compact-output vnoremap fj :'<,'>!jq " Use jq for pretty printing JSON selection vnoremap fcj :'<,'>!jq --compact-output " 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