Skip to content

Instantly share code, notes, and snippets.

@davidmh
Last active February 18, 2018 22:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidmh/f6640d010265a1c2a705bb2ea5a2311d to your computer and use it in GitHub Desktop.
Save davidmh/f6640d010265a1c2a705bb2ea5a2311d to your computer and use it in GitHub Desktop.
neovim config
let g:mapleader = "\<SPACE>"
" Show white spaces at the end of a line
set list listchars=tab:▸\ ,eol:¬,trail:·
" edit this nvim config
nnoremap <silent> <leader>ev :vs $HOME/.config/nvim/init.vim<CR>
" auto-reload
augroup VimConfig
au!
au BufWritePost ~/.config/nvim/init.vim so <afile>
augroup END
" save all buffers on enter
nnoremap <silent> <leader><leader> :wa<CR>:echo "saved" <CR>
" tabs as 2 spaces
set tabstop=2
set shiftwidth=2
set softtabstop=2
set expandtab
" avoid wrapping long lines by default
set nowrap
set number relativenumber
set cursorline
" allows modified-unsaved buffers to go into the background
set hidden
" be case-sensitive only when the search inclides upper-case characters
set ignorecase
set smartcase
" preview replace changes in a split window
set inccommand=split
" system clipboard
for action in ['y', 'x', 'p', 'c']
let Action = toupper(action)
for mode_target in ['n', 'v']
exec printf('%snoremap <leader>%s "+%s', mode_target, action, action)
exec printf('%snoremap <leader>%s "+%s', mode_target, Action, Action)
endfor
endfor
" resize faster
nnoremap <M-,> <C-W>5<
nnoremap <M-.> <C-W>5>
nnoremap <M--> <C-W>5-
nnoremap <M-=> <C-W>5+
" move faster
nnoremap <M-up> <C-W>k
nnoremap <M-down> <C-W>j
nnoremap <M-left> <C-W>h
nnoremap <M-right> <C-W>l
" Move to the previous buffer and close current one
" This replicates the idea of closing a tab
nnoremap <leader>q :bprevious <BAR> bdelete #<CR>
" rotate windows
nnoremap <M-r> <C-W>r
" open current file path in a split window
nnoremap vgf <C-W>v<C-W>lgf
" auto-adjust window height to a max of 20 lines
function! AdjustWindowHeight(minheight, ...)
exe max([min([line("$"), (a:0 >= 1) ? a:1 : a:minheight]), a:minheight]) . "wincmd _"
endfunction
augroup QuickFixTweaks
au!
au FileType qf call AdjustWindowHeight(1, 20)
augroup END
" disable visual mode
" using as a toggle for the quickfix window
" nnoremap Q :echo "That's visual-mode what were you trying to do?"<CR>
" Zoom window
function! s:Zoom() abort
if get(s:, 'zoomed', v:false)
execute get(s:, 'window_layout', 'echo null')
let s:zoomed = v:false
else
let s:window_layout = winrestcmd()
" take all the space possible
resize " <C-W>|
vertical resize " <C-W>_
let s:zoomed = v:true
endif
endfunction
command! Zoom call s:Zoom()
nnoremap <C-W><C-z> :Zoom<CR>
" Window fit
" nnoremap <C-W><C-f> :vertical resize max(map(getline(1,'$'), 'len(v:val)'))<CR>
" Toggle quickfix
function! s:toggle_qf()
for i in range(1, winnr('$'))
let bnum = winbufnr(i)
if getbufvar(bnum, '&buftype') == 'quickfix'
cclose
return
endif
endfor
copen
endfunction
command! ToogleQF call s:toggle_qf()
nnoremap Q :ToogleQF<CR>
function! DoRemote(arg)
UpdateRemotePlugins
endfunction
" Plugins
call plug#begin('~/.config/nvim/bundle')
Plug 'tpope/vim-repeat'
" fuzzy finder
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" fzf wrappers for vim
Plug 'junegunn/fzf.vim'
" improved command line
Plug 'junegunn/vim-pseudocl'
" improved search
Plug 'junegunn/vim-oblique'
" clear highlighs
Plug 'pgdouyon/vim-evanesco'
" extending features
"
" new punctuation text objects: ci/, di;, yi*, vi@ ...
Plug 'kurkale6ka/vim-pairs'
" navigation/common actions mappings
Plug 'tpope/vim-unimpaired'
" mappings to easily delete, change and add surroundings in pairs
Plug 'tpope/vim-surround'
" navigate netwr
Plug 'tpope/vim-vinegar'
" swap objects
Plug 'tommcdo/vim-exchange'
" status line
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'airblade/vim-gitgutter'
" color schemes
Plug 'romainl/Apprentice'
Plug 'junegunn/seoul256.vim'
Plug 'arcticicestudio/nord-vim'
" tmux/vim integration
Plug 'christoomey/vim-tmux-navigator'
Plug 'christoomey/vim-tmux-runner'
" git
Plug 'tpope/vim-git'
Plug 'tpope/vim-fugitive' | Plug 'tpope/vim-rhubarb'
Plug 'junegunn/gv.vim'
" js
Plug 'pangloss/vim-javascript'
Plug 'mxw/vim-jsx'
Plug 'moll/vim-node'
" linter
Plug 'w0rp/ale'
" Plug 'prettier/vim-prettier', { 'do': 'yarn install' }
" auto complete
Plug 'Shougo/deoplete.nvim', { 'do': function('DoRemote') }
Plug 'fishbullet/deoplete-ruby'
Plug 'tpope/vim-endwise'
" like :only but for buffers
Plug 'vim-scripts/BufOnly.vim'
" highlight yanked object
Plug 'machakann/vim-highlightedyank'
" handlebars syntax highlight
Plug 'joukevandermaas/vim-ember-hbs'
" elm
Plug 'ElmCast/elm-vim'
" markdown preview
Plug 'shime/vim-livedown'
" unix helper
Plug 'tpope/vim-eunuch'
" display marks in the side
Plug 'kshenoy/vim-signature'
Plug 'tpope/vim-dispatch'
Plug 'tpope/vim-projectionist'
call plug#end()
" Plugin configs
colorscheme nord
" vim-fugitive
" open the latest committed version of the current file
nnoremap <leader>ge :Gedit<cr>
" git blame for the current file
nnoremap <leader>gb :Gblame<cr>
" how git diff on the current changes
nnoremap <leader>gd :Gvdiff<cr>
" show git status
nnoremap <leader>gs :Gstatus<cr>
" git log viewer
nnoremap <leader>gl :GV<CR>
" git log viewer for the current file
nnoremap <leader>gL :GV!<CR>
" git grep the current word
nnoremap <leader>gg :Ag <C-R><C-W>
" git grep the current selection
vnoremap <leader>gg y:Ag <C-R>"
" stage/unstage
nnoremap <leader>gw :Gwrite<cr>
nnoremap <leader>gr :Gread<cr>
nnoremap <leader>gc :Gcommit<cr>
" airline buffer list
" Vim-airline
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#enabled = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.space = "\ua0"
let g:airline_left_sep=''
let g:airline_right_sep=''
let g:airline#extensions#tabline#left_sep = ' '
let g:airline#extensions#tabline#left_alt_sep = '|'
" tmux runner
let g:VtrUseVtrMaps = 1
" Close all other buffers
nnoremap <leader>bo :BufOnly<CR>
" FZF configuration
let $FZF_DEFAULT_COMMAND = 'ag -l --nocolor -g "" | egrep -v ".*(ico|png|jpe?g|gif|svg|ttf|otf|eot|woff|map|dat)\$"'
" [Files] File preview
let g:fzf_files_options =
\ '--preview "highlight -O ansi {} 2> /dev/null"'
" [Buffers] Jump to the existing window if possible
let g:fzf_buffers_jump = 1
" regular search
nnoremap <silent> <C-p> :echo "stop using ctrl-p! use \<leader\>ff"<CR>:sleep 1<CR>:Files<CR>
nnoremap <silent> <leader>ff :Files<CR>
" Open buffers
nnoremap <leader>bu :Buffers<CR>
" MRU
nnoremap <leader>hi :History<CR>
" Marks
nnoremap <leader>ma :Marks<CR>
" Search within current buffer
nnoremap <leader>/ :BLines<CR>
" Search within all buffers
nnoremap <leader>? :Lines<CR><Paste>
" ALE
let g:ale_linters = { 'javascript': ['eslint'] }
let g:ale_fixers = { 'javascript': ['eslint'] }
let g:ale_fix_on_save = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment