Skip to content

Instantly share code, notes, and snippets.

Last active May 11, 2024 17:03
Show Gist options
  • Save subfuzion/7d00a6c919eeffaf6d3dbf9a4eb11d64 to your computer and use it in GitHub Desktop.
Save subfuzion/7d00a6c919eeffaf6d3dbf9a4eb11d64 to your computer and use it in GitHub Desktop.
vim/neovim configuration

I recently switched over to neovim (see my screenshots at the bottom). Below 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 this is working for me with 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.

These days I primarily develop in Go. I'm super thrilled and grateful for fatih/vim-go, as well as all the other awesome plugins contributed by an excellent community.

Key map features

I try to avoid C- combinations for the things I do frequently, mapping things that make sense to the <leader> key. The leader key provides a facility for creating customized shortcuts that can be further restricted to apply only in certain modes, such as normal, insert, visual, terminal (neovim-specific), etc.

The leader key is normally defined by the mapleader variable as \. Many people like to redefine it to ,. I prefer ; since it sits right under my right pinkie.

Leader key


In the section below, you can substitute ; for whatever you have configured for you <leader> key.

Insert mode

Shortcut Action
;; Escape (exit insert mode)

Normal mode

Shortcut Action
;c Toggle light and dark themes
;h Toggle distraction free mode (hide/show both nerdtree and tagbar)
Space Toggle NERD Tree, a file tree explorer.
;tb Toggle tagbar
C-l Redraw and ald also clear current highlighted search items (note: l' is lowercase L, not number 1`)
C-p Open fuzzy finder (for files, buffers, etc)
Shortcut Action
;ec Edit vim/neovim config
;sc Source (reload) the config (save it first with :w)
;n Toggle line numbers
;w Toggle wrap
bv Create a new (empty) buffer to the right of a vertical split
bh Create a new (empty) buffer below a horizontal split
;bb Toggle between current and last buffer
;bn Go to next buffer
;bp Go tp prev buffer
;bd Delete current buffer
;bk Kill current buffer (don't prompt to save changes)
;bl List buffers
;bg List and select buffer by #
;tt Open a full screen terminal
;tv Open a terminal in a new split to the right
;th Open a terminal in a new split below
;c Toggle between light and dark backround modes (for supported themes)

Go support

Shortcut Action
gd go-def
;gd go-doc
;gv go-doc in a new vertical split to the right
;gb go-doc for current word in a new browser window/tab
;gs go-implements
gi go-info

To learn more or customize yourself, see fatih/vim-go and read this.

Terminal mode

Shortcut Action
C-x Quit terminal buffer

Any mode

Shortcut Action
A-h Go to buffer to the left
A-j Go to buffer below
A-k Go to buffer above
A-l go to buffer to the right
" Plug (vim-plug) - plugin manager
" Basically: after adding a plug, just remember to run 'PlugInstall'
" This is best with neovim!
" Other helpful links:
" =====================================
call plug#begin('~/.vim/plugged')
" -------------------------------------
" various color schemes (neovim default is 'dark'; I like 'slate' with dark background)
Plug 'freeo/vim-kalisi'
Plug 'w0ng/vim-hybrid'
Plug 'bitterjug/vim-colors-bitterjug'
Plug 'jonathanfilip/vim-lucius'
Plug 'crusoexia/vim-monokai'
Plug 'jacoborus/tender.vim'
Plug 'pbrisbin/vim-colors-off'
Plug 'muellan/am-colors'
Plug 'blueshirts/darcula'
" NERD Tree - tree explorer
" (loaded on first invocation of the command)
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
" nerdtree-git-plugin - show git status in NERD Tree
Plug 'Xuyuanp/nerdtree-git-plugin'
" vim-airline
" Enhanced statusline
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
" Save/restore session support
" tmux users also see:
Plug 'tpope/vim-obsession'
" Excellent git wrapper
Plug 'tpope/vim-fugitive'
" Enforce editor settings
Plug 'editorconfig/editorconfig-vim'
" Make vim a first class Go development environment
Plug 'fatih/vim-go', { 'do': ':GoInstallBinaries' }
" vim-misc
Plug 'xolox/vim-misc'
" vim-easytags
Plug 'xolox/vim-easytags'
" Tagbar
Plug 'majutsushi/tagbar'
Plug 'nsf/gocode', { 'rtp': 'nvim', 'do': '~/.config/nvim/plugged/gocode/nvim/' }
" deoplete (for gocode completion support)
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
" deoplete-go (for gocode completion support)
Plug 'zchee/deoplete-go', { 'do': 'make'}
" Markdown support
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
" Nice interaction with tmux
Plug 'benmills/vimux'
" Fuzzy file, buffer, mru, tag, etc finder
" ctrlp.vim
Plug 'ctrlpvim/ctrlp.vim'
" A better grep (source code aware)
" You must install ack on your machine for the plugin to work
" sudo apt-get install ack-grep, brew install ack, etc.
Plug 'mileszs/ack.vim'
" OMG - insanely awesome fuzzy search and blazing fast grep
" (parent project)
" (more extensive wrapper)
" To update: :PlugUpdate fzf
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" indentline
Plug 'Yggdroot/indentLine'
" -------------------------------------
" 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
" Use 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
set hidden
set confirm
set autowriteall
set wildmenu wildmode=full
" 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
" Use Ag (the silver searcher) instack of Ack
let g:ackprg = 'ag --nogroup --nocolor --column'
" =====================================
" Theme color scheme settings
" =====================================
" blue
" darkblue
" default
" delek
" desert
" elflord
" evening
" koehler
" morning
" murphy
" pablo
" peachpuff
" ron
" shine
" slate
" torte
" zellner
" -------------------------------------
function! Light()
echom "set bg=light"
set bg=light
colorscheme off
set list
function! Dark()
echom "set bg=dark"
set bg=dark
colorscheme darcula
"darcula fix to hide the indents:
set nolist
function! ToggleLightDark()
if &bg ==# "light"
call Dark()
call Light()
" adjustments
"hi Statement ctermfg=1 guifg=#60BB60
"hi Constant ctermfg=4
" 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:
" =====================================
" 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
inoremap ;; <Esc>
" Toggle NERDTree
" Can't get <C-Space> by itself to work, so this works as Ctrl - space - space
"nnoremap <C-Space> :NERDTreeToggle<CR>
"nmap <C-@> <C-Space>
nnoremap <silent> <Space> :NERDTreeToggle<CR>
" toggle tagbar
nnoremap <silent> <leader>tb :TagbarToggle<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>
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
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
" vimux
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)
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
" =====================================
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
" go-def is automatically by default to plain "gd" (no leader required)
au FileType go nnoremap <Leader>gd <Plug>(go-def)
au FileType go nmap <Leader>gp <Plug>(go-def-pop)
au FileType go nnoremap <Leader>gv <Plug>(go-doc-vertical)
" or open in a browser...
au FileType go nnoremap <Leader>gb <Plug>(go-doc-browser)
au FileType go nnoremap <Leader>s <Plug>(go-implements)
au FileType go nnoremap <Leader>i <Plug>(go-info)
au FileType go nnoremap <Leader>gl <Plug>(go-metalinter)
au FileType go nnoremap <Leader>gc <Plug>(go-callers)
" =====================================
" vim-airline status
" configure:
" =====================================
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
set foldcolumn=10
set foldcolumn=0
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
" NERDTree takes focus, so move focus back to the right
" (note: "l" is lowercase L (mapped to moving right)
wincmd l
nnoremap <silent> <leader>h :call ToggleHiddenAll()<CR>
" =====================================
" Custom find
" =====================================
" --column: Show column number
" --line-number: Show line number
" --no-heading: Do not show file headings in results
" --fixed-strings: Search term as a literal string
" --ignore-case: Case insensitive search
" --no-ignore: Do not respect .gitignore, etc...
" --hidden: Search hidden files and folders
" --follow: Follow symlinks
" --glob: Additional conditions for search (in this case ignore everything in the .git/ folder)
" --color: Search color options
command! -bang -nargs=* Find call fzf#vim#grep('rg --column --line-number --no-heading --fixed-strings --ignore-case --no-ignore --hidden --follow --glob "!.git/*" --color "always" '.shellescape(<q-args>), 1, <bang>0)
" =====================================
" Custom styling
" =====================================
set fillchars+=vert:\
autocmd BufEnter * setlocal cursorline
autocmd WinEnter * setlocal cursorline
autocmd BufLeave * setlocal nocursorline
autocmd WinLeave * setlocal nocursorline
" tagbar autopen
"autocmd VimEnter * nested :call tagbar#autoopen(1)
"autocmd FileType * nested :call tagbar#autoopen(0)
"autocmd BufEnter * nested :call tagbar#autoopen(0)
" =====================================
" auto completion
" =====================================
set completeopt+=noinsert
set completeopt+=noselect
let g:deoplete#enable_at_startup = 1
let g:deoplete#sources#go#use_cache = 1
" =====================================
" Init
" =====================================
silent call Dark()
autocmd VimEnter * wincmd p
Copy link

Dark theme with NERDTree and Tagbar


Dark theme - distraction free mode


Light theme


Copy link

How to save file in Neovim and how to quit?

Copy link

How to save file in Neovim and how to quit?

@Anonymous6598 same as vim. esc then :w to write, or :q to quit

Copy link

ntn888 commented Sep 21, 2023

I installed the kickstart config file. Which remaps the 'leader key' to space. But still your mentioned key combination shortcuts dont work. Where can I find key combinations for this config?

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