Skip to content

Instantly share code, notes, and snippets.

@jdhao
Last active July 29, 2022 17:18
Show Gist options
  • Star 19 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jdhao/d592ba03a8862628f31cba5144ea04c2 to your computer and use it in GitHub Desktop.
Save jdhao/d592ba03a8862628f31cba5144ea04c2 to your computer and use it in GitHub Desktop.
My Neovim configurations for both terminal and gui (using nvim-qt). Repo: https://github.com/jdhao/nvim-config
""""""""""""""""""""""" vim-plug start """""""""""""""""""""""""""""
call plug#begin('~/.local/share/nvim/plugged')
" settings for deoplete
if has('nvim')
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/deoplete.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" python source for deoplete
Plug 'zchee/deoplete-jedi'
" Python completion, goto definition etc.
Plug 'davidhalter/jedi-vim'
" ack front end for vim
Plug 'mileszs/ack.vim'
" autosave files on certain events
Plug '907th/vim-auto-save'
" snippet engine
Plug 'SirVer/ultisnips'
" snippet template for ultisnips
Plug 'honza/vim-snippets'
" show indent lines
" Plug 'Yggdroot/indentLine'
" fancy wim start screen
Plug 'mhinz/vim-startify'
" universal-ctags plugin
Plug 'majutsushi/tagbar'
" status line
Plug 'vim-airline/vim-airline'
" vim-airline theme
Plug 'vim-airline/vim-airline-themes'
" fuzzy file search
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" for insert mode completion
Plug 'ervandew/supertab'
" auto pair insert and delete
Plug 'jiangmiao/auto-pairs'
" another auto pair plugin
Plug 'tpope/vim-surround'
" colorscheme gruvbox
Plug 'morhetz/gruvbox'
" another monokai theme created to mimick sublime text
Plug 'ErichDonGubler/vim-sublime-monokai'
" solarized color scheme
Plug 'lifepillar/vim-solarized8'
" monokai theme for vim
Plug 'sickill/vim-monokai'
" comment plugin
Plug 'scrooloose/nerdcommenter'
" auto format tool
Plug 'sbdchd/neoformat'
" another auto format tool
"Plug 'Chiel92/vim-autoformat'
" file explorer for vim
Plug 'scrooloose/nerdtree'
" syntax check and make
Plug 'neomake/neomake'
" multiline editting plugin
Plug 'terryma/vim-multiple-cursors'
" highlight yanked region
Plug 'machakann/vim-highlightedyank'
" python code folding
Plug 'tmhedberg/SimpylFold'
" colorful icons, always put this plugin to the last
"Plug 'ryanoasis/vim-devicons'
call plug#end()
"""""""""""""""""""""""""""""""" vim-plug end """""""""""""""""""""""""""
"""""""""""""""""""""""""""""""" plugin settings """"""""""""""""""""""""""
""""""""""""""""""""""" deoplete settings""""""""""""""""""""""""""
let g:deoplete#enable_at_startup = 1
" automatically close function preview windows after completion
" see https://goo.gl/Bn5n39
"autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
" deoplete tab-complete, see https://goo.gl/LvwZZY
" inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
" disable completion for comment and string
call deoplete#custom#source('_', 'disabled_syntaxes', ['Comment', 'String'])
" min character needed to start completion, see https://goo.gl/QP9am2
call deoplete#custom#source('_', 'min_pattern_length', 3)
" auto select the first completion entry
set completeopt+=noinsert
" completely disable the preview window during autocomplete process,
" see https://goo.gl/18zNPD for more info
set completeopt-=preview
" candidate list item limit
call deoplete#custom#option('max_list', 30)
"The number of processes used for the deoplete parallel feature.
call deoplete#custom#option('num_processes', 16)
" Delay the completion after input in milliseconds.
call deoplete#custom#option('auto_complete_delay', 10)
""""""""""""""""""""""""""""nerdcommenter settings"""""""""""""""""""
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
" Align line-wise comment delimiters flush left instead
" of following code indentation
let g:NERDDefaultAlign = 'left'
" Enable NERDCommenterToggle to check all selected lines is commented or not
let g:NERDToggleCheckAllLines = 1
""""""""""""""""""""""""vim-auto-save settings"""""""""""""""""""""""
" enable AutoSave on nvim startup
let g:auto_save = 1
" autosave events
let g:auto_save_events = ["InsertLeave", "TextChanged"]
" show autosave status
let g:auto_save_silent = 0
"""""""""""""""""""""""""indentLine settings""""""""""""""""""""""""""
" disable indentLine
" let g:indentLine_enabled = 0
"""""""""""""""""""""""""supertab settings""""""""""""""""""""""""""
" auto-close method preview window
"let g:SuperTabClosePreviewOnPopupClose = 1
""""""""""""""""""deoplete-jedi settings"""""""""""""""""""""""""""
" show doc string
let g:deoplete#sources#jedi#show_docstring = 1
" for large package, set autocomplete wait time longer
let g:deoplete#sources#jedi#server_timeout = 50
"""""""""""""""""""""""""""""'ack.vim settings""""""""""""""""""""""'""
" Prefer rg > ag > ack
" https://hackercodex.com/guide/vim-search-find-in-project/
if executable('rg')
let g:ackprg = 'rg -S --no-heading --vimgrep'
elseif executable('ag')
let g:ackprg = 'ag --vimgrep'
endif
" sublime text style text searching across the whole project
" also do not open the first match by default(the bang version does not
" open the first match), see https://goo.gl/xMsmxi
cnoreabbrev Ack Ack!
nnoremap <C-S-F> :Ack!<SPACE>
"""""""""""""""""""""""""""""" neomake settings """""""""""""""""""""""
" when writing or reading a buffer, and
" on changes in normal mode (after 0.5s; no delay when writing).
call neomake#configure#automake('nrw', 50)
" change warning signs, see https://goo.gl/eHcjSq
highlight NeomakeErrorMsg ctermfg=227 ctermbg=237
let g:neomake_warning_sign={'text': '!', 'texthl': 'NeomakeErrorMsg'}
" only enable pylint linter for python
let g:neomake_python_enabled_makers = ['flake8', 'pylint']
" do not highlight columns, it works bad for sublimemonokai
" see https://goo.gl/wd68ex for more info
let g:neomake_highlight_columns = 0
"let g:neomake_python_pylint_maker = {
" \ 'args': [
" \ '-d', 'C0103, C0111',
" \ '-f', 'text',
" \ '--msg-template="{path}:{line}:{column}:{C}: [{symbol}] {msg} [{msg_id}]"',
" \ '-r', 'n'
" \ ],
" \ 'errorformat':
" \ '%A%f:%l:%c:%t: %m,' .
" \ '%A%f:%l: %m,' .
" \ '%A%f:(%l): %m,' .
" \ '%-Z%p^%.%#,' .
" \ '%-G%.%#',
" \ }
""""""""""""""""""""""" nerdtree settings """"""""""""""""""""""""""
" toggle nerdtree window
nnoremap <silent> <C-k><C-B> :NERDTreeToggle<CR>
" ignore certain files and folders
let NERDTreeIgnore = ['\.pyc$', '^__pycache__$']
" reveal currently editted file in nerdtree widnow, see https://goo.gl/kbxDVK
nmap ,nf :NERDTreeFind<CR>
" exit vim when the only window is nerdtree window, see
" https://github.com/scrooloose/nerdtree
" autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") &&
" \ b:NERDTree.isTabTree()) | q | endif
" automatically show nerdtree window on entering nvim,
" see https://github.com/scrooloose/nerdtree, but now the cursor
" is in nerdtree window, so we need to change it to the file window,
" extract from https://goo.gl/vumpvo
autocmd VimEnter * NERDTree | wincmd l
" delete a file buffer when you have deleted it in nerdtree
let NERDTreeAutoDeleteBuffer = 1
" show current root as realtive path from HOME in status bar
let NERDTreeStatusline="%{exists('b:NERDTree')?fnamemodify(b:NERDTree.root.path.str(), ':~'):''}"
""""""""""""""""""""""" tagbar settings """"""""""""""""""""""""""
" shortcut to toggle tagbar window
nnoremap <silent> <C-K><C-T> :TagbarToggle<CR>
"""""""""""""""""""""""""""vim-airline setting""""""""""""""""""""""
"set airline themes
let g:airline_theme='badwolf'
" show tabline
let g:airline#extensions#tabline#enabled = 1
" show buffer number for easier switching between buffer
" see https://github.com/vim-airline/vim-airline/issues/1149
let g:airline#extensions#tabline#buffer_nr_show = 1
"make airline more beautiful, see https://goo.gl/XLY19H for more info
let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
" unicode symbols
let g:airline_left_sep = '»'
let g:airline_left_sep = '▶'
let g:airline_right_sep = '«'
let g:airline_right_sep = '◀'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.linenr = '␤'
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.paste = 'ρ'
let g:airline_symbols.paste = 'Þ'
let g:airline_symbols.paste = '∥'
let g:airline_symbols.whitespace = 'Ξ'
" airline symbols
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.branch = ''
let g:airline_symbols.readonly = ''
let g:airline_symbols.linenr = ''
""""""""""""""""""" vim-highlightedyank settings """"""""""""""
" reverse the highlight color for yanked text for better visuals
highlight HighlightedyankRegion cterm=reverse gui=reverse
" let highlight endures longer
let g:highlightedyank_highlight_duration = 1000
""""""""""""""""""neoformat settins"""""""""""""""""""""""
" Enable alignment
let g:neoformat_basic_format_align = 1
" Enable tab to spaces conversion
let g:neoformat_basic_format_retab = 1
" Enable trimmming of trailing whitespace
let g:neoformat_basic_format_trim = 1
"""""""""""""""""""""""""fzf settings""""""""""""""""""""""""""
" hide status line when open fzf window
autocmd! FileType fzf
autocmd FileType fzf set laststatus=0 noshowmode noruler
\| autocmd BufLeave <buffer> set laststatus=2 showmode ruler
" use ff to open fzf search window
nnoremap <silent> ff :FZF<cr>
nnoremap <silent> FF :FZF ~<cr>
"""""""""""""""""""""""""fzf.vim settings""""""""""""""""""
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" [Tags] Command to generate tags file
let g:fzf_tags_command = 'ctags -R'
""""""""""""""""""""""""jedi-vim settings"""""""""""""""""""
" disable autocompletion, cause we use deoplete for completion
let g:jedi#completions_enabled = 0
" open the go-to function in split, not another buffer
" let g:jedi#use_splits_not_buffers = "right"
""""""""""""""""""""""""supertab settings"""""""""""""""""""
" use the default top to bottom way for scroll, see https://goo.gl/APdo9V
let g:SuperTabDefaultCompletionType = "<c-n>"
"""""""""""""""""""""""""""""""""""options"""""""""""""""""""""""""""""""
" activate syntax
syntax on
" turn on plugin and indent for file types
filetype plugin indent on
" changing fillchars for folding, so there is no garbage charactes
set fillchars=fold:-,vert:\|
" paste mode toggle, it seems that neovim's bracketed paste mode
" does not work very well for now, so we use old paste mode
set pastetoggle=<F2>
" show current line cursor is in
set cursorline
" split window below when creating new window
set splitbelow
"highlight python code
let python_highlight_all=1
" Time in milliseconds to wait for a mapped sequence to complete
" see https://goo.gl/vHvyu8 for more info
set timeoutlen=1200
" clipboard settings, see https://goo.gl/YAHBbJ for more
" information
set clipboard+=unnamedplus
" do not create swap files
set noswapfile " disable creating swapfiles, see https://goo.gl/FA6m6h
"general tab settings
set tabstop=4 " number of visual spaces per TAB
set softtabstop=4 " number of spaces in tab when editing
set shiftwidth=4 " number of spaces to use for autoindent
set expandtab " tabs are space
set showmatch " show matching bracket
set number " show line number
set relativenumber " show line number relative to current line
" character case related settings
set ignorecase " ignore case when searching
set smartcase " case sensitive when uppercase present
" encoding settings for vim
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1
set linebreak " line will break at predefined characters
set wildmode=list:longest,full " list all items and start selecting matches
" set a ruler at column 80 and also set its color
" see https://goo.gl/vEkF5i for more info
set colorcolumn=80
highlight ColorColumn ctermbg=235 guibg=#2c2d27
" minimum lines to keep above and below cursor
set scrolloff=5
""""""""""""""""""""""" mapping settings """""""""""""""""""""""""
let mapleader = "," " leader is comma
" paste above current cursor, see https://stackoverflow.com/a/1346777/6064933
nmap <leader>p o<ESC>p
" paste below current cursor
nmap <leader>P O<ESC>p
" fast save and close, halt time between pressing
" leader key and the following key should be short,
" or it will be interpreted as separate command.
nmap <leader>w :w<CR>
nmap <leader>q :q<CR>
nmap <leader>Q :qa<CR>
" go to previous and next item in location list quickly
nmap [l :lnext<CR>
nmap ]l :lprevious<CR>
" go to previous and next item in quickfix list
nmap [q :cprevious<CR>
nmap ]q :cnext<CR>
nmap \x :cclose<CR>
" toggle highlight search, see https://goo.gl/3H85hh
nnoremap <silent><expr> <Leader>hl (&hls && v:hlsearch ? ':nohls' : ':set hls')."\n"
" Do not use arrow key in vim, see https://goo.gl/s1yfh4
" disable arrow key for normal mode
nnoremap <Up> <nop>
nnoremap <Down> <nop>
nnoremap <Left> <nop>
nnoremap <Right> <nop>
" disable arrow key for insert mode
inoremap <Up> <nop>
inoremap <Down> <nop>
inoremap <Left> <nop>
inoremap <Right> <nop>
" better ESC in insert mode, see https://goo.gl/SSSW5v
inoremap jj <esc>
" insert new line below, see https://stackoverflow.com/a/16136133/6064933
nmap oo o<ESC>
" insert new line above
nmap OO O<ESC>
" go to lineBegin and lineEnd
nnoremap lb 0
nnoremap le $
" yank from cursor to end of line, to be consistent with C, D
nnoremap Y y$
" move cursor based on physical lines not the actual lines.
nmap j gj
nmap k gk
nmap $ g$
nmap ^ g^
nmap 0 g0
noremap <silent> <expr> j (v:count == 0 ? 'gj' : 'j')
noremap <silent> <expr> k (v:count == 0 ? 'gk' : 'k')
" resize windows using alt and h,j,k,l, inspiration from
" https://goo.gl/vVQebo (page bottom)
nnoremap <silent> <A-h> <C-w><
nnoremap <silent> <A-j> <C-W>-
nnoremap <silent> <A-k> <C-W>+
nnoremap <silent> <A-l> <C-w>>
" fast window switching, inspiration from
" https://stackoverflow.com/a/4373470/6064933
nnoremap <silent> <A-left> <C-w>h
nnoremap <silent> <A-right> <C-w>l
nnoremap <silent> <A-down> <C-w>j
nnoremap <silent> <A-up> <C-w>k
" continuous visual shifting (does not exit Visual mode), `gv` means
" to reselect previous visual area, see https://goo.gl/m1UeiT
vnoremap < <gv
vnoremap > >gv
" when completion menu is shown, use <enter> to select an item
" and do not add an annoying newline, otherwise, <enter> is just what it is,
" for more info , see https://goo.gl/KTHtrr and https://goo.gl/MH7w3b
inoremap <expr> <cr> ((pumvisible())?("\<C-Y>"):("\<cr>"))
" switching buffers quickly, extracted from vim-unimpaired
nnoremap [b :bp<cr> " go to previous buffer
nnoremap ]b :bn<cr> " go to next buffer
" reload init.vim quickly and give a message
" `%` represent the current file, i.e., init.vim
nnoremap <silent> <leader>s :so $MYVIMRC<cr>
\ :echom "Nvim new config is in effect now!"<cr>
" edit init.vim in a vertical split
nnoremap <silent> <leader>e :vnew $MYVIMRC<cr>
""""""""""""""""""""""" colorscheme and highlight""""""""""""""""""""""""""""
"set termguicolors
set notermguicolors
set background=dark
""""""""""""""""""""""""""sublimemonokai settings"""""""""""""""""""""""""
" fix highlight problem with sublimemonokai, see https://goo.gl/sq4WvF
" only 256 colors are supported, so color with html format is not accepted,
" see https://goo.gl/H4xvDr.
" augroup vimrc_highlightedyank
" autocmd ColorScheme sublimemonokai highlight HighlightedyankRegion
" \ ctermbg=88 guibg=#41423a
" augroup END
" colorscheme sublimemonokai
""""""""""""""""""""""""""""gruvbox settings"""""""""""""""""""""""""""
colorscheme gruvbox
let g:gruvbox_contrast_dark="hard"
""""""""""""""""""""""""""" solarized8 settings"""""""""""""""""""""""""
"colorscheme solarized8
"let g:solarized_use16 = 1
" change the color of popup menu for autocompletion
" extracted from spf13-vim, see https://goo.gl/frRXHP
highlight Pmenu guifg=#000000 guibg=#F8F8F8 ctermfg=black ctermbg=Lightgray
highlight PmenuSbar guifg=#8A95A7 guibg=#F8F8F8 gui=NONE ctermfg=darkcyan
\ ctermbg=lightgray cterm=NONE
highlight PmenuThumb guifg=#F8F8F8 guibg=#8A95A7 gui=NONE ctermfg=lightgray
\ ctermbg=darkcyan cterm=NONE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" auto command "
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" automatically save current file and execute it when pressing the <F9> key
" it is useful for small script
autocmd FileType python nnoremap <buffer> <F9> :exec 'w !python'
\ shellescape(@%, 1)<CR>
autocmd FileType cpp nnoremap <F9> :w <CR> :!g++ -Wall -std=c++11 %
\ -o %<&&./%<<CR>
" do not use smart case in command line mode
" extracted from https://goo.gl/vCTYdK
augroup dynamic_smartcase
autocmd!
autocmd CmdLineEnter : set nosmartcase
autocmd CmdLineLeave : set smartcase
augroup END
@jdhao
Copy link
Author

jdhao commented Apr 18, 2019

To make deoplete work, the value of variable python3_host_prog should be changed to the location of Python 3 executable on your system

No longer needed. Now the script will detect your system and set up python3_host_prog automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment