Skip to content

Instantly share code, notes, and snippets.

@shaypal5
Created July 31, 2019 16:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaypal5/c016b3f1d08d326060a0d444fa3f3a7b to your computer and use it in GitHub Desktop.
Save shaypal5/c016b3f1d08d326060a0d444fa3f3a7b to your computer and use it in GitHub Desktop.
My current .vimrc
" :echom "Loading Shay's .vimrc!"
" === vim-plug plugin manager ===
" automatic installation of vim-plug itself, if missing
if empty(glob('~/.vim/autoload/plug.vim'))
:echom "vim-plug is missing. Installing vim-plug..."
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin('~/.vim/plugged')
" :echom "Updating vim-plug, if needed..."
" :PlugUpgrade
" :echom "Installing uninstalled plugins, if any..."
" :PlugInstall
if !empty(filter(copy(g:plugs), '!isdirectory(v:val.dir)'))
autocmd VimEnter * PlugInstall | q
endif
" File tree/explorer for vim
Plug 'scrooloose/nerdtree'
" Git symbols on files in NERDtree
Plug 'Xuyuanp/nerdtree-git-plugin'
" A Vim plugin which shows a git diff in the 'gutter' (sign column). It shows whether each line has been added, modified, and where lines have been removed. You can also stage and undo individual hunks.
Plug 'airblade/vim-gitgutter'
" Manage python virtualenvs; I just use it to showup in airline
" Plug 'mcantrell/vim-virtualenv'
" Lean & mean status/tabline for vim that's light as air.
Plug 'vim-airline/vim-airline'
" Themes for vim-airline
Plug 'vim-airline/vim-airline-themes'
" Git commands inside vim, like :Gcommit
Plug 'tpope/vim-fugitive'
" Turns vim into a Python IDE
Plug 'python-mode/python-mode', {'branch': 'develop'}
" Faster automatic folding, for vim generally
Plug 'Konfekt/FastFold'
" better folding using a plugin
Plug 'tmhedberg/SimpylFold'
" Vim plugin for previewing markup files
Plug 'greyblake/vim-preview'
" Standalone (from python-mode) flake8 plugin
Plug 'nvie/vim-flake8'
" Comment/Uncomment plugin
"Plug 'tpope/vim-commentary'
Plug 'tomtom/tcomment_vim'
" Easy find and replace - run ':help far.vim' for help
Plug 'brooth/far.vim'
" Many themes/color schemes, including tommorow night eighties
Plug 'chriskempson/base16-vim'
" Monokai theme
Plug 'crusoexia/vim-monokai'
" Jedi autocompletion for vim
" Plug 'davidhalter/jedi-vim'
" Required by vim-easyclip
Plug 'tpope/vim-repeat'
" Copy to clipboard: y copys to clipboard, m deletes to clipboard, d just
" deletes - ended up not working
" Plug 'svermeulen/vim-easyclip'
" Might enable a working yank yo pseudo-clipboard over tmux - ended up not
" working
" Plug 'kana/vim-fakeclip'
Plug 'flazz/vim-colorschemes'
" nice formatting for json files
Plug 'tpope/vim-jdaddy'
" black - The uncompromising Python code formatter
Plug 'python/black'
" Initialize plugin system
call plug#end()
" == vim-plug END OF ===
" === Pathogen package manager setup ===
" Pathogen load
filetype off
" call pathogen#infect()
" call pathogen#helptags()
" execute pathogen#infect()
filetype plugin indent on
syntax on
" === End of Pathogen package manager setup ===
" === General configuration ===
" --- Theme & Colors---
"
" If termguicolors not playing well inside tmux, make sure tmux version is >=
" 2.2
" set termguicolors
set t_Co=256 " vim-monokai now only support 256 colours in terminal.
syntax enable
" set vim base16 colorscheme to match current base16 shell scheme
if filereadable(expand("~/.vimrc_background"))
let base16colorspace=256
source ~/.vimrc_background
endif
"set vim base16 colorscheme manually
"let base16colorspace=256
"colorscheme base16-eighties
" Using the 'flazz/vim-colorschemes' plugin
colorscheme monokai
" hi Folded ctermbg=242
" Should make sure selection is different background, not underline
highlight Visual cterm=reverse ctermbg=NONE
" Nicer highlight for current line
set cursorline
hi CursorLine term=bold cterm=bold guibg=Grey40
" --- END-OF Theme & Colors---
" --- Keys & Controls ---
"
" make the backspace work like in most other programs
set backspace=indent,eol,start
" setting \(backslash) as the leader key
let mapleader = "\\"
map <Space> <Leader>
nnoremap <Leader>x i
set showcmd
" infinite timeout on sequences
set notimeout
set ttimeout
" set macmeta " sets alt as the meta key, can be references as M
" Map <Leader>+S to write. Works in normal mode, must press Esc first
map <Leader>s :w<kEnter>
" Map <Leader>+s to write. Works in insert mode, saves and returns to insert mode
"imap <Leader>s <Esc>:w<kEnter>i
" Map <Leader>+q to quit. Works in normal mode, must press Esc first
map <Leader>q :q<kEnter>
" Map <Leader>+x to save and quit. Works in normal mode, must press Esc first
map <Leader>x :x<kEnter>
" Enable mouse mode
set mouse=a
" should fix the problem of Mouse not working past the 223rd Column
" https://github.com/vim/vim/issues/2309
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
" Enable dragging splits with the mouse over tmux/byobu
" if &term =~ '^screen'
" " tmux knows the extended mouse mode
" set ttymouse=xterm2
" endif
" --- END-OF Keys & Controls ---
" splits open on the right
set splitright
" --- Folds ---
" all folds open by default
" set foldlevel=99
" all folds close by default
set foldlevel=0
set foldmethod=manual
autocmd BufWritePost *.py call Flake8()
" Should open all folds on write
" autocmd BufWritePost *.py normal! zR
" For python: enable folding and make fold method = syntax
" autocmd FileType python setlocal foldenable foldmethod=syntax
" Then follow this to have fold-able docstrings: https://chrisdown.name/2015/02/26/folding-python-docstrings-in-vim.html
" set foldtext=getline(v:foldstart+1)
" Show line numbers
set number
" --- Sharing the clipboard with the OS ---
set clipboard=unnamed
" set clipboard^=unnamedplus
" set clipboard^=unnamed
" set clipboard=unnamed
vmap <C-c> "*y
map <C-P> "*p
" make pasting from clipboard work (no indents etc.)
" toggle paste and then toggle back
set pastetoggle=<F10>
if $TMUX == ''
" set clipboard+=unnamed
" set clipboard^=unnamed
set clipboard=unnamed
endif
" Works as a shared register between instances of vim, in all usecases
vmap <leader>y :w! /tmp/vitmp<CR>
nmap <leader>p :r! cat /tmp/vitmp<CR>
" --- END-OF Sharing the clipboard with the OS ---
set encoding=utf-8
" 4-spaces indents (and not tabs)
filetype plugin indent on
" show existing tab with 4 spaces width
set tabstop=4
" when indenting with '>', use 4 spaces width
set shiftwidth=4
" On pressing tab, insert 4 spaces
set expandtab
" Jumping between splits with jklh keys
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" set pythonhome=$HOME/.pyenv/versions/2.7.11
" set pythondll=$HOME/.pyenv/versions/2.7.11/lib/libpython2.7.dylib
" set pythonthreehome=$HOME/.pyenv/versions/3.6.2
" set pythonthreedll=$HOME/.pyenv/versions/3.6.2/lib/libpython3.6m.a
" automatically open all folds when opening a file
au BufRead * normal zR
" change with BufWinEnter if needed
" ---- change cursor shape according to mode ---
" let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
" let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
" let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
" === End of General Configuration ===
" === NERDtree configuration ===
autocmd vimenter * NERDTree
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
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
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" NERDTree window width
let g:NERDTreeWinSize=25
" Always open in tab
" let NERDTreeMapOpenInTab='<ENTER>'
" Always show hidden files (including dot files)
let NERDTreeShowHidden=1
" don't show some specific file types
let NERDTreeIgnore = ['\.pyc$', '\.DS_Store$', '\.egg*', '__pycache__$', '\.vscode$', '\.ropeproject*']
" NERDTress File highlighting
function! NERDTreeHighlightFile(extension, fg, bg, guifg, guibg)
exec 'autocmd filetype nerdtree highlight ' . a:extension .' ctermbg='. a:bg .' ctermfg='. a:fg .' guibg='. a:guibg .' guifg='. a:guifg
exec 'autocmd filetype nerdtree syn match ' . a:extension .' #^\s\+.*'. a:extension .'$#'
endfunction
call NERDTreeHighlightFile('jade', 'green', 'none', 'green', '#151515')
call NERDTreeHighlightFile('ini', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('md', 'blue', 'none', '#3366FF', '#151515')
call NERDTreeHighlightFile('yml', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('config', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('conf', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('json', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('html', 'yellow', 'none', 'yellow', '#151515')
call NERDTreeHighlightFile('styl', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('css', 'cyan', 'none', 'cyan', '#151515')
call NERDTreeHighlightFile('coffee', 'Red', 'none', 'red', '#151515')
call NERDTreeHighlightFile('js', 'Red', 'none', '#ffa500', '#151515')
call NERDTreeHighlightFile('php', 'Magenta', 'none', '#ff00ff', '#151515')
call NERDTreeHighlightFile('py', 'Magenta', 'none', '#ff00ff', '#151515')
" === End of NERDtree configuration ===
" === python-mode configuration ===
" Turn on python-mode plugin
let g:pymode = 1
" Python 3 syntax checking
let g:pymode_python = 'python3'
" Turn off plugin's warnings
let g:pymode_warnings = 1
" Enable automatic virutalenv detection
let g:pymode_virtualenv = 1
" My virutalenv
let g:pymode_virtualenv_path = $HOME.'/.pyenv/versions/py3'
" Trim unused white spaces on save
let g:pymode_trim_whitespaces = 1
" Turn on default python options
let g:pymode_options = 1
" Setup max line length
let g:pymode_options_max_line_length = 79
"Enable colorcolumn display at max_line_length
let g:pymode_options_colorcolumn = 1
" Setup pymode |quickfix| window
let g:pymode_quickfix_minheight = 3
let g:pymode_quickfix_maxheight = 6
" Enable PEP8-compatible python indent.
let g:pymode_indent = 1
" Enable fast and usual python folding in Vim.
let g:pymode_folding = 0
" Enable pymode-motion
let g:pymode_motion = 1
" Turns on the documentation script
" let g:pymode_doc = 1
" If you prefer the Omni-Completion tip window to close when a selection is
" made, these lines close it on movement in insert mode or when leaving
" insert mode
autocmd CursorMovedI * if pumvisible() == 0|pclose|endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
" Bind keys to show documentation for current word (selection)
let g:pymode_doc_bind = 'K'
" Turn on the run code script
let g:pymode_run = 1
" Binds keys to run python code
let g:pymode_run_bind = '<Leader>rc'
" Enable debugging functionality
let g:pymode_breakpoint = 1
" Bind debugging key
let g:pymode_breakpoint_bind = '<Leader>b'
" Turn on code checking
let g:pymode_lint = 0
" Check code on every save (if file has been modified)
let g:pymode_lint_on_write = 0
" Check code on every save (every)
let g:pymode_lint_unmodified = 0
" Check code when editing (on the fly)
let g:pymode_lint_on_fly = 0
" Show error message if cursor placed at the error line
let g:pymode_lint_message = 0
" Default code checkers (you could set several)
let g:pymode_lint_checkers = []
"['pyflakes', 'pep8']
" Bind key for rename
let g:pymode_rope_rename_bind = '<Leader>rr'
" Turn on code completion support in the plugin
let g:pymode_rope_completion = 1
" Turn on autocompletion when typing a period
let g:pymode_rope_complete_on_dot = 1
" Keymap for autocomplete to Ctrl-Space
let g:pymode_rope_completion_bind = '<C-Space>'
" Turn off annoying slow shit.
let g:pymode_rope_lookup_project = 1
let g:pymode_rope_regenerate_on_write = 0
" Turn rope on(1)/off(0) completely
let g:pymode_rope = 1
" By default when you press *<C-C>g* on any object in your code you will be moved to definition.
let g:pymode_rope_goto_definition_bind = '<Leader>g'
" Turn on pymode syntax
let g:pymode_syntax = 1
" Slower syntax synchronization that is better at handling code blocks in
" docstrings. Consider disabling this on slower hardware.
let g:pymode_syntax_slow_sync = 1
" Enable all python highlights
let g:pymode_syntax_all = 1
" Should stop rope from working on non-git folders
" requires: pip install GitPython, for the systems' python3!!!
" taken from: https://github.com/python-mode/python-mode/issues/525
python3 << EOF
# import sys
# print(sys.executable)
# print(sys.version)
# import pip
# pip.main(['install', 'GitPython'])
import vim
import git
def is_git_repo():
try:
_ = git.Repo('.', search_parent_directories=True).git_dir
return "1"
except:
return "0"
vim.command("let g:pymode_rope = " + is_git_repo())
EOF
" === End of python-mode configuration ===
" === vim-airline config ===
let g:airline_theme='base16_eighties'
" let g:airline_section_z = airline#section#create(['%3p%%: ', 'linenr', ':%3v', ' | %{kite#statusline()}'])
" === Vim-Preview configuration ===
" <Leader>P open the html preview
let g:PreviewBrowsers="open -a Safari"
" === vim-flake8 configuration ====
let g:flake8_show_quickfix=1 " show (default)
let g:flake8_show_in_gutter=1 " show
let g:flake8_show_in_file=0
" run the Flake8 check every time you write a Python file
autocmd BufWritePost *.py call Flake8()
" === Run Black (python formatter) on every save
" autocmd BufWritePre *.py execute ':Black'
let g:black_linelength=79
let g:black_skip_string_normalization=1
" === tcomment_vim config ===
let g:tcomment#options = {'whitespace': 'yes'}
" === vim-easyclip config ===
" let g:EasyClipShareYanks = 1
" let g:EasyClipEnableBlackHoleRedirect = 0
" === python docstring hide ===
" hides docstrings when python files are opened
" this command is defined in my ~/.vim/after/syntax/python.vim file
" and taken directly from https://github.com/yhat/vim-docstring
" autocmd FileType python PyDocHide
" === Vundle stuff for python I ended up not using ===
" PEP8 indentation
" au BufNewFile,BufRead *.py
" \ set tabstop=4
" \ set softtabstop=4
" \ set shiftwidth=4
" \ set textwidth=79
" \ set expandtab
" \ set autoindent
" \ set fileformat=unix
" Plugin 'vim-scripts/indentpython.vim'
"" mark extra whitespaces
" au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/
" autocomplete for python
" Bundle 'Valloric/YouCompleteMe'
" === End of Vundle stuff for python I ended up not using ===
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment