Skip to content

Instantly share code, notes, and snippets.

@julianwachholz
Last active October 17, 2017 14:07
Show Gist options
  • Save julianwachholz/118a0cbfbb492fc5d6329b967723086e to your computer and use it in GitHub Desktop.
Save julianwachholz/118a0cbfbb492fc5d6329b967723086e to your computer and use it in GitHub Desktop.
NeoVIM configuration (wip)
" NeoVIM Configuration
" Map the leader key to SPACE
let mapleader="\<SPACE>"
nnoremap <SPACE> <nop>
" Set options {{{
set title " Set window title to file
set showcmd " Show (partial) command in status line
set showmatch " Show matching brackets
set showmode " Show current mode
set ruler " Show line and column numbers of the cursor
set number " Show line numbers
set formatoptions+=o " Continue comment marker in new lines
set textwidth=0 " Hard wrap long lines as you type them
set expandtab " Insert spaces when tab is pressed
set tabstop=2 " Tab shows as 2 spaces
set softtabstop=2 " 2 Spaces in a tab when editing
set shiftwidth=2 " Indentation amounts
set cursorline " Highlight current cursor line
set autowrite " Write buffer when switching
set autowriteall " also when quitting etc
set noerrorbells " No beeps
set modeline " Enable modeline
set linespace=0 " line-space minimum
set nojoinspaces " No two spaces after punctuation in joins
set mouse=a " Use the mouse
set wildmenu " Visual autocomplete for files
set clipboard+=unnamedplus " Use system clipboard
set splitbelow
set splitright
if !&scrolloff
set scrolloff=3 " Show next 3 lines while scrolling
endif
if !&sidescrolloff
set sidescrolloff=5 " Show next 5 columns while side-scrolling
endif
set nostartofline " Do not jump to first char with page commands
" }}}
" Whitespace control {{{
" Tell Vim which characters to show for expanded TABs,
" trailing whitespace, and end-of-lines. VERY useful!
if &listchars ==# 'eol:$'
set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
endif
set list " Show problematic characters.
" Also highlight all tabs and trailing whitespace characters.
highlight ExtraWhitespace ctermbg=darkgreen guibg=darkgreen
match ExtraWhitespace /\s\+$\|\t/
" Remove trailing spaces.
function! TrimWhitespace()
let l:save = winsaveview()
%s/\s\+$//e
call winrestview(l:save)
endfunction
" FIXME: Do not call this on makefile and sv files.
autocmd BufWritePre * call TrimWhitespace()
nnoremap <leader>W :call TrimWhitespace()<CR>
" }}}
" Create directories if they don't exist when saving a file
augroup BWCCreateDir
autocmd!
autocmd BufWritePre * if expand("<afile>")!~#'^\w\+:/' && !isdirectory(expand("%:h")) | execute "silent! !mkdir -p ".shellescape(expand("%:h"), 1) | redraw | endif
augroup END
autocmd FileType vim,txt setlocal foldmethod=marker
au FileType gitcommit 1 | startinsert
" Search {{{
set ignorecase " Make searching case insensitive
set smartcase " ... unless query has capital letters
set gdefault " Use 'g' flag by default with :s/foo/bar/
set magic " Use magic patterns (extended regex)
" Use <C-L> to clear the highlighting of :set hlsearch.
if maparg('<C-L>', 'n') ==# ''
nnoremap <silent> <C-L> :nohlsearch<CR><C-L>
endif
" }}}
" Moving around
inoremap <C-e> <End>
inoremap <C-a> <Home>
nnoremap <Leader>w :w<CR>
nnoremap <Leader>dd :bdel<CR>
nnoremap <C-j> :bnext<CR>
nnoremap <C-k> :bprev<CR>
" Move lines one up or down
"inoremap <C-S-j> :m .+1<CR>==
"inoremap <C-S-k> :m .-2<CR>==
" Search and Replace
nmap <Leader>s :%s//g<Left><Left>
nmap <Leader>m :make<space>
" Relative numbering
function! NumberToggle()
if(&relativenumber == 1)
set nornu
set number
else
set rnu
endif
endfunc
" Toggle between normal and relative numbering.
nnoremap <leader>r :call NumberToggle()<cr>
" Lazy commands
nnoremap ; :
let g:python_host_prog = '/usr/local/bin/python2'
let g:python3_host_prog = '/usr/local/bin/python3'
" Plugins {{{
call plug#begin('~/.local/share/nvim/plugged')
Plug 'Shougo/denite.nvim' " Fuzzy matcher
Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' } " Auto completion
Plug 'airblade/vim-gitgutter' " Show changed/deleted/added lines in gutter
Plug 'bling/vim-bufferline' " Show buffers in airline
Plug 'chriskempson/base16-vim' " Base16 colorschemes
Plug 'jreybert/vimagit' " Git functions
Plug 'neomake/neomake' " Asynchronous linting
Plug 'scrooloose/nerdcommenter' " Code commenting (toggling)
Plug 'sheerun/vim-polyglot' " Proper modern language syntax
Plug 'slashmili/alchemist.vim', { 'for': 'elixir' } " Elixir
Plug 'elixir-editors/vim-elixir', { 'for': 'elixir' } " More Elixir
Plug 'python-mode/python-mode', { 'for': 'python', 'branch': 'develop' } " Python
Plug 'tmhedberg/SimpylFold', { 'for': 'python' } " Python code folds
Plug 'tpope/vim-vinegar' " Enhance netrw
Plug 'vim-airline/vim-airline' " Lightweight statusline
Plug 'vim-airline/vim-airline-themes' " ... and themes
Plug 'zchee/deoplete-jedi', { 'for': 'python' } " Python auto completion server
Plug 'wellle/targets.vim'
Plug 'chrisbra/csv.vim'
call plug#end()
" }}}
" Plugin configuration
colorscheme base16-ocean
let g:airline_theme='base16'
" fugitive {{{
nmap <leader>gs :Gstatus<CR>
nmap <leader>gc :Gcommit<CR>
" }}}
" Denite {{{
nnoremap <leader><leader> :Denite file_rec<CR>
nnoremap <leader>fl :Denite line<CR>
nnoremap <leader>fb :Denite buffer<CR>
nnoremap <leader>ff :Denite grep<CR>
call denite#custom#option('default', {
\ 'prompt': '❯'
\ })
call denite#custom#source('file_rec', 'matchers', ['matcher_fuzzy', 'matcher_ignore_globs'])
" Ignore files from results
call denite#custom#filter('matcher_ignore_globs', 'ignore_globs',
\ [ '*~', '*.o', '*.exe', '*.bak',
\ '.DS_Store', '*.pyc', '*.sw[po]', '*.class',
\ '.hg/', '.git/', '.bzr/', '.svn/',
\ 'node_modules/', 'bower_components/', 'tmp/', 'log/', 'vendor/ruby',
\ '.idea/', 'dist/',
\ 'deps/', '_build/', 'build/', 'data/',
\ '.cache/', '.venv/',
\ 'tags', 'tags-*'])
" use <C-j> <C-k> to navigate results
call denite#custom#map('insert', '<C-j>', '<denite:move_to_next_line>', 'noremap')
call denite#custom#map('insert', '<C-k>', '<denite:move_to_previous_line>', 'noremap')
call denite#custom#var('file_rec', 'command',
\ ['ag', '--follow', '--nocolor', '--nogroup', '-g', ''])
call denite#custom#var('grep', 'command', ['ag'])
call denite#custom#var('grep', 'default_opts',
\ ['-i', '--vimgrep'])
call denite#custom#var('grep', 'recursive_opts', [])
call denite#custom#var('grep', 'pattern_opt', [])
call denite#custom#var('grep', 'separator', ['--'])
call denite#custom#var('grep', 'final_opts', [])
" }}}
" bufferline
let g:bufferline_echo = 0
let g:bufferline_modified = '*'
let g:bufferline_show_bufnr = 0
" airline {{{
"let g:airline_left_sep = ' '
"let g:airline_left_alt_sep = '|'
"let g:airline_right_sep = ' '
"let g:airline_right_alt_sep = '|'
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline#extensions#tabline#enabled = 0
let g:airline_skip_empty_sections = 1
let g:airline_left_sep = ''
let g:airline_right_sep = ''
let g:airline_symbols.crypt = '🔒'
let g:airline_symbols.linenr = '☰'
let g:airline_symbols.linenr = '␊'
let g:airline_symbols.maxlinenr = ''
let g:airline_symbols.branch = '⎇'
let g:airline_symbols.whitespace = 'Ξ'
" }}}
" neomake
call neomake#configure#automake('rnw', 300)
let g:neomake_python_enabled_makers = ['flake8']
let g:neomake_elixir_enabled_makers = []
let g:neomake_elixir_elixir_maker = {
\ 'exe': 'elixirc',
\ 'args': [
\ '--ignore-module-conflict', '--warnings-as-errors',
\ '--app', 'mix', '--app', 'ex_unit',
\ '-o', '$TMPDIR', '%:p',
\ '-pa', '_build/dev/lib/*/ebin'
\ ],
\ 'errorformat':
\ '** %s %f:%l: %m,'.
\ '%Ewarning: %m,%C %f:%l,%Z'
\ }
" \ '%E** %s %f:%l: %m,'.
" \ '%W%f:%l'
" SimpylFold
let g:SimpylFold_docstring_preview = 1
let g:SimpylFold_fold_import = 1
let g:pymode_python = 'python3'
let g:pymode_rope = 0
" Deoplete {{{
"set completeopt+=noinsert
"set completeopt-=preview
let g:deoplete#enable_at_startup = 1
let g:deoplete#sources#jedi#show_docstring = 1
let g:deoplete#max_list = 10
autocmd InsertLeave,CompleteDone * if pumvisible() == 0 | pclose | endif
inoremap <expr><tab> pumvisible()? "\<c-n>" : "\<tab>"
" inoremap <expr><C-h> deoplete#smart_close_popup()."\<C-h>"
" inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
" function! s:my_cr_function() abort
" return deoplete#close_popup() . "\<CR>"
" endfunction
" }}}
" netrw ignore patterns
set wildignore=*.pyc,__pycache__,.DS_Store,*.exe,*.sw[po],.git/,node_modules,.idea/,.cache/,.venv/
"let g:netrw_list_hide=netrw_gitignore#Hide()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment