Skip to content

Instantly share code, notes, and snippets.

@sangdongvan
Last active December 4, 2019 06:40
Show Gist options
  • Save sangdongvan/c0acfa984d8a78f6db7d to your computer and use it in GitHub Desktop.
Save sangdongvan/c0acfa984d8a78f6db7d to your computer and use it in GitHub Desktop.
Neovim configuration
" Setup vim-plug -----------------------------------------------------------{{{
" Declare Plugin system Config
call plug#begin('~/.local/share/nvim/plugged')
" UI enhance
Plug 'Yggdroot/indentLine'
Plug 'airblade/vim-gitgutter'
Plug 'itchyny/lightline.vim'
" Distraction-free
Plug 'junegunn/goyo.vim'
" Color scheme
Plug 'joshdick/onedark.vim'
" Editing enhance
Plug 'tpope/vim-surround'
" insert or delete brackets, parens, quotes in pair
Plug 'jiangmiao/auto-pairs'
" Code completion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" Fuzzy search FZF
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Golang editing enhance, not include LSP support
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
" Bash enhance
Plug 'z0mbix/vim-shfmt', { 'for': 'sh' }
" Navigating
Plug 'scrooloose/nerdtree'
" Git
Plug 'Xuyuanp/nerdtree-git-plugin'
Plug 'octref/RootIgnore'
" Support Server Language Protocol
" Check syntax in Vim asynchronously and fix files,
"" with Language Server Protocol (LSP) support
Plug 'w0rp/ale'
" Initialize plugin system
call plug#end()
" }}}
" System Settings -----------------------------------------------------------{{{
" True color support
if (has("termguicolors"))
set termguicolors
endif
" Neovim Settings
set tabstop=2 shiftwidth=2 expandtab
set conceallevel=0
" When you make a change to a file tracked by git, the diff markers should appear automatically.
" The delay is governed by vim's updatetime option; the default value is 4
set updatetime=250
" Fix delay in entering normal mode after pressing ESC (switching to normal mode)
set timeoutlen=1000 ttimeoutlen=0
" Show tabs
set lcs=tab:▸\ ,
" use mouse
set mouse=a
" }}}
" Look and Feel -------------------------------------------------------------{{{
" Keep the git gutter space even with new buffer
set signcolumn=yes
autocmd FileType tagbar,nerdtree setlocal signcolumn=no
" Color scheme
syntax on
set background=dark
colorscheme onedark
" Distraction-free
let g:goyo_width=120
let g:goyo_linenr=1
" Highlight the current line
set cursorline
" One Dark scheme
let g:onedark_termcolors=256
let g:onedark_terminal_italics=1
let g:lightline = {
\ 'colorscheme': 'onedark',
\ }
" }}}
" NERDTree ------------------------------------------------------------------{{{
let NERDTreeIgnore = ['\.pyc$', '__pycache__']
let NERDTreeShowHidden = 1
" }}}
" FZF -----------------------------------------------------------------------{{{
let g:unite_data_directory='~/.nvim/.cache/unite'
let g:unite_source_history_yank_enable=1
let g:unite_prompt='» '
let g:unite_source_rec_async_command =['ag', '--follow', '--nocolor', '--nogroup','--hidden', '-g', '',
\ '--ignore', '.git',
\ '--ignore', '*.png',
\ ]
"}}}
" Golang --------------------------------------------------------------------{{{
let g:go_def_mode='gopls'
let g:go_info_mode='gopls'
" }}}
" Bash enhance --------------------------------------------------------------{{{
" use 2 spaces
let g:shfmt_extra_args = '-i 2'
" }}}
" Key mapping ---------------------------------------------------------------{{{
" Remap Leader to ,
let mapleader = ","
" NERDTree
map <Leader>e :NERDTreeToggle<cr>
map <Leader>c :NERDTreeFind<cr>
" Golang
map <Leader>r :GoRun<cr>
map <Leader>d :GoDef<cr>
" FZF
map <Leader>f :FZF<cr>
" }}}
" Fold, gets it's own section ----------------------------------------------{{{
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()
autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif
autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif
autocmd FileType vim setlocal fdc=1
set foldlevel=99
" Space to toggle folds.
nnoremap <Space> za
vnoremap <Space> za
autocmd FileType vim setlocal foldmethod=marker
autocmd FileType vim setlocal foldlevel=0
autocmd FileType html setlocal foldmethod=marker
autocmd FileType html setlocal fdl=3
autocmd FileType javascript,html,css,scss,typescript setlocal foldlevel=99
autocmd FileType javascript,typescript,css,scss,json setlocal foldmethod=marker
autocmd FileType javascript,typescript,css,scss,json setlocal foldmarker={,}
au FileType html nnoremap <buffer> <leader>F zfat
" }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment