Skip to content

Instantly share code, notes, and snippets.

@ShawnRong
Created November 27, 2017 06:50
Show Gist options
  • Save ShawnRong/a713495c4b12d22854f46342c04f467b to your computer and use it in GitHub Desktop.
Save ShawnRong/a713495c4b12d22854f46342c04f467b to your computer and use it in GitHub Desktop.
neovim config
"nvim plugin settting
let g:nvim_fancy_font = 0
let g:nvim_bundle_groups = ['ui', 'enhance', 'move', 'navigate',
\'complete', 'compile', 'git', 'language']
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => General
"---------------------------------------------------------------------------------------------------
set nocompatible " Get out of vi compatible mode
" filetype plugin indent on " Enable filetype
filetype off
let &runtimepath.=',~/.vim/bundle/ale'
filetype plugin on
let mapleader=',' " Change the mapleader
"line number
set number
set timeoutlen=500 " Time to wait for a command
" Source the vimrc file after saving it
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" Fast edit the .vimrc file using ,x
nnoremap <Leader>ev :tabedit $MYVIMRC<CR>
set autoread " Set autoread when a file is changed outside
set autowrite " Write on make/shell commands
set hidden " Turn on hidden"
set history=1000 " Increase the lines of history
set modeline " Turn on modeline
set encoding=utf-8 " Set utf-8 encoding
set completeopt+=longest " Optimize auto complete
set completeopt-=preview " Optimize auto complete
set undofile " Set undo
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Keymap
"---------------------------------------------------------------------------------------------------
inoremap jj <esc>
" Make j and k work the way you expect
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
" Navigation between windows
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l
" Same when jumping around
nnoremap g; g;zz
nnoremap g, g,zz
" Reselect visual block after indent/outdent
vnoremap < <gv
vnoremap > >gv
" Repeat last substitution, including flags, with &.
nnoremap & :&&<CR>
xnoremap & :&&<CR>
" Keep the cursor in place while joining lines
nnoremap J mzJ`z
" Select entire buffer
nnoremap vaa ggvGg_
" FZF Keymap
nnoremap <Leader>p :Files<cr>
nnoremap <Leader>r :Buffers<cr>
nnoremap <Leader>h :History<cr>
" Strip all trailing whitespace in the current file
nnoremap <Leader>q :%s/\s\+$//<CR>:let @/=''<CR>
" Modify all the indents
nnoremap \= gg=G
"Termnial model quit
tnoremap <Esc> <C-\><C-n>
tnoremap <A-h> <C-\><C-n><C-w>h
tnoremap <A-j> <C-\><C-n><C-w>j
tnoremap <A-k> <C-\><C-n><C-w>k
tnoremap <A-l> <C-\><C-n><C-w>l
" See the differences between the current buffer and the file it was loaded from
command! DiffOrig vert new | set bt=nofile | r ++edit # | 0d_
\ | diffthis | wincmd p | diffthis
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Plugin
"---------------------------------------------------------------------------------------------------
call plug#begin('~/.vim/bundle')
if count(g:nvim_bundle_groups, 'ui') " UI setting
Plug 'rakr/vim-one'
Plug 'liuchengxu/space-vim-dark'
Plug 'colepeters/spacemacs-theme.vim'
Plug 'vim-airline/vim-airline' | Plug 'vim-airline/vim-airline-themes' " Status line
Plug 'Yggdroot/indentLine' " Indentation level
endif
if count(g:nvim_bundle_groups, 'enhance') " Vim Enhancement
Plug 'Raimondi/delimitMate' " Closing of quotes
Plug 'terryma/vim-multiple-cursors' " Multiple cursors
Plug 'mbbill/undotree', { 'on': 'UndotreeToggle' } " Undo tree
Plug 'tpope/vim-surround' " Surround
Plug 'tomtom/tcomment_vim' " Commenter
Plug 'roxma/vim-paste-easy' " Easy paste
Plug 'sickill/vim-pasta' " Vim pasta
Plug 'Keithbsmiley/investigate.vim' " Helper
Plug 'Shougo/denite.nvim'
Plug 'w0rp/ale'
Plug 'brooth/far.vim'
" Plug 'kassio/neoterm' " NeoVim Terminal
endif
if count(g:nvim_bundle_groups, 'move') " Moving
Plug 'easymotion/vim-easymotion' " Easy motion
Plug 'majutsushi/tagbar' " Tag bar
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " Fuzzy finder
Plug 'junegunn/fzf.vim' " Fuzzy finder plugin
" Plug 'yuttie/comfortable-motion.vim' " Comfortable motion
endif
if count(g:nvim_bundle_groups, 'navigate') " navigation
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' } " NERD tree
Plug 'Xuyuanp/nerdtree-git-plugin' " NERD tree git plugin
endif
if count(g:nvim_bundle_groups, 'complete') " completion
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'Shougo/neosnippet.vim' " Snippet engine
Plug 'Shougo/neosnippet-snippets' " Snippets
endif
if count(g:nvim_bundle_groups, 'compile') " UI compile
" Plug 'vim-syntastic/syntastic' " Syntax checking
endif
if count(g:nvim_bundle_groups, 'git') " Git
Plug 'tpope/vim-fugitive' " Git wrapper
endif
if count(g:nvim_bundle_groups, 'language') " Language
Plug 'davidhalter/jedi-vim', { 'for': 'python' } " Python jedi plugin
Plug 'mattn/emmet-vim', { 'for': ['html', 'css'] } " Emmet
Plug 'sheerun/vim-polyglot' " Language Support
Plug 'carlitux/deoplete-ternjs', { 'do': 'npm install -g tern', 'for': 'javascript' } " Completion for javascript
Plug 'shawncplus/phpcomplete.vim', { 'for': ['php', 'module', 'theme'] }
Plug 'ekalinin/Dockerfile.vim'
endif
call plug#end()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Colors and Font
"---------------------------------------------------------------------------------------------------
syntax on " Enable syntax
" colorscheme one
" colorscheme space-vim-dark
colorscheme spacemacs-theme
set background=dark " Set background
if !has('gui_running')
set t_Co=256 " Use 256 colors
endif
" Use true colors
if (empty($TMUX))
if (has("termguicolors"))
set termguicolors
endif
endif
" Set GUI font
if has('gui_running')
if has('gui_gtk')
set guifont=DejaVu\ Sans\ Mono\ 18
else
set guifont=DejaVu\ Sans\ Mono:h18
endif
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => User Interface
"---------------------------------------------------------------------------------------------------
let g:onedark_termcolors=256
if count(g:nvim_bundle_groups, 'ui')
let g:airline#extensions#tabline#enabled=1
else
" Set title
set title
set titlestring=%t%(\ %m%)%(\ (%{expand('%:p:h')})%)%(\ %a%)
" Set tabline
set showtabline=2 " Always show tab line
" Set up tab labels
set guitablabel=%m%N:%t[%{tabpagewinnr(v:lnum)}]
set tabline=%!MyTabLine()
function! MyTabLine()
let s=''
let t=tabpagenr() " The index of current page
let i=1
while i<=tabpagenr('$') " From the first page
let buflist=tabpagebuflist(i)
let winnr=tabpagewinnr(i)
let s.=(i==t ? '%#TabLineSel#' : '%#TabLine#')
let s.='%'.i.'T'
let s.=' '
let bufnr=buflist[winnr-1]
let file=bufname(bufnr)
let buftype = getbufvar(bufnr, 'buftype')
let m=''
if getbufvar(bufnr, '&modified')
let m='[+]'
endif
if buftype=='nofile'
if file=~'\/.'
let file=substitute(file, '.*\/\ze.', '', '')
endif
else
let file=fnamemodify(file, ':p:t')
endif
if file==''
let file='[No Name]'
endif
let s.=m
let s.=i.':'
let s.=file
let s.='['.winnr.']'
let s.=' '
let i=i+1
endwhile
let s.='%T%#TabLineFill#%='
let s.=(tabpagenr('$')>1 ? '%999XX' : 'X')
return s
endfunction
" Set up tab tooltips with each buffer name
set guitabtooltip=%F
endif
"Set Airline Status
if count(g:nvim_bundle_groups, 'ui')
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
set noshowmode
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_theme='base16_spacemacs'
" let g:airline_theme='one'
set laststatus=2
set ttimeoutlen=50
let g:bufferline_echo=0
let g:bufferline_modified='[+]'
if g:nvim_fancy_font
let g:airline_powerline_fonts=1
else
let g:airline_left_sep=''
let g:airline_right_sep=''
endif
" let g:airline#extensions#tabline#show_tab_nr = 0
" let g:airline#extensions#tabline#show_tab_type = 1
" let g:airline#extensions#tabline#buffers_label = 'b'
" let g:airline#extensions#tabline#tabs_label = 't'
endif
" Only have cursorline in current window and in normal window
autocmd WinLeave * set nocursorline
autocmd WinEnter * set cursorline
autocmd InsertEnter * set nocursorline
autocmd InsertLeave * set cursorline
set wildmenu " Show list instead of just completing
set wildmode=list:longest,full " Use powerful wildmenu
set shortmess=at " Avoids hit enter
set showcmd " Show cmd
set backspace=indent,eol,start " Make backspaces delete sensibly
set whichwrap+=h,l,<,>,[,] " Backspace and cursor keys wrap to
set virtualedit=block,onemore " Allow for cursor beyond last character
set scrolljump=5 " Lines to scroll when cursor leaves screen
set scrolloff=3 " Minimum lines to keep above and below cursor
set sidescroll=1 " Minimal number of columns to scroll horizontally
set sidescrolloff=10 " Minimal number of screen columns to keep away from cursor
set showmatch " Show matching brackets/parenthesis
set matchtime=2 " Decrease the time to blink
set formatoptions+=rnlmM " Optimize format options
set wrap " Set wrap
set textwidth=80 " Change text width
if g:nvim_fancy_font
set list " Show these tabs and spaces and so on
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮ " Change listchars
set linebreak " Wrap long lines at a blank
set showbreak=↪ " Change wrap line break
set fillchars=diff:⣿,vert:│ " Change fillchars
augroup trailing " Only show trailing whitespace when not in insert mode
autocmd!
autocmd InsertEnter * :set listchars-=trail:⌴
autocmd InsertLeave * :set listchars+=trail:⌴
augroup END
endif
" Set gVim UI setting
if has('gui_running')
set guioptions-=m
set guioptions-=T
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Indent Related
"---------------------------------------------------------------------------------------------------
set autoindent " Preserve current indent on new lines
set cindent " set C style indent
set expandtab " Convert all tabs typed to spaces
set softtabstop=4 " Indentation levels every four columns
set shiftwidth=4 " Indent/outdent by four columns
set shiftround " Indent/outdent to nearest tabstop
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Search Related
"---------------------------------------------------------------------------------------------------
set ignorecase " Case insensitive search
set smartcase " Case sensitive when uc present
set hlsearch " Highlight search terms
set incsearch " Find as you type search
set gdefault " turn on g flag
" Use sane regexes
nnoremap / /\v
vnoremap / /\v
cnoremap s/ s/\v
nnoremap ? ?\v
vnoremap ? ?\v
cnoremap s? s?\v
" Use ,Space to toggle the highlight search
nnoremap <Leader><Space> :set hlsearch!<CR>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Fold Realted
"---------------------------------------------------------------------------------------------------
set foldlevelstart=0 " Start with all folds closed
set foldcolumn=1 " Set fold column
" Space to toggle and create folds.
nnoremap <silent> <Space> @=(foldlevel('.') ? 'za' : '\<Space>')<CR>
vnoremap <Space> zf
" Set foldtext
function! MyFoldText()
let line=getline(v:foldstart)
let nucolwidth=&foldcolumn+&number*&numberwidth
let windowwidth=winwidth(0)-nucolwidth-3
let foldedlinecount=v:foldend-v:foldstart+1
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.'L'.' '
endfunction
set foldtext=MyFoldText()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"---------------------------------------------------------------------------------------------------
" => Plugin Setting
"---------------------------------------------------------------------------------------------------
" Setting for enhancement plugins
if count(g:nvim_bundle_groups, 'enhance')
" -> delimitMate
let delimitMate_expand_cr=1
let delimitMate_expand_space=1
let delimitMate_balance_matchpairs=1
" -> ale
let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']
let g:ale_linters = {
\ 'javascript': ['eslint'],
\}
let g:ale_linters = {'jsx': ['stylelint', 'eslint']}
let g:ale_linter_aliases = {'jsx': 'css'}
let g:ale_javascript_eslint_use_global = 1
let g:ale_javascript_eslint_executable = "/usr/local/lib/node_modules/eslint"
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%linter%] %s [%severity%]'
" -> Tcomment
" Map \<Space> to commenting
function! IsWhiteLine()
if (getline('.')=~'^$')
exe 'TCommentBlock'
normal! j
else
normal! A
exe 'TCommentRight'
normal! l
normal! x
endif
startinsert!
endfunction
nnoremap <silent> <LocalLeader><Space> :call IsWhiteLine()<CR>
" -> Undo tree
nnoremap <Leader>u :UndotreeToggle<CR>
let g:undotree_SetFocusWhenToggle=1
" -> Investigate.vim
nnoremap K :call investigate#Investigate()<CR>
let g:investigate_use_dash=1
" -> neomterm
" let g:neoterm_position = 'horizontal'
" let g:neoterm_automap_keys = ',tt'
"
" " Useful maps
" " hide/close terminal
" nnoremap <silent> ,th :call neoterm#close()<cr>
" " clear terminal
" nnoremap <silent> ,tl :call neoterm#clear()<cr>
" " kills the current job (send a <c-c>)
" nnoremap <silent> ,tc :call neoterm#kill()<cr>
endif
" setting for moving plugins
if count(g:nvim_bundle_groups, 'move')
" -> Tag bar
nnoremap <Leader>t :TagbarToggle<CR>
let g:tagbar_autofocus=1
let g:tagbar_expand=1
let g:tagbar_foldlevel=2
let g:tagbar_autoshowtag=1
" Matchit
" Start mathit
" packadd! matchit
" Use Tab instead of % to switch
nmap <Tab> %
vmap <Tab> %
endif
" Setting for navigation plugins
if count(g:nvim_bundle_groups, 'navigate')
" -> NERD Tree
nnoremap <Leader>f :NERDTreeToggle<CR>
let NERDTreeChDirMode=2
let NERDTreeShowBookmarks=1
let NERDTreeShowHidden=1
let NERDTreeShowLineNumbers=0
let NERDTreeAutoDeleteBuffer=1
" let g:NERDTreeShowGitStatus=1
" let g:loaded_nerdtree_git_status=1
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
endif
" Setting for completion plugins
if count(g:nvim_bundle_groups, 'complete')
let g:deoplete#enable_at_startup = 1
" Enable camel case completion
let g:deoplete#enable_camel_case=1
autocmd FileType python setlocal omnifunc=jedi#completions
let g:jedi#completions_enabled=0
let g:jedi#auto_vim_configuration=0
let g:jedi#smart_auto_mappings=0
let g:jedi#use_tabs_not_buffers=1
let g:tmuxcomplete#trigger=''
" -> Neosnippet
" Set information for snippets
let g:neosnippet#enable_snipmate_compatibility=1
" Use <C-O> to expand or jump snippets in insert mode
imap <C-k> <Plug>(neosnippet_expand_or_jump)
smap <C-k> <Plug>(neosnippet_expand_or_jump)
xmap <C-k> <Plug>(neosnippet_expand_target)
" Use <C-O> to replace TARGET within snippets in visual mode
xmap <C-k> <Plug>(neosnippet_start_unite_snippet_target)
" For snippet_complete marker
if has('conceal')
set conceallevel=2 concealcursor=i
endif
endif
" Setting for compiling plugins
if count(g:nvim_bundle_groups, 'compile')
" -> Syntastic
let g:syntastic_check_on_open=1
let g:syntastic_aggregate_errors=1
let g:syntastic_auto_jump=1
let g:syntastic_auto_loc_list=1
if g:nvim_fancy_font
let g:syntastic_error_symbol = '✗'
let g:syntastic_style_error_symbol = '✠'
let g:syntastic_warning_symbol = '∆'
let g:syntastic_style_warning_symbol = '≈'
endif
endif
" Setting for git plugins
if count(g:nvim_bundle_groups, 'git')
endif
" Setting for language specificity
if count(g:nvim_bundle_groups, 'language')
" -> Emmet
" let g:user_emmet_leader_key='<C-Z>'
let g:user_emmet_settings={'indentation':' '}
let g:use_emmet_complete_tag=1
" -> Polyglot
let g:vim_markdown_conceal=0
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment