Skip to content

Instantly share code, notes, and snippets.

@ironhouzi
Created May 22, 2018 20:38
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 ironhouzi/21a334a99f8deb1b4a4a5837fd6a63cb to your computer and use it in GitHub Desktop.
Save ironhouzi/21a334a99f8deb1b4a4a5837fd6a63cb to your computer and use it in GitHub Desktop.
" vim-plug
call plug#begin('~/.vim/plugged')
" Bare necessities
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-abolish'
Plug 'ironhouzi/vim-stim'
Plug 'tpope/vim-commentary'
" Utilities
Plug 'w0rp/ale'
Plug 'junegunn/fzf'
Plug 'junegunn/fzf.vim'
Plug 'wellle/targets.vim'
Plug 'bling/vim-airline'
Plug 'https://github.com/vim-airline/vim-airline-themes.git'
Plug 'simnalamburt/vim-mundo'
Plug 'osyo-manga/vim-over'
Plug 'junegunn/vim-easy-align'
Plug 'tommcdo/vim-exchange'
Plug 'ludovicchabant/vim-gutentags'
Plug 'PeterRincker/vim-argumentative'
Plug 'guns/vim-sexp', { 'for': ['scheme', 'clojure', 'racket', 'lisp'] }
Plug 'ervandew/supertab'
Plug 'majutsushi/tagbar'
Plug 'mhinz/vim-grepper'
Plug 'lfv89/vim-interestingwords'
" Python
Plug 'bps/vim-textobj-python', { 'for': 'python' }
Plug 'kana/vim-textobj-user', { 'for': 'python' }
Plug 'tmhedberg/SimpylFold', { 'for': 'python' }
Plug 'michaeljsmith/vim-indent-object', { 'for': 'python' }
Plug 'vim-scripts/indentpython.vim', { 'for': 'python' }
" Haskell
Plug 'neovimhaskell/haskell-vim', { 'for': 'haskell' }
Plug 'alx741/vim-hindent', { 'for': 'haskell' }
" Snippets
Plug 'SirVer/ultisnips' | Plug 'git@bitbucket.org:ironhouzi/myultisnippets.git'
" Markdown
Plug 'tpope/vim-markdown', { 'for': 'markdown' }
Plug 'jtratner/vim-flavored-markdown', { 'for': 'markdown' }
" Colour schemes
Plug 'jonathanfilip/vim-lucius'
Plug 'endel/vim-github-colorscheme'
Plug 'john2x/flatui.vim'
Plug 'ironhouzi/bioluminescence.vim'
Plug 'sjl/badwolf'
Plug 'arcticicestudio/nord-vim', { 'branch': 'develop' }
if $NVIM_TUI_ENABLE_TRUE_COLOR == 1
Plug 'frankier/neovim-colors-solarized-truecolor-only'
endif
" Multi-layout sanity
Plug 'ironhouzi/bikey-vim'
" File types
Plug 'lepture/vim-jinja'
call plug#end()
filetype plugin indent on " load file type plugins + indentation
set omnifunc=syntaxcomplete#Complete " activate omnicompletion
syntax on " enable syntax highlighting
set backspace=indent,eol,start " backspace through everything in insert mode
set fileencoding=utf-8
scriptencoding utf-8
set hidden " Don't complain when switching buffers
set undofile " Persistent undo
set ignorecase " searches are case insensitive...
set smartcase " ... unless they contain at least one capital letter
set showcmd " display incomplete commands
set nowrap " No wrapping when coding
set nohls " search highlighting off is better for arbitrary jumps
set number " Line numbering
set autoindent " indent at the same level of the previous line
set nosmartindent " Doesn't mess up filetype indentation
set incsearch " highlights searches for efficient movement
set autowrite " save on buffer switch
set autoread " update externally modified files
set autochdir " automaticly update cwd to your buffer
set lazyredraw " defer updating window when executing macros
set whichwrap=b,s " allow cursor left/right movement span accross lines
set shortmess=aI " abbreviate/avoid prompts and intro message
set diffopt=vertical " use vertical splits for diffmode
set scrolloff=5 " scrolls 5 lines before reaching the very top or bottom
set sidescroll=2 " only scroll horizontally little by little
set tabstop=4 " tabs are 4 characters wide
set shiftwidth=4 " indentations are 4 characters wide
set softtabstop=4 " backspace deletes indents of 4 characters
set expandtab " tab key outputs space characters
set textwidth=80
set wildmenu " ex command tab completion
set nojoinspaces " Don't insert two spaces after sentence when joining lines
set mouse=a " Mouse scroll wheel moves buffer, not cursor
if has('nvim')
set wildmode=full " statusline is filled with completion suggestions
set equalalways " vsplit widths are equalized
set inccommand=nosplit " show preview of commands
set termguicolors
endif
set completeopt=menuone,preview " show ex completion info in statusline
" Avoid editing binary files
set wildignore=*.o,*.obj,*.jpg,*.png,*.pdf,*.pyc,*.tgz,*.txz,*.zip,*.7z,*.rar,*.py*cover
set formatoptions=qrn1jc " q: format w/ 'gq'
" r: auto-continue comments for newline
" n: recognize numbered lists
" 1: don't break line after one-letter word
" j: remove comment leader when joining lines
" c: autoformat comments
" toggle invisible characters
set listchars=tab:▸\ ,eol:¬,trail:⌴,extends:❯,precedes:
set showbreak=
" Don't try to highlight lines longer than 200 characters.
set synmaxcol=200
" Thank you Steve Losh
set notimeout
set ttimeout
set ttimeoutlen=10
" Keep column position in visual block mode movements
set nostartofline
let mapleader = ","
let maplocalleader = "\\"
" ----- Backup -------------------------
set backup
set noswapfile
set undodir=~/.vim/tmp/undodir//
set backupdir=~/.vim/tmp/backup//
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
" Paper printouts contain line numbers
set printoptions=number:y
" ---------------------------------------
" ----------------------------------------------------------------------------
" Au rules
" ----------------------------------------------------------------------------
" Resize splits when the window is resized
au VimResized * :wincmd =
" Different settings for html files
autocmd FileType html,xml,htmldjango,xsd,json,yml,yaml,proto setlocal sw=2 ts=2 sts=2
autocmd FileType htmldjango setlocal commentstring={#\ %s\ #}
autocmd FileType python setlocal ts=8 sw=4 sts=4 et tw=80
autocmd FileType python set makeprg=python\ -u\ %
autocmd FileType markdown :Prose
autocmd FileType sh setlocal tabstop=4 shiftwidth=4 noexpandtab
autocmd FileType markdown syntax sync fromstart " redraw syntax highlighting
let g:haskell_enable_quantification = 1 " to enable highlighting of `forall`
let g:haskell_enable_recursivedo = 1 " to enable highlighting of `mdo` and `rec`
let g:haskell_enable_arrowsyntax = 1 " to enable highlighting of `proc`
let g:haskell_enable_pattern_synonyms = 1 " to enable highlighting of `pattern`
let g:haskell_enable_typeroles = 1 " to enable highlighting of type roles
let g:haskell_enable_static_pointers = 1 " to enable highlighting of `static`
let g:haskell_backpack = 1 " to enable highlighting of backpack keywords
" nginx syntax
autocmd BufNewFile,BufRead *nginx*.conf setlocal ft=nginx
if has('nvim')
" Ensures correct python runtime for neovim
let g:python_host_prog='/home/ironhouzi/.pyenv/versions/neovim2/bin/python'
let g:python3_host_prog='/home/ironhouzi/.pyenv/versions/neovim3/bin/python'
endif
" Make sure Vim returns to the same line when you reopen a file.
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" Auto save aund auto read
augroup autoSaveAndRead
autocmd!
autocmd TextChanged,InsertLeave,FocusLost * silent! wall
autocmd CursorHold * silent! checktime
augroup END
" Fix unresponsive editing of TeX files
autocmd FileType tex :NoMatchParen
au FileType tex setlocal nocursorline
if has('nvim')
autocmd TermOpen * startinsert
endif
" ----------------------------------------------------------------------------
if $TERM == "xterm-256color" || $TERM == "screen-256color" || $TERM == "xterm-termite"
let g:nord_italic = 1
let g:nord_italic_comments = 1
let g:nord_italic_comments = 1
colorscheme nord
endif
" -------------------------------
" FOLDING (WIP)
" -------------------------------
set foldlevelstart=1
" Make zO recursively open whatever fold we're in, even if it's partially open.
nnoremap zO zczO
function! MyFoldText() " {{{
let line = getline(v:foldstart)
let nucolwidth = &fdc + &number * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 3
let foldedlinecount = v:foldend - v:foldstart
" expand tabs into spaces
let onetab = strpart(' ', 0, &tabstop)
let line = substitute(line, '\t', onetab, 'g')
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let fillcharcount = windowwidth - len(line) - len(foldedlinecount)
return line . '' . repeat(" ",fillcharcount) . foldedlinecount . '' . ' '
endfunction " }}}
set foldtext=MyFoldText()
" Mappings {{{
" HIGHLIGHTING -----------------------------------------
" correct highlighting is controlled by the vim-stim plugin
" ensure that search highlighting is off for regular search
nnoremap / :set nohlsearch nohlsearch?<CR>/
" Toggle search highlighting and clear all matches
nnoremap <silent> <leader><space> :set hlsearch! hlsearch?<CR>:call clearmatches()<CR>
" ------------------------------------------------------
" %% expands to current working directory
cnoremap %% <c-r>=expand('%:h').'/'<cr>
" gs saves
noremap gs :update<CR>
" toggle Gundo
nnoremap <leader>gu :MundoToggle<CR>
" Cleanup trailing whitespace in entire file
nnoremap <leader>w :silent! %s/\s\+$//<cr>:let @/=''<CR>
" Fat finger correction
nmap Ø :
command! -nargs=* Q q <args>
command! -nargs=* W w <args>
command! -nargs=* Wq wq <args>
" allows incsearch highlighting for range commands
cnoremap $t <CR>:t''<CR>
cnoremap $T <CR>:T''<CR>
cnoremap $m <CR>:m''<CR>
cnoremap $M <CR>:M''<CR>
cnoremap $y <CR>:y''<CR>
cnoremap $d <CR>:d<CR>``
" Easier linewise reselection of what you just pasted.
nnoremap <leader>v V`]
" Indent/dedent/autoindent what you just pasted.
nnoremap <lt>> V`]<
nnoremap ><lt> V`]>
nnoremap =- V`]=
" Alt-] opens tag in vsplit
map <A-]> :vsp <CR>:exec("tag ".expand("<cword>"))<CR>
" resize windows
nnoremap <silent> <Leader>+ :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "resize " . (winheight(0) * 2/3)<CR>
" increase current pane size
nnoremap <silent> <Leader>> :exe "vertical resize " . (winwidth(0) * 3/2)<CR>
" decrease current pane size
nnoremap <silent> <Leader>< :exe "vertical resize " . (winwidth(0) * 2/3)<CR>
" switch between current and last buffer
nnoremap <leader>. <c-^>
" switch between current and last window
nnoremap <leader>m <c-w><c-p>
" Emacs bindings in command mode
cnoremap <C-a> <Home>
cnoremap <C-b> <Left>
cnoremap <C-f> <Right>
cnoremap <C-d> <Delete>
cnoremap <M-b> <S-Left>
cnoremap <M-f> <S-Right>
cnoremap <M-d> <S-right><Delete>
cnoremap <C-g> <C-c>
" Uppercase line when in insert mode (NB: messes with register z)
inoremap <C-u> <esc>mzgUiw`za
" Zip Right (Steve Losh)
" Once you hit escape your cursor is on the closing paren, so you can 'zip' it
" over to the right with this mapping. Also preserves your last yank/delete.
" print()'some text' --------(zl)---------> print('some text')
" ^------- cursor is here
nnoremap zl :let @z=@"<cr>x$p:let @"=@z<cr>
" close window
nnoremap <leader>ww :wincmd q<cr>
" wipe buffer
nnoremap <leader>wq :bwipeout!<cr>
" set working directory to current file
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
" execute macro over visual range
" xnoremap @ :<C-u>call ExecuteMacroOverVisualRange()<CR>
" perform dot command in visal mode
vnoremap . :norm.<CR>
" easy-align ----------------------------
vnoremap <silent> <Enter> :EasyAlign<Enter>
" Vim-Over ------------------------------
" cabbrev s OverCommandLine<CR>s
" cabbrev %s OverCommandLine<CR>%s
cabbrev '<,'>s OverCommandLine<CR>'<,'>s
" Toggle Mode
" TODO: use a safer check than checking wrap setting
nnoremap com :<C-R>=&wrap ? 'Code' : 'Prose'<CR><CR>
" Fix broken syntax highlighting
nnoremap <silent> <leader>s :syntax sync fromstart<CR>
" single to multiline function definition
nnoremap gK :s/\(,\) \\|\((\)\\|\(\S\+\)\()\)/\1\2\3\r\4/g<CR>=%
" TODO: parameterize numbers
" Highlights words in six different colours
nnoremap <silent> <leader>1 :call InterestingWords(1)<cr>
nnoremap <silent> <leader>2 :call InterestingWords(2)<cr>
nnoremap <silent> <leader>3 :call InterestingWords(3)<cr>
nnoremap <silent> <leader>4 :call InterestingWords(4)<cr>
nnoremap <silent> <leader>5 :call InterestingWords(5)<cr>
nnoremap <silent> <leader>6 :call InterestingWords(6)<cr>
" ------- TAGBAR ---------------------
nnoremap <silent> <leader>t :TagbarToggle<CR>
" ------- FZF - fuzzy finder ------------
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --hidden --color=always --follow --no-ignore --glob "!.histfile" --glob "!.tags" --glob "!.mypy_cache/*" --glob "!*~" --glob "!.git/*" '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
nnoremap <silent> <leader>f :Files<CR>
nnoremap <silent> <leader>b :Buffers<CR>
nnoremap <space>/ :<C-u>Rg
" --------------- netrw -----------------
" Don't switch back to netrw buffer with ctrl-^ (<leader>.)
let g:netrw_altfile = 1
" --------------- Bikey-Vim -------------
inoremap <c-k> <esc>:call SwitchKbd()<cr>a
if has('nvim')
tnoremap <c-k> <C-\><C-n><esc>:call SwitchKbd()<cr>
autocmd CmdwinEnter * call SetLayout(GetCurrentKbd())
autocmd CmdwinLeave * call SetLayout(g:kbd_langs[0])
endif
" --------------- Fugitive --------------
set diffopt=vertical,filler
nnoremap <leader>gi :Git<space>
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gl :Git log --all --graph --decorate --oneline<CR>
" Open current buffer in a new tab and show Fugitive diff
nnoremap <silent> <leader>d :tab split \| Gdiff \| wincmd h<cr>
" --------- ALE ------------------
let g:ale_python_mypy_options = '--ignore-missing-imports'
let g:ale_python_flake8_executable = '/home/ironhouzi/.pyenv/versions/3.6.2/envs/neovim3/bin/flake8'
let g:ale_python_mypy_executable = '/home/ironhouzi/.pyenv/versions/3.6.2/envs/neovim3/bin/mypy'
let g:ale_lint_on_text_changed = 'never'
" ----------- AIRLINE -----------------
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
let g:airline_section_x=''
let g:airline_section_y=''
let g:airline_section_z='%3v'
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline#extensions#branch#enabled=1
let g:airline#extensions#tabline#enabled=0 " Extended tab bar on top
let g:airline_theme='nord'
" Truncate legend:
" ----------------
" a: mode, paste, iminsert
" b: hunks, branch
" c: bufferline, filename
" x: tagbar, filetype, virtualenv
" y: fileencoding, fileformat
" z: percentage, line number, column number
let g:airline#extensions#default#section_truncate_width = {
\ 'a': 45,
\ 'b': 45,
\ 'c': 45,
\ 'x': 74,
\ 'y': 45,
\ 'z': 74,
\ }
" ----------------------------------------------------------------------------
" move to the window in the direction shown, or create a new split in that
" direction
" ----------------------------------------------------------------------------
func! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfu
if has('nvim')
nnoremap <silent> <A-h> :call WinMove('h')<cr>
nnoremap <silent> <A-j> :call WinMove('j')<cr>
nnoremap <silent> <A-k> :call WinMove('k')<cr>
nnoremap <silent> <A-l> :call WinMove('l')<cr>
tnoremap <C-[> <C-\><C-n>
tnoremap <a-h> <c-\><c-n>:call WinMove('h')<cr>
tnoremap <a-j> <c-\><c-n>:call WinMove('j')<cr>
tnoremap <a-k> <c-\><c-n>:call WinMove('k')<cr>
tnoremap <a-l> <c-\><c-n>:call WinMove('l')<cr>
else
nnoremap <silent> <C-h> :call WinMove('h')<cr>
nnoremap <silent> <C-j> :call WinMove('j')<cr>
nnoremap <silent> <C-k> :call WinMove('k')<cr>
nnoremap <silent> <C-l> :call WinMove('l')<cr>
endif
" MAPPING ENDS }}}
" ULTINIPS ------------------------------
let g:UltiSnipsSnippetsDir = "~/.vim/plugged/myultisnippets/UltiSnips"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
" NETRW --------------------------------
let g:netrw_list_hide = '*.o,*.obj,*.jpg,*.png,*.pdf,*.pyc,*.tgz,*.txz,*.zip,*.7z,*.rar,*.py\,cover'
" STATUSLINE ---------------------------
if has('statusline')
set laststatus=2
set noshowmode " Hide default mode (-- INSERT -- below the statusline)
endif
" GUI mode settings --------------------
if has("gui_running")
set guioptions-=r
set guioptions-=T
set guioptions-=m " no gui menu
set guioptions+=c " use console dialogs
endif
" InterestingWords custom highlighting -----
let g:interestingWordsGUIColors = ['#aeee00', '#8cffba', '#b88853', '#ff9eb8', '#ff2c4b', '#ffa724']
let g:interestingWordsTermColors = ['154', '121', '137', '211', '195', '214']
" FUNCTIONS {{{
" ----------------------------------------------------------------------------
" Enable word processor mode
" ----------------------------------------------------------------------------
func! ProseMode()
setlocal formatoptions=1 " 1: don't break line after one-letter word
map j gj
map k gk
setlocal spell
silent setlocal spelllang=en_us,nb
"set thesaurus+=/Users/sbrown/.vim/thesaurus/mthesaur.txt
"set complete+=s
setlocal formatprg=par\ 80
setlocal nonumber
setlocal wrap
setlocal linebreak
setlocal nolist
" max character highlighting in GUI
if has("gui_running")
hi clear OverLength
endif
endfu
com! Prose call ProseMode()
func! CodeMode()
silent! iunmap <buffer> .
silent! iunmap <buffer> !
silent! iunmap <buffer> ?
setlocal formatoptions=qrn1jc " q: format w/ 'gq'
" r: auto-continue comments for newline
" n: recognize numbered lists
" 1: don't break line after one-letter word
" j: remove comment leader when joining lines
" c: autoformat comments
setlocal nospell
setlocal number
setlocal nowrap
setlocal nolinebreak
if has("gui_running")
highlight OverLength ctermbg=red ctermfg=white guibg=#592929
match OverLength /\%106v.\+/
endif
silent! autocmd! PROSE * <buffer>
endfu
com! Code call CodeMode()
" ----------------------------------------------------------------------------
function! ExecuteMacroOverVisualRange()
echo "@".getcmdline()
execute ":'<,'>normal @".nr2char(getchar())
endfunction
function! CopyMatches(reg)
let hits = []
%s//\=len(add(hits, submatch(0))) ? submatch(0) : ''/ge
let reg = empty(a:reg) ? '+' : a:reg
execute 'let @'.reg.' = join(hits, "\n") . "\n"'
endfunction
command! -register CopyMatches call CopyMatches(<q-reg>)
" }}}
function! Reformat()
normal mz
set st=2 sts=2 noet
retab!
set st=4 sts=4 et
retab
normal ,w
normal gg=G
normal `z
endfunction
command! -register Reformat call Reformat()
function! Light()
colorscheme flatui
AirlineTheme solarized
let g:airline_solarized_bg='dark'
endfunction
command! -register Light call Light()
function! Dark()
colorscheme nord
AirlineTheme nord
endfunction
command! -register Dark call Dark()
" switch between C source and header files
function! ToggleCH()
let extension = expand('%:e')
if extension =~ 'c'
let extension = '.h'
elseif extension =~ 'h'
let extension = '.c'
else
return
endif
let filename = expand('%:r') . extension
if filereadable(filename)
execute "e " . filename
endif
endfunction
command! -register ToggleCH call ToggleCH()
nnoremap <silent> <leader>h :<C-u>ToggleCH<CR>
function! ScratchEdit(cmd, options)
exe a:cmd tempname()
setl buftype=nofile bufhidden=wipe nobuflisted
if !empty(a:options) | exe 'setl' a:options | endif
endfunction
command! -bar -nargs=* Scratch call ScratchEdit('edit', <q-args>)
command! -bar -nargs=* Ssplit call ScratchEdit('split', <q-args>)
command! -bar -nargs=* Svsplit call ScratchEdit('vsplit', <q-args>)
command! -bar -nargs=* Stabedit call ScratchEdit('tabe', <q-args>)
" }}}
function! PowerJayRange() range " Fix space after `(` when joining functions
" join
execute ":" . a:firstline . "," . a:lastline . " j"
" Remove annoying space between ( and first param
" (/e substitute option ignores non-match errors)
execute "s/\\((\\) \\(\\S\\+\\)/\\1\\2/e"
endfunction
" ensure the operation is dot repeatable
vnoremap <silent> <Plug>PJayRange :call PowerJayRange()<CR>:call repeat#set("\<Plug>PJayRange")<CR>
vmap J <Plug>PJayRange
function! PowerJay() " Fix space after `(` when joining functions
" join
execute "j"
" Remove annoying space between ( and first param
" (/e substitute option ignores non-match errors)
execute "s/\\((\\) \\(\\S\\+\\)/\\1\\2/e"
endfunction
" ensure the operation is dot repeatable
nnoremap <silent> <Plug>PJay :call PowerJay()<CR>:call repeat#set("\<Plug>PJay")<CR>
nmap J <Plug>PJay
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment