Skip to content

Instantly share code, notes, and snippets.

@ggicci
Created February 2, 2020 09:28
Show Gist options
  • Save ggicci/d359c6c4420ae119b96bb59e2d2c4cb7 to your computer and use it in GitHub Desktop.
Save ggicci/d359c6c4420ae119b96bb59e2d2c4cb7 to your computer and use it in GitHub Desktop.
Sample configure file init.vim for NeoVim
"
" ## Installed Plugins
"
call plug#begin('~/.nvim/plugins')
Plug 'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
Plug 'itchyny/lightline.vim'
Plug 'tpope/vim-fugitive'
Plug 'NLKNguyen/papercolor-theme'
Plug 'dense-analysis/ale' " Asynchronous Lint Engine (LSP support)
Plug 'maximbaz/lightline-ale'
call plug#end()
" Turns on filetype "detection", "plugin" and "indent".
" https://vi.stackexchange.com/q/10124
filetype plugin indent on " required
"
" ## VIM Settings
"
syntax on
" Allow backspacing over everything in insert mode.
set bs=indent,eol,start
" Show line numbers.
set nu
" Highlight searches.
set hlsearch
" Realtime searches.
set incsearch
" Ignore case when searching.
set ignorecase
" Use terminal true color.
" set termguicolors
" Color scheme.
set t_Co=256
colorscheme PaperColor
set background=dark
if strftime("%H") > 10 && strftime("%H") < 18
set background=light
endif
" Ruler.
set colorcolumn=80,88,120
" Set cursor style.
set guicursor=a:block
" Display extra whitespaces.
set list listchars=tab:»·,trail:·,nbsp:·
" Use `:retab` command to convert all tabs to spaces after setting `expandtab` on.
" For indentation without tabs, the principle is to set 'expandtab', and set 'shiftwidth'
" and 'softtabstop' to the same value, while leaving 'tabstop' at its default value.
" http://vim.wikia.com/wiki/VimTip83
set expandtab " all new tabs will be changed to spaces
set shiftwidth=2 " number of spaces to (auto)indent
set softtabstop=2 " makes the spaces feel like real tabs
set tabstop=2 " number of spaces of tab character
" Encoding guess list while opening a file.
set fencs=utf-8,ucs-bom,gbk
" Encoding while saving a file.
set fenc=utf-8
" Key binding: move between windows.
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
"
" ## Plugin Settings
"
" Plugin: nerdtree
map <C-N> :NERDTreeToggle<CR>
" Close vim if the only window left open is a NERDTree.
autocmd BufEnter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" Open NERDTree automatically when vim starts up on opening a directory.
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
" Hide some files.
let NERDTreeIgnore = ['\.pyc$', '\.git$']
let NERDTreeShowHidden=1
let g:NERDTreeNodeDelimiter = "\u00a0"
" Plugin: ALE
let g:ale_linters = {
\ 'python': [ 'pylint' ],
\ 'javascript': [ 'eslint' ]
\ }
let g:ale_fixers = {
\ 'python': [ 'isort', 'black' ],
\ 'javascript': [ 'eslint' ],
\ 'markdown': [ 'prettier' ],
\ 'html': [ 'prettier' ],
\ 'json': [ 'prettier' ],
\ 'css': [ 'prettier' ],
\ 'less': [ 'prettier' ],
\ 'scss': [ 'prettier' ],
\ 'graphql': [ 'prettier' ],
\ 'yaml': [ 'prettier' ],
\ }
let g:ale_fix_on_save = 1
" Plugin: lightline, lightline-ale
let g:lightline = {
\ 'colorscheme': 'PaperColor',
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modifed' ],
\ ],
\ 'right': [
\ [ 'linter_checking', 'linter_errors', 'linter_warnings', 'linter_infos', 'linter_ok' ],
\ [ 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ],
\ ]
\ },
\ 'component': {
\ 'charvaluehex': '0x%B'
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head',
\ }
\ }
let g:lightline.component_expand = {
\ 'linter_checking': 'lightline#ale#checking',
\ 'linter_infos': 'lightline#ale#infos',
\ 'linter_warnings': 'lightline#ale#warnings',
\ 'linter_errors': 'lightline#ale#errors',
\ 'linter_ok': 'lightline#ale#ok',
\ }
let g:lightline.component_type = {
\ 'linter_checking': 'right',
\ 'linter_infos': 'right',
\ 'linter_warnings': 'warning',
\ 'linter_errors': 'error',
\ 'linter_ok': 'right',
\ }
set laststatus=2
set noshowmode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment