My NeoVim Config File

set nocompatible

filetype off

" Line numbers on:
set nu

" Use 256 colors:
set t_Co=256

" Use UTF-8 by default:
set encoding=utf-8

" Remap leader key to space bar:
let mapleader = "\<space>"

"""" Plugins """"""""""""""""""""
call plug#begin()

" Folding:
Plug 'tmhedberg/SimpylFold'
" See docstrings for folded code:
let g:SimplyFold_docstring_preview=1

" PEP8 indentation
Plug 'vim-scripts/indentpython.vim'

" Matching brackets, parens, ...:
Plug 'tpope/vim-surround'

" HTML Tags (for docs see
Plug 'mattn/emmet-vim'
" Use ctrl-a+comma to activate emmet-vim (default is ctrl-y+comma)
let g:user_emmet_expandabbr_key = '<C-a>,'

" Easymotion (see
Plug 'easymotion/vim-easymotion'
" Type <leader><leader>[action] (e.g. <leader><leader>w) to invoke easymotion

" Completion:
Plug 'Valloric/YouCompleteMe'
" Ensure auto-completion window goes away when we're done with it:
let g:ycm_autoclose_preview_window_after_completion=1
" Define shortcut for goto definition:
" map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

" vim-jedi for "IDE" functions:
Plug 'davidhalter/jedi-vim'
" disable autocompletion, since we use YCM for that:
let g:jedi#completions_enabled = 0
" open the go-to function in split, not another buffer:
let g:jedi#use_splits_not_buffers = "right"
" vim-jedi shortcuts:
" <leader>d -> go to definition
" <leader>n -> show usage of a name in the current file
" <leader>r -> rename
" K -> show documentation

" Commenting:
Plug 'scrooloose/nerdcommenter'
" nerdcommentor options:
" Allow commenting and inverting empty lines (useful when commenting a region)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting
let g:NERDTrimTrailingWhitespace = 1
" For more options, see

" A couple of color scheme plugins:
Plug 'jnurmine/Zenburn'
Plug 'altercation/vim-colors-solarized'
colorscheme blue

" A file browser:
Plug 'scrooloose/nerdtree'
" Tell file browser to ignore clutter:
let NERDTreeIgnore=['\.pyc$', '\~$']
" Use F3 to toggle nerdtree:
nnoremap <silent> <F3> :NERDTreeToggle<CR>
" Search:
Plug 'kien/ctrlp.vim'

" Git integration:
Plug 'tpope/vim-fugitive'

" Status line (using Vim-Airline instead of Powerline):
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'

" PEP8 formatting:
Plug 'psf/black'

" All of your Plugins must be added before the following line
call plug#end()            " required
"""" End of Plugins """""""""""""

" Specify where splits should occur:
set splitbelow
set splitright

" split navigation:
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

" code folding:
set foldmethod=indent
set foldlevel=99

" For Python files:
"   four spaces for tab, line length <= 80, Unix line endings:
au BufNewFile,BufRead *.py
     \ | set tabstop=4
     \ | set softtabstop=4
     \ | set shiftwidth=4
     \ | set textwidth=79
     \ | set expandtab
     \ | set autoindent
     \ |set fileformat=unix 
" And for some other file types:
au BufNewFile,BufRead *.js, *.html, *.css
    \ set tabstop=2 \
    \ | set softtabstop=2 \
    \ | set shiftwidth=2

" If in virtual environment, tell
" nvim to use the system Python instead of the one in the venv:
" Figure out the system Python for Neovim.
" NOTE: pynvim must be installed (pip install pynvim) in each
" virtual environment where nvim will be used.
if exists("$VIRTUAL_ENV")
    let g:python3_host_prog=substitute(system("which -a python3 | head -n2 | tail -n1"), "\n", '', 'g')
    let g:python3_host_prog=substitute(system("which python3"), "\n", '', 'g')

" In addition, check if we're in a virtual environment.
" If so, activate it. Among other things, this
" allows YCM to be aware of all packages installed
" in that environment.
py3 << EOF
import os
import sys
if 'VIRTUAL_ENV' in os.environ:
  project_base_dir = os.environ['VIRTUAL_ENV']
  activate_this = os.path.join(project_base_dir, 'bin/')
  exec(open(activate_this).read(), {'__file__': activate_this})

let python_highlight_all=1
syntax on

" If nvim is started with no file or directory named on the command line,
" or if a directory is named on the command line, start NerdTree:
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists("s:std_in") | exe 'NERDTree' argv()[0] | wincmd p | ene | exe 'cd '.argv()[0] | endif

How to Change the Leader Key in Vim

I have to look this up every time I need to do it, so I’m posting this for myself. (Of course, it would be better to keep track of my .vimrc so I wouldn’t have to do it from scratch!)

Add to your .vimrc:

let mapleader = <space> (or whatever key you want)

Installing YouCompleteMe Plugin for Vim in Ubuntu


The YouCompleteMe plugin (YCM) provides “Intellisense-like” features within Vim. Setting it up requires several steps:

  1. Install the plugin using any Vim plugin manager. For example, if you use Vundle, you would add to your .vimrc:
    • Plugin ‘Valloric/YouCompleteMe’
  2. Install development tools:
    • sudo apt install build-essential cmake python3-dev
  3. Install Ubuntu packages on which YCM depends for the programming languages you plan on using:
    1. For C and C++ support: sudo apt install clang-8 libclang1-8 clang-tools-8
    2. For C# support: sudo apt install mono-complete
    3. For JavaScript and TypeScript: sudo apt install nodejs npm
    4. For others, see the YCM documentation at
  4. Run the YCM script with flags appropriate to the above languages:
    • For C and C++: --clang-completer
    • For C#: –cs-completer
    • –ts-completer
    • For example, if you want support for all three of the above language groups, you would do:
      • cd ~/.vim/bundle/YouCompleteMe
      • python3 ./ –clang-completer –cs-completer –ts-completer