Skip to content

Instantly share code, notes, and snippets.

@skydevht
Last active May 8, 2020 16:45
Show Gist options
  • Save skydevht/87e76cd3354308804195fba0218e02c9 to your computer and use it in GitHub Desktop.
Save skydevht/87e76cd3354308804195fba0218e02c9 to your computer and use it in GitHub Desktop.
My Neovim configuration
" Plugins {{{1
call plug#begin()
" Language
Plug 'sheerun/vim-polyglot'
Plug 'reasonml-editor/vim-reason-plus'
Plug 'mattn/emmet-vim'
Plug 'tpope/vim-surround'
Plug 'dart-lang/dart-vim-plugin'
Plug 'w0rp/ale'
" Integration
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-projectionist'
Plug 'tpope/vim-fugitive'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Completion
Plug 'jiangmiao/auto-pairs'
Plug 'SirVer/ultisnips'
Plug 'neoclide/coc.nvim', {'do': { -> coc#util#install()}}
" Interface
Plug 'itchyny/lightline.vim'
Plug 'airblade/vim-gitgutter'
Plug 'moll/vim-bbye'
Plug 'unblevable/quick-scope'
" Commands
Plug 'justinmk/vim-sneak'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-commentary'
Plug 'godlygeek/tabular'
Plug 'wellle/targets.vim'
Plug 'arithran/vim-delete-hidden-buffers'
" Code Display
Plug 'mhinz/vim-startify'
Plug 'morhetz/gruvbox'
Plug 'nlknguyen/papercolor-theme'
Plug 'skydevht/palenight.vim'
Plug 'jacoborus/tender.vim'
Plug 'ap/vim-css-color'
Plug 'ryanoasis/vim-devicons'
call plug#end()
" General Options {{{1
scriptencoding utf-8
" Global Configuration Options {{{2
set encoding=utf-8
lang en_US.UTF-8
set backspace=indent,eol,start " Make backspace work like most other programs
set nobackup
set nowritebackup
set colorcolumn=81 " Set the 80 character column (+1 if textwidth is defined else 81)
set cursorline " Highlight the current line
set hidden " Any buffer can be hidden
set number
set history=1000 " Set a huge history
set lazyredraw " Render window only after the end of a macro
set linespace=0 " No extra spaces between rows
set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set showmatch " Show current brackets
set splitbelow " Puts new split windows to the bottom of the current
set splitright " Puts new vsplit windows to the right of the current
set winminheight=0 " Windows can be 0 line height
set updatetime=100 " Faster refresh time
" Fuzzy matching {{{2
set path+=** " fuzzy matching with :find *.ext*
set wildmenu " Show list instead of just completing
set wildignore+=**/node_modules/** " Ignore some folders
set wildignore+=**/.git/**
set wildignore+=**/build/**
set wildignore+=**/dist/**
" Folding {{{2
set foldmethod=syntax " Fold are defined by syntax highlighting
" Indentation {{{2
" Don't enable smarindent or cindent with filetype plugin indent on
filetype plugin indent on " Indentation based on filetype
set autoindent " Does not interfere with other indentation settings
" Invisible characters {{{2
set list
set listchars=tab\ ,trail:¿,nbsp:~ " Display invisible characters
" Mouse {{{2
set mouse=a
" Netrw {{{2
let g:netrw_banner=0 " Disable banner
let g:netrw_altv = 1 " Open split to the right
let g:netrw_winsize = 20
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
" Omni Completiton {{{2
autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS
autocmd FileType haskell setlocal omnifunc=necoghc#omnifunc
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
" Search {{{2
set hlsearch " highlight the search result
set ignorecase " Case insensitive search
set incsearch " Find as I type during the search
set smartcase " Case sensitive only if search contains uppercase letter.
" Tabulation and spaces {{{2
set expandtab " Show spaces instead of tabs
set shiftwidth=0 " columns per <<
set softtabstop=4 " spaces per tab
set tabstop=4 " columns per tabs
" Vim directories {{{2
set nobackup
set noswapfile
" Wrapping {{{2
set nowrap
" Colors {{{2
if (has("nvim"))
"For Neovim 0.1.3 and 0.1.4 < https://github.com/neovim/neovim/pull/2198 >
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
endif
"For Neovim > 0.1.5 and Vim > patch 7.4.1799 < https://github.com/vim/vim/commit/61be73bb0f965a895bfb064ea3e55476ac175162 >
"Based on Vim patch 7.4.1770 (`guicolors` option) < https://github.com/vim/vim/commit/8a633e3427b47286869aa4b96f2bfc1fe65b25cd >
" < https://github.com/neovim/neovim/wiki/Following-HEAD#20160511 >
if (has("termguicolors"))
set termguicolors
endif
" Plugin Configuration {{{1
" LightLine {{{2
let g:lightline = {
\ 'colorscheme': 'gruvbox',
\ 'active': {
\ 'left': [['mode', 'paste'], ['fugitive', 'filename']],
\ 'right': [['lineinfo'], ['percent'], ['fileformat', 'fileencoding', 'filetype'], ['linter_warnings', 'linter_errors', 'linter_ok']]
\ },
\ 'component_function': {
\ 'fugitive': 'LightlineFugitive',
\ 'filename': 'LightlineFilename',
\ 'filetype': 'MyFiletype',
\ 'fileformat': 'MyFileformat'
\ },
\ 'component_expand': {
\ 'linter_warnings': 'LightlineLinterWarnings',
\ 'linter_errors': 'LightlineLinterErrors',
\ 'linter_ok': 'LightlineLinterOK'
\ }
\ }
function! LightlineModified()
return &ft =~ 'help\|vimfiler' ? '' : &modified ? '+' : &modifiable ? '' : '-'
endfunction
function! LightlineReadonly()
return &ft !~? 'help\|vimfiler' && &readonly ? 'RO' : ''
endfunction
function! LightlineFilename()
return ('' != LightlineReadonly() ? LightlineReadonly() . ' ' : '') .
\ (&ft == 'vimfiler' ? vimfiler#get_status_string() :
\ &ft == 'vimshell' ? vimshell#get_status_string() :
\ '' != expand('%:t') ? expand('%:t') : '[No Name]') .
\ ('' != LightlineModified() ? ' ' . LightlineModified() : '')
endfunction
function! LightlineFugitive()
if &ft !~? 'vimfiler' && exists('*fugitive#head')
return fugitive#head()
endif
return ''
endfunction
function! MyFiletype()
return winwidth(0) > 70 ? (strlen(&filetype) ? &filetype . ' ' . WebDevIconsGetFileTypeSymbol() : 'no ft') : ''
endfunction
function! MyFileformat()
return winwidth(0) > 70 ? (&fileformat . ' ' . WebDevIconsGetFileFormatSymbol()) : ''
endfunction
function! LightlineLinterWarnings() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ◆', all_non_errors)
endfunction
function! LightlineLinterErrors() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : printf('%d ✗', all_errors)
endfunction
function! LightlineLinterOK() abort
let l:counts = ale#statusline#Count(bufnr(''))
let l:all_errors = l:counts.error + l:counts.style_error
let l:all_non_errors = l:counts.total - l:all_errors
return l:counts.total == 0 ? '' : ''
endfunction
autocmd User ALELint call s:MaybeUpdateLightline()
" Update and show lightline but only if it's visible (e.g., not in Goyo)
function! s:MaybeUpdateLightline()
if exists('#lightline')
call lightline#update()
end
endfunction
" FZF {{{2
let $FZF_DEFAULT_COMMAND = 'ag -g ""'
" Emmet {{{2
let g:user_emmet_settings = {
\ 'javascript.jsx' : {
\ 'extends' : 'jsx',
\ },
\ }
" Ale {{{2
let g:ale_completion_enabled = 0
let g:ale_php_phpcbf_executable = '/home/hash/.config/composer/vendor/bin/phpcbf'
let g:ale_php_phpcs_executable = '/home/hash/.config/composer/vendor/bin/phpcs'
let g:ale_php_phpcs_standard = 'PSR2'
let g:ale_php_phpcbf_standard = g:ale_php_phpcs_standard
let g:ale_linters = {
\ 'php': ['phpcs'],
\ 'dart': ['dartanalyzer'],
\ 'javascript': ['flow', 'eslint'],
\ 'typescript': ['tsserver'],
\}
let g:ale_fixers = {
\ 'javascript': ['eslint'],
\ 'perl': ['perl'],
\ 'php': ['phpcbf'],
\ 'json': ['jq'],
\ 'scss': ['prettier'],
\ 'css': ['prettier'],
\ 'html': ['prettier'],
\ 'dart': ['dartfmt'],
\ 'typescript': ['prettier'],
\}
let g:ale_sign_error = ''
let g:ale_sign_warning = ''
" call Base16hi("ALEWarningSign", g:base16_gui0A, "", "", "")
" call Base16hi("ALEErrorSign", g:base16_gui08, "", "", "")
let g:ale_fix_on_save = 1
" AutoPairs {{{2
let g:AutoPairsMapSpace = 0
" Startify {{{3
let g:startify_change_to_vcs_root = 1
let g:startify_change_to_dir = 0
autocmd BufNewFile,BufRead *.tern-project set filetype=json
"autocmd BufNewFile,BufRead *.js set filetype=javascript.jsx
autocmd Filetype javascript setlocal ts=2 sts=2 sw=2
autocmd Filetype typescript setlocal ts=2 sts=2 sw=2
autocmd Filetype pug setlocal ts=2 sts=2 sw=2
autocmd Filetype vue setlocal ts=2 sts=2 sw=2
" Mappings {{{1
" Leader {{{2
let mapleader = ","
let g:mapleader = ","
" Fast saving {{{2
nmap <leader>w :w!<cr>
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :<C-u>call VisualSelection('', '')<CR>/<C-R>=@/<CR><CR>
vnoremap <silent> # :<C-u>call VisualSelection('', '')<CR>?<C-R>=@/<CR><CR>
" Search {{{2
map <space> /
map <c-space> ?
" Disable highlight when <leader><cr> is pressed
map <silent> <leader><cr> :noh<cr>
" Terminal {{{2
if has('nvim')
nnoremap <leader>` :te<CR>
" tnoremap <ESC> <c-\><c-n>
tnoremap <C-j> <c-\><c-n><C-W>j
tnoremap <C-k> <c-\><c-n><C-W>k
tnoremap <C-h> <c-\><c-n><C-W>h
tnoremap <C-l> <c-\><c-n><C-W>l
endif
" Windows {{{2
noremap <leader>h <C-w>s
noremap <leader>v <C-w>v
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" Buffers {{{2
noremap <leader>bq :q<cr>
map <leader>bd :Bclose<cr>
map <leader>ba :bufdo bd<cr>
" Tabs {{{2
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
noremap <S-l> gt
noremap <S-h> gT
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
map <leader>t<leader> :tabnext
let g:lasttab = 1
nmap <Leader>tl :exe "tabn ".g:lasttab<CR>
au TabLeave * let g:lasttab = tabpagenr()
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/
" Switch CWD to the directory of the open buffer
map <leader>cd :cd %:p:h<cr>:pwd<cr>
" Remap VIM 0 to first non-blank character
map 0 ^
" Move a line of text using ALT+[jk] or Command+[jk] on mac
nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z
if has("mac") || has("macunix")
nmap <D-j> <M-j>
nmap <D-k> <M-k>
vmap <D-j> <M-j>
vmap <D-k> <M-k>
endif
" Pressing ,ss will toggle and untoggle spell checking
map <leader>ss :setlocal spell!<cr>
" Shortcuts using <leader>
map <leader>sn ]s
map <leader>sp [s
map <leader>sa zg
map <leader>s? z=
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
" Toggle paste mode on and off
map <leader>pp :setlocal paste!<cr>
"" No arrow {{{2
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
inoremap <Left> <NOP>
inoremap <Right> <NOP>
" Git {{{2
nmap <leader>gs :Gstatus<CR>
nmap <leader>ga :Git add -A<CR>
nmap <leader>gb :Gblame<CR>
nmap <leader>gc :Gcommit<CR>
nmap <leader>gd :Gdiff<CR>
nmap <leader>gl :Glog<CR>
nmap <leader>gp :Gpush<CR>
nmap <leader>gpl :Gpull<CR>
nmap <leader>gr :Gread<CR>
nmap <leader>gw :Gwrite<CR>
nmap <leader>ge :Gedit<CR>
" Function keys {{{2
noremap <F3> :ALEFix<CR>
noremap <F5> :source $HOME/.config/nvim/init.vim<CR>
nnoremap <F10> :e $MYVIMRC<CR>
" UltiSnips {{{2
let g:UltiSnipsExpandTrigger="<TAB>"
let g:UltiSnipsJumpForwardTrigger="TAB"
" Git Gutter
let g:gitgutter_map_keys = 0
" COC {{{2
nmap <silent> <leader>rg <Plug>(coc-definition)
nmap <silent> <leader>rr <Plug>(coc-references)
nmap <silent> <leader>ri <Plug>(coc-implementation)
nmap <silent> <leader>rd <Plug>(coc-diagnostic-info)
nmap <silent> <leader>rn <Plug>(coc-diagnostic-next)
nmap <silent> <leader>rp <Plug>(coc-diagnostic-prev)
" FZF {{{2
nmap <leader>fb :Buffers<cr>
nmap <leader>ff :Files<cr>
nnoremap <leader>fg :Ag<space>
nnoremap <F12> :syntax sync fromstart<cr>
" Quick Scope {{{2
augroup qs_colors
autocmd!
autocmd ColorScheme * highlight QuickScopePrimary guifg='#afff5f' gui=underline ctermfg=155 cterm=underline
autocmd ColorScheme * highlight QuickScopeSecondary guifg='#5fffff' gui=underline ctermfg=81 cterm=underline
augroup END
" Colorscheme {{{1
" Italics for my favorite color scheme
let g:palenight_terminal_italics=1
let g:material_terminal_italics=1
let g:gruvbox_contrast_dark='soft'
set background=dark
colorscheme gruvbox
" Custom highlight
hi jsClassDefinition gui=bold
hi jsFuncArgs gui=italic
let g:javascript_plugin_flow = 1
" hi Normal guibg=NONE ctermbg=NONE
" hi NonText guibg=NONE ctermbg=NONE
" vim:fdm=marker:fdl=0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment