Skip to content

Instantly share code, notes, and snippets.

@yihuaxiang
Forked from subfuzion/README.md
Created November 14, 2020 12:05
Show Gist options
  • Select an option

  • Save yihuaxiang/cff79ec709a05150eb360f515bf76f49 to your computer and use it in GitHub Desktop.

Select an option

Save yihuaxiang/cff79ec709a05150eb360f515bf76f49 to your computer and use it in GitHub Desktop.
vim/neovim configuration

I just switched over to neovim. This is my updated config file.

It's currently synchronized with my .vimrc config except for a block of neovim-specific terminal key mappings.

This is still a work in progress (everyone's own config is always a labor of love), but I'm already extremely pleased with how well it's working for me in neovim. While terminal mode isn't enough to make me stop using tmux, it is quite good and I like having it since it simplifies my documentation workflow for yanking terminal output to paste in a markdown buffer.

" Plug (vim-plug) - plugin manager
" https://github.com/junegunn/vim-plug
" Basically: after adding a plug, just remember to run 'PlugInstall'
" =====================================
call plug#begin('~/.vim/plugged')
" -------------------------------------
" NERD Tree - tree explorer
" https://github.com/scrooloose/nerdtree
" (loaded on first invocation of the command)
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" nerdtree-git-plugin - show git status in NERD Tree
" https://github.com/Xuyuanp/nerdtree-git-plugin
Plug 'Xuyuanp/nerdtree-git-plugin'
" vim-airline
" Enhanced statusline
" https://github.com/vim-airline/vim-airline
Plug 'vim-airline/vim-airline'
" https://github.com/vim-airline/vim-airline-themes
Plug 'vim-airline/vim-airline-themes'
" Save session
" https://github.com/tpope/vim-obsession
Plug 'tpope/vim-obsession'
" git wrapper
" https://github.com/tpope/vim-fugitive
Plug 'tpope/vim-fugitive'
" https://github.com/editorconfig/editorconfig-vim
Plug 'editorconfig/editorconfig-vim'
" https://github.com/fatih/vim-go
Plug 'fatih/vim-go'
" https://github.com/nsf/gocode
Plug 'nsf/gocode'
" https://github.com/plasticboy/vim-markdown
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
" Nice interaction with tmux
" https://github.com/benmills/vimux
Plug 'benmills/vimux'
" ctrlp.vim
" https://github.com/ctrlpvim/ctrlp.vim
Plug 'ctrlpvim/ctrlp.vim'
" color schemes
" http://vimcolors.com/
Plug 'freeo/vim-kalisi'
Plug 'w0ng/vim-hybrid'
Plug 'bitterjug/vim-colors-bitterjug'
Plug 'jonathanfilip/vim-lucius'
" -------------------------------------
" Add plugins to &runtimepath
call plug#end()
" =====================================
" Auto start NERD tree when opening a directory
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | wincmd p | endif
" Auto start NERD tree if no files are specified
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | exe 'NERDTree' | endif
" Let quit work as expected if after entering :q the only window left open is NERD Tree itself
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
" =====================================
" Initial settings
" =====================================
" Relax file compatibility restriction with original vi
" (not necessary to set with neovim, but useful for vim)
set nocompatible
" Disable beep / flash
set vb t_vb=
" Set tabs and indents (for go)
set ts=8
set shiftwidth=8
set ai sw=8
" replace tab with spaces
"set expandtab
" allow cursor to move to beginning of tab
" will interfere with soft line wrapping (set nolist)
set list lcs=tab:\ \
" highlight matches when searching
" Ust C-l to clear (see key map section)
set hlsearch
" Line numbering
" Toggle set to ';n' in key map section
set nonumber
" Disable line wrapping
" Toggle set to ';w' in key map section
set nowrap
" enable line and column display
set ruler
"disable showmode since using vim-airline; otherwise use 'set showmode'
set noshowmode
" file type recognition
filetype on
filetype plugin on
filetype indent on
" syntax highlighting
syntax on
" scroll a bit horizontally when at the end of the line
set sidescroll=6
" Make it easier to work with buffers
" http://vim.wikia.com/wiki/Easier_buffer_switching
set hidden
set confirm
set autowriteall
set wildmenu wildmode=full
" markdown
" https://github.com/plasticboy/vim-markdown
let g:vim_markdown_folding_disabled = 1
" auto switch current working directory to current buffer (not recommended)
"autocmd BufEnter * :cd %:p:h
" open new split panes to right and below (as you probably expect)
set splitright
set splitbelow
" color scheme
" blue
" darkblue
" default
" delek
" desert
" elflord
" evening
" koehler
" morning
" murphy
" pablo
" peachpuff
" ron
" shine
" slate
" torte
" zellner
colorscheme slate
set bg=light
" adjustments
hi Statement ctermfg=1 guifg=#60BB60
hi Constant ctermfg=4
function! ToggleLightDark()
if &bg ==# "light"
echom "set bg=dark"
set bg=dark
else
echom "set bg=light"
set bg=light
endif
endfunction
" for macvim
"
" Disable scrollbar in gui
" set scrolloff=9999
" hide right scrollbar
set guioptions-=r
"
set guifont=Menlo\ Regular:h16
" =====================================
" key map
" Understand mapping modes:
" http://stackoverflow.com/questions/3776117/what-is-the-difference-between-the-remap-noremap-nnoremap-and-vnoremap-mapping#answer-3776182
" http://stackoverflow.com/questions/22849386/difference-between-nnoremap-and-inoremap#answer-22849425
" =====================================
" change the leader key from "\" to ";" ("," is also popular)
let mapleader=";"
" Shortcut to edit THIS configuration file: (e)dit (c)onfiguration
nnoremap <silent> <leader>ec :e $MYVIMRC<cr>
" Shortcut to source (reload) THIS configuration file after editing it: (s)ource (c)onfiguraiton
nnoremap <silent> <leader>sc :source $MYVIMRC<cr>
" use ;; for escape
" http://vim.wikia.com/wiki/Avoid_the_escape_key
inoremap ;; <Esc>
" Toggle NERDTree
" Can't get <C-Space> by itself to work, so this works as Ctrl - space - space
" https://github.com/neovim/neovim/issues/3101
" http://stackoverflow.com/questions/7722177/how-do-i-map-ctrl-x-ctrl-o-to-ctrl-space-in-terminal-vim#answer-24550772
"nnoremap <C-Space> :NERDTreeToggle<CR>
"nmap <C-@> <C-Space>
nnoremap <silent> <Space> :NERDTreeToggle<cr>
" toggle line numbers
nnoremap <silent> <leader>n :set number! number?<cr>
" toggle line wrap
nnoremap <silent> <leader>w :set wrap! wrap?<cr>
" toggle buffer (switch between current and last buffer)
nnoremap <silent> <leader>bb <C-^>
" go to next buffer
nnoremap <silent> <leader>bn :bn<cr>
nnoremap <C-l> :bn<cr>
" go to previous buffer
nnoremap <silent> <leader>bp :bp<cr>
" https://github.com/neovim/neovim/issues/2048
nnoremap <C-h> :bp<cr>
" close buffer
nnoremap <silent> <leader>bd :bd<cr>
" kill buffer
nnoremap <silent> <leader>bk :bd!<cr>
" list buffers
nnoremap <silent> <leader>bl :ls<cr>
" list and select buffer
nnoremap <silent> <leader>bg :ls<cr>:buffer<Space>
" horizontal split with new buffer
nnoremap <silent> <leader>bh :new<cr>
" vertical split with new buffer
nnoremap <silent> <leader>bv :vnew<cr>
" redraw screan and clear search highlighted items
"http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting#answer-25569434
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
" vimux
" https://raw.githubusercontent.com/benmills/vimux/master/doc/vimux.txt
nnoremap <leader>vc :VimuxPromptCommand<cr>
nnoremap <leader>vl :VimuxRunLastCommand<cr>
nnoremap <leader>vq :VimuxCloseRunner<cr>
nnoremap <leader>vx: VimuxInterruptRunner<cr>
" improved keyboard navigation
nnoremap <leader>h <C-w>h
nnoremap <leader>j <C-w>j
nnoremap <leader>k <C-w>k
nnoremap <leader>l <C-w>l
" improved keyboard support for navigation (especially terminal)
" https://neovim.io/doc/user/nvim_terminal_emulator.html
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
nnoremap <A-h> <C-w>h
nnoremap <A-j> <C-w>j
nnoremap <A-k> <C-w>k
nnoremap <A-l> <C-w>l
" Start terminal in insert mode
au BufEnter * if &buftype == 'terminal' | :startinsert | endif
nnoremap <silent> <leader>tt :terminal<cr>
nnoremap <silent> <leader>tv :vnew<cr>:terminal<cr>
nnoremap <silent> <leader>th :new<cr>:terminal<cr>
tnoremap <C-x> <C-\><C-n><C-w>q
" ctrlp.vim
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = ''
" toggle colors to optimize based on light or dark background
nnoremap <leader>c :call ToggleLightDark()<cr>
" =====================================
" Go
" https://github.com/fatih/vim-go
" =====================================
let g:go_highlight_functions = 1
let g:go_highlight_methods = 1
let g:go_highlight_fields = 1
let g:go_highlight_types = 1
let g:go_highlight_operators = 1
let g:go_highlight_build_constraints = 1
au FileType go nmap <Leader>gd <Plug>(go-doc)
au FileType go nmap <Leader>gv <Plug>(go-doc-vertical)
au FileType go nmap <Leader>gb <Plug>(go-doc-browser)
au FileType go nmap <Leader>s <Plug>(go-implements)
au FileType go nmap <Leader>i <Plug>(go-info)
" =====================================
" vim-airline status
" configure: https://github.com/vim-airline/vim-airline#user-content-extensible-pipeline
" =====================================
let g:airline_theme='monochrome'
" show buffers (if only one tab)
"let g:airline#extensions#tabline#enabled = 1
let s:hidden_all = 0
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
set laststatus=0
set noshowcmd
else
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
endif
endfunction
nnoremap <silent> <leader>h :call ToggleHiddenAll()<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment