This is a guide for setting up Neovim in Windows with plugins for doing Python development. While most of the time I'll be working in WSL using a similar Neovim setup there, I thought it be handy to have approximation of the config in Windows.
Packages
We'll be using scoop for installing neovim and our Python versions (2 and 3). Head on over to https://scoop.sh/ and follow the instructions there to get scoop configured and installed.
Neovim is present in the main buckets:
scoop install neovim
As well as Python 3.8.0
scoop install python
Let's also grab a copy of Python 2.7.17 so we can create a virtualenv for either version
scoop bucket add versions
scoop install python27
Grab a copy of fzf
for fuzzy finding in your project directories. We'll install an plugin for this in a later step
scoop install fzf
And rg
for text searching
scoop install rg
Virtualenvs
We'll be creating virtualenvs for nvim to use Python plugins, like deoplete
, as well as one for the black
formatting plugin. By default, the pip
shim should point to the binary in your Python 3.8 install.
pip install virtualenv
md C:\Users\coolguy\virtualenvs
cd virtualenvs
virtualenv -p C:\Users\coolguy\scoop\apps\python\3.8.0\python.exe nvimpy3
virtualenv -p C:\Users\coolguy\scoop\apps\python27\2.7.17\python.exe nvimpy2
virtualenv -p C:\Users\coolguy\scoop\apps\python\3.8.0\python.exe black
Now we'll install some packages in the virtualenvs.
C:\Users\coolguy\virtualenvs\nvimpy3\Scripts\pip.exe install pynvim jedi
C:\Users\coolguy\virtualenvs\nvimpy2\Scripts\pip.exe install pynvim jedi
C:\Users\coolguy\virtualenvs\black\Scripts\pip.exe install black
vim-plug Plugin Manager
Run the following to setup your plugin directory and install vim-plug
md ~\AppData\Local\nvim\autoload
$uri = 'https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
(New-Object Net.WebClient).DownloadFile(
$uri,
$ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath(
"~\AppData\Local\nvim\autoload\plug.vim"
)
)
init.vim
The config for Neovim lives in C:\Users<user>\AppData\Local\nvim\init.vim. The following is the config we'll be using:
set nocompatible
filetype off
set t_Co=256
call plug#begin('~/AppData/Local/nvim/plugged')
" Python autocomplete
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
Plug 'zchee/deoplete-jedi'
" Git wrapper
Plug 'tpope/vim-fugitive'
" Directory sidebar tree view
Plug 'scrooloose/nerdtree'
" Json plugin
Plug 'elzr/vim-json'
" Text search your project directory
Plug 'dyng/ctrlsf.vim'
" Fuzzy file finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
" Root the project dir to folder w/ .git if applicable
Plug 'airblade/vim-rooter'
" Nice colorscheme based on Visual Studio dark
Plug 'tomasiser/vim-code-dark'
call plug#end()
colors codedark
let g:airline_theme = 'codedark'
set shiftwidth=4
set tabstop=4
set expandtab
filetype plugin on
filetype indent on
syntax on
set nu
set autochdir
nmap <leader>l :set list!<CR>
set mouse=a
set autoread
let NERDTreeQuitOnOpen = 1
set completeopt=menu
set linebreak
autocmd Filetype html,ruby,javascript,yml,yaml,json,haskell,ejs,htmldjango setlocal ts=2 sts=2 sw=2
set noswapfile
set wildignore+=*.pyc
if &term =~ '256color'
" disable Background Color Erase (BCE) so that color schemes
" render properly when inside 256-color tmux and GNU screen.
" see also http://snk.tuxfamily.org/log/vim-256color-bce.html
set t_ut=
endif
let g:ycm_autoclose_preview_window_after_completion=1
set enc=utf-8
set fileencodings=ucs-bom,utf8,prc
set fileencoding=utf-8
set nofoldenable
filetype plugin indent on
let g:python2_host_prog = 'C:\Users\coolguy\virtualenvs\nvimpy2\Scripts\python.exe'
let g:python3_host_prog = 'C:\Users\coolguy\virtualenvs\nvimpy3\Scripts\python.exe'
let g:black_virtualenv = 'c:/Users/jgori/virtualenvs/black'
let g:acp_enableAtStartup = 0
let g:deoplete#enable_at_startup = 1
" deoplete tab-complete
inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
let g:fzf_action = {
\ 'ctrl-s': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-t': 'tabe'
\ }
nnoremap <c-p> :FZF<cr>
nnoremap <c-f> :Rg<cr>
command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ <bang>0 ? fzf#vim#with_preview('up:60%')
\ : fzf#vim#with_preview('right:50%:hidden', '?'),
\ <bang>0)
First Run
You'll get some errors of nonexistent packages. In command mode, enter :PlugInstall
to install the plugins listed in init.vim
. To update these later, run :PlugUpdate
.
TODO
- Explain init.vim
- Copy/Paste between Windows clipboard
- ???
Top comments (3)
Thanks Man
I cannot find init.vim in my AppData Local Directory Folder ?
you need to create with notepad or your text editor. and save it with name init.vim