Last active
July 9, 2020 13:25
-
-
Save gnarula/e42e9310af9e44a830fca63d07a6e94f to your computer and use it in GitHub Desktop.
Neovim config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mapleader = "," | |
" Load vundle | |
set nocompatible | |
filetype off | |
call plug#begin() | |
" GUI enhancements | |
Plug 'itchyny/lightline.vim' | |
Plug 'machakann/vim-highlightedyank' | |
Plug 'andymass/vim-matchup' | |
" Fuzzy finder | |
Plug 'airblade/vim-rooter' | |
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } | |
Plug 'junegunn/fzf.vim' | |
" NerdTree | |
Plug 'preservim/nerdtree' | |
" Indent Detection | |
Plug 'luochen1990/indent-detector.vim' | |
" Semantic language support | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
" Syntactic language support | |
Plug 'cespare/vim-toml' | |
Plug 'stephpy/vim-yaml' | |
Plug 'rust-lang/rust.vim' | |
Plug 'rhysd/vim-clang-format' | |
Plug 'godlygeek/tabular' | |
Plug 'plasticboy/vim-markdown' | |
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' } | |
Plug 'HerringtonDarkholme/yats.vim' | |
" Colorscheme | |
Plug 'chriskempson/base16-vim' | |
Plug 'shinchu/lightline-gruvbox.vim' | |
" Navigation | |
Plug 'christoomey/vim-tmux-navigator' | |
" Beancount | |
Plug 'nathangrigg/vim-beancount' | |
call plug#end() | |
if has('nvim') | |
set guicursor=n-v-c:block-Cursor/lCursor-blinkon0,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor | |
set inccommand=nosplit | |
noremap <C-q> :confirm qall<CR> | |
end | |
" deal with colors | |
if !has('gui_running') | |
set t_Co=256 | |
endif | |
if (match($TERM, "-256color") != -1) && (match($TERM, "screen-256color") == -1) | |
" screen does not (yet) support truecolor | |
set termguicolors | |
endif | |
" Colors | |
set background=dark | |
colorscheme base16-gruvbox-dark-hard | |
hi Normal ctermbg=NONE | |
" Get syntax | |
syntax on | |
" Base16 | |
let base16colorspace=256 | |
" Lightline | |
let g:lightline = { | |
\ 'component_function': { | |
\ 'filename': 'LightlineFilename', | |
\ }, | |
\ 'colorscheme': 'gruvbox', | |
\ } | |
function! LightlineFilename() | |
return expand('%:t') !=# '' ? @% : '[No Name]' | |
endfunction | |
if executable('rg') | |
set grepprg=rg\ --no-heading\ --vimgrep | |
set grepformat=%f:%l:%c:%m | |
endif | |
" Javascript | |
"let javaScript_fold=1 | |
" Java | |
let java_ignore_javadoc=1 | |
" Open hotkeys | |
map <leader>f :Files<CR> | |
map <leader>F :Bufffers<CR> | |
" Better display for messages | |
set cmdheight=2 | |
set updatetime=300 | |
inoremap <silent><expr> <TAB> | |
\ pumvisible() ? "\<C-n>" : | |
\ <SID>check_back_space() ? "\<TAB>" : | |
\ coc#refresh() | |
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>" | |
function! s:check_back_space() abort | |
let col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~# '\s' | |
endfunction | |
" Use <c-space> to trigger completion. | |
inoremap <silent><expr> <c-space> coc#refresh() | |
" Use <cr> to confirm completion, `<C-g>u` means break undo chain at current position. | |
" Coc only does snippet and additional edit on confirm. | |
" inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>" | |
" Or use `complete_info` if your vim support it, like: | |
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>" | |
" ============================================================================= | |
" # Editor settings | |
" ============================================================================= | |
"filetype plugin indent on | |
set autoindent | |
set timeoutlen=300 | |
set encoding=utf-8 | |
set scrolloff=2 | |
set noshowmode | |
set hidden | |
set nowrap | |
set number | |
set nojoinspaces | |
" Splits | |
set splitright | |
set splitbelow | |
" Center search results | |
nnoremap <silent> n nzz | |
nnoremap <silent> N Nzz | |
nnoremap <silent> * *zz | |
nnoremap <silent> # #zz | |
nnoremap <silent> g* g*zz | |
" Very magic by default | |
nnoremap ? ?\v | |
nnoremap / /\v | |
cnoremap %s/ %sm/ | |
" Show hidden characters | |
set listchars=nbsp:¬,extends:»,precedes:«,trail:• | |
" <leader>s for Rg search | |
noremap <leader>s :Rg | |
let g:fzf_layout = { 'down': '~20%' } | |
command! -bang -nargs=* Rg | |
\ call fzf#vim#grep( | |
\ 'rg --column --line-number --no-heading --color=always '.shellescape(<q-args>), 1, | |
\ <bang>0 ? fzf#vim#with_preview('up:60%') | |
\ : fzf#vim#with_preview('right:50%:hidden', '?'), | |
\ <bang>0) | |
function! s:list_cmd() | |
let base = fnamemodify(expand('%'), ':h:.:S') | |
return base == '.' ? 'fd --type file --follow' : printf('fd --type file --follow | proximity-sort %s', shellescape(expand('%'))) | |
endfunction | |
command! -bang -nargs=? -complete=dir Files | |
\ call fzf#vim#files(<q-args>, {'source': s:list_cmd(), | |
\ 'options': '--tiebreak=index'}, <bang>0) | |
" Open new file adjacent to current file | |
nnoremap <leader>e :e <C-R>=expand("%:p:h") . "/" <CR> | |
" No arrow keys --- force yourself to use the home row | |
nnoremap <up> <nop> | |
nnoremap <down> <nop> | |
inoremap <up> <nop> | |
inoremap <down> <nop> | |
inoremap <left> <nop> | |
inoremap <right> <nop> | |
" Left and right can switch buffers | |
nnoremap <left> :bp<CR> | |
nnoremap <right> :bn<CR> | |
" Move by line | |
nnoremap j gj | |
nnoremap k gk | |
" 'Smart' nevigation | |
nmap <silent> E <Plug>(coc-diagnostic-prev) | |
nmap <silent> W <Plug>(coc-diagnostic-next) | |
nmap <silent> <leader>l <Plug>(coc-diagnostic-info) | |
nmap <silent> gd <Plug>(coc-definition) | |
nmap <silent> gy <Plug>(coc-type-definition) | |
nmap <silent> gi <Plug>(coc-implementation) | |
nmap <silent> gr <Plug>(coc-references) | |
" Use K to show documentation in preview window | |
nnoremap <silent> K :call <SID>show_documentation()<CR> | |
function! s:show_documentation() | |
if (index(['vim','help'], &filetype) >= 0) | |
execute 'h '.expand('<cword>') | |
else | |
call CocAction('doHover') | |
endif | |
endfunction | |
" <leader><leader> toggles between buffers | |
nnoremap <leader><leader> <c-^> | |
" Default indentation rules based on filetype | |
autocmd FileType javascript setlocal shiftwidth=2 softtabstop=2 expandtab | |
autocmd FileType typescript setlocal shiftwidth=2 softtabstop=2 expandtab | |
autocmd FileType typescriptreact setlocal shiftwidth=2 softtabstop=2 expandtab | |
" Prettier | |
command! -nargs=0 Prettier :CocCommand prettier.formatFile | |
" Golang organise imports on save | |
autocmd BufWritePre *.go :call CocAction('runCommand', 'editor.action.organizeImport') | |
" Disable tmux navigator when zooming the Vim pane | |
let g:tmux_navigator_disable_when_zoomed = 1 | |
" Open NerdTree with leader-n | |
map <leader>n :NERDTreeToggle<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment