Last active
July 31, 2020 19:25
-
-
Save srcrip/f6989cc8a335365114468d4a69d1a790 to your computer and use it in GitHub Desktop.
My (pretty) simple Neovim config
This file contains 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
" Remappings and Commands {{{ | |
nnoremap <silent> <esc> :noh<cr><esc> | |
nnoremap <space>s :w<CR> | |
nnoremap gp `[v`] | |
nnoremap Q @q | |
nnoremap gj J | |
nnoremap <c-g> :let @+ = expand("%:p") . ":" . line(".") \| echo 'copied ' . @+ . ' to the clipboard.'<CR> | |
nnoremap == =ap | |
nmap <silent> } :<C-u>execute "keepjumps norm! " . v:count1 . "}"<CR> | |
nmap <silent> { :<C-u>execute "keepjumps norm! " . v:count1 . "{"<CR> | |
nnoremap J } | |
nnoremap K { | |
vnoremap J } | |
vnoremap K { | |
nnoremap j gj | |
nnoremap k gk | |
vnoremap < <gv | |
vnoremap > >gv | |
" nnoremap < << | |
" nnoremap > >> | |
nmap ; g; | |
nmap , g, | |
com! Wq :wq | |
com! WQ :wq | |
com! Vimrc :edit $MYVIMRC | |
"" }}} | |
call plug#begin() | |
"" Wiki {{{ | |
Plug 'vimwiki/vimwiki' | |
let g:vimwiki_list = [{'path': '~/wiki/', | |
\ 'syntax': 'markdown', 'ext': '.md'}] | |
"" }}} | |
"" Monokai Theme & Statusline {{{ | |
Plug 'crusoexia/vim-monokai' | |
let g:monokai_term_italic = 1 | |
let g:monokai_gui_italic = 1 | |
Plug 'rbong/vim-crystalline' | |
Plug 'gcavallanti/vim-noscrollbar' | |
"" }}} | |
"" Autocomplete {{{ | |
" Plug 'neovim/nvim-lsp' | |
Plug 'neoclide/coc.nvim', {'branch': 'release'} | |
Plug 'ajh17/VimCompletesMe' | |
"" }}} | |
"" Clipboard & Yanking {{{ | |
set clipboard=unnamed,unnamedplus | |
Plug 'svermeulen/vim-yoink' | |
let g:yoinkSyncNumberedRegisters = 1 | |
let g:yoinkIncludeDeleteOperations = 1 | |
nmap <c-p> <plug>(YoinkPostPasteSwapBack) | |
nmap <c-n> <plug>(YoinkPostPasteSwapForward) | |
nmap <c-=> <plug>(YoinkPostPasteToggleFormat) | |
nmap p <plug>(YoinkPaste_p) | |
nmap P <plug>(YoinkPaste_P) | |
nmap [y <plug>(YoinkRotateBack) | |
nmap ]y <plug>(YoinkRotateForward) | |
nmap y <plug>(YoinkYankPreserveCursorPosition) | |
nmap Y y$ | |
xmap y <plug>(YoinkYankPreserveCursorPosition) | |
inoremap <silent> <c-v> <c-o>P | |
"" }}} | |
"" Undo {{{ | |
Plug 'mbbill/undotree' | |
inoremap <C-z> <C-o>u | |
nmap U <C-r> | |
nnoremap <silent> <c-\> :UndotreeToggle<cr> | |
let g:undotree_WindowLayout = 4 | |
let g:undotree_SplitWidth = 25 | |
let g:undotree_SetFocusWhenToggle = 1 | |
let g:undotree_HelpLine = 0 | |
let g:undotree_HighlightChangedText = 0 | |
let g:undotree_ShortIndicators = 1 | |
set undofile | |
set undodir=~/.config/nvim/undo | |
set undolevels=10000 | |
set undoreload=10000 | |
"" }}} | |
"" tpope and other utilities {{{ | |
Plug 'tpope/vim-sensible' | |
Plug 'tpope/vim-endwise' | |
Plug 'tpope/vim-repeat' | |
Plug 'tpope/vim-eunuch' | |
Plug 'tpope/vim-rsi' | |
Plug 'tpope/vim-unimpaired' | |
Plug 'farmergreg/vim-lastplace' | |
Plug 'norcalli/nvim-colorizer.lua' | |
"" }}} | |
"" Surround and Align {{{ | |
Plug 'machakann/vim-sandwich' | |
Plug 'junegunn/vim-easy-align' | |
" Start interactive EasyAlign in visual mode (e.g. vipga) | |
xmap ga <Plug>(EasyAlign) | |
" Start interactive EasyAlign for a motion/text object (e.g. gaip) | |
nmap ga <Plug>(EasyAlign) | |
" }}} | |
"" Commenting and Auto close pairs {{{ | |
Plug 'tomtom/tcomment_vim' | |
Plug 'tmsvg/pear-tree' | |
let g:pear_tree_repeatable_expand=0 | |
"" }}} | |
"" Highlight {{{ | |
" This works on latest nvim | |
" augroup highlight_yank | |
" autocmd! | |
" autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank("IncSearch", 1000) | |
" augroup END | |
Plug 'machakann/vim-highlightedyank' | |
let g:highlightedyank_highlight_duration = 100 | |
"" }}} | |
"" File Managing {{{ | |
nmap <silent> - :Ranger<cr> | |
Plug 'francoiscabrol/ranger.vim' | |
let g:ranger_replace_netrw = 1 | |
"" Used to close file manager | |
"" Could replace sayonara? | |
Plug 'rbgrouleff/bclose.vim' | |
" }}} | |
"" Substitution & Abreviation {{{ | |
Plug 'svermeulen/vim-subversive' | |
nmap s <plug>(SubversiveSubstitute) | |
nmap ss <plug>(SubversiveSubstituteLine) | |
nmap S <plug>(SubversiveSubstituteToEndOfLine) | |
xmap s <plug>(SubversiveSubstitute) | |
xmap p <plug>(SubversiveSubstitute) | |
xmap P <plug>(SubversiveSubstitute) | |
"" }}} | |
"" Git {{{ | |
Plug 'airblade/vim-gitgutter' | |
Plug 'tpope/vim-fugitive' | |
com! Branches :te echo $(git branch \| fzf +m) | |
au FileType gitcommit execute "normal! O" | startinsert | |
nnoremap <silent> <space>gc :Commits!<CR> | |
nnoremap <silent> <space>gd :Gdiff<CR> | |
nnoremap <silent> <space>gb :Gblame<CR> | |
nnoremap <silent> <space>gL :Glog --author=sevensidedmarble <CR> | |
nnoremap <silent> <space>gl :Glog<CR> | |
nnoremap <space>gP :Git push origin HEAD<cr> | |
nnoremap <silent> <space>gg :Gstatus<CR> | |
" Update sign column every quarter second | |
set updatetime=250 | |
"" }}} | |
"" Buffers {{{ | |
Plug 'mhinz/vim-sayonara', { 'on': 'Sayonara' } | |
nnoremap <silent> <c-x><c-k> :Sayonara!<CR> | |
nnoremap <silent> <c-h> :bp<CR> | |
nnoremap <silent> <c-l> :bn<CR> | |
nmap <silent> <c-x><c-s> :w<CR> | |
nmap <silent> <c-x><c-b> :Buffers<CR> | |
nmap <silent> <c-x><b> :Buffers<CR> | |
"" }}} | |
"" Languages {{{ | |
Plug 'sheerun/vim-polyglot' | |
" Ruby on Rails | |
" Plug 'tpope/vim-rails' | |
" Plug 'tpope/vim-rake' | |
" Plug 'ngmy/vim-rubocop', { 'on': 'RuboCop' } | |
" Plug 'ngmy/vim-rubocop', { 'on': 'RuboCop' } | |
"" }}} | |
"" FZF {{{ | |
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } | |
Plug 'junegunn/fzf.vim' | |
function! s:GetVisualSelection() | |
let [line_start, column_start] = getpos("'<")[1:2] | |
let [line_end, column_end] = getpos("'>")[1:2] | |
let lines = getline(line_start, line_end) | |
if len(lines) == 0 | |
return '' | |
endif | |
let offset = &selection ==# 'exclusive' ? 2 : 1 | |
let lines[-1] = lines[-1][:column_end - offset] | |
let lines[0] = lines[0][column_start - 1:] | |
return join(lines, "\n") | |
endfunction | |
let s:rg_common = 'rg --column --line-number --no-heading --color=always ' . | |
\ '--smart-case ' | |
command! -bang -nargs=* Rg | |
\ call fzf#vim#grep( | |
\ s:rg_common . '--fixed-strings ' . shellescape(<q-args>), | |
\ 1, | |
\ fzf#vim#with_preview( | |
\ { 'options': '--delimiter : --nth 4..' }, 'right:50%'), | |
\ <bang>0) | |
command! -bang -nargs=* -complete=dir Rgd | |
\ call fzf#vim#grep( | |
\ s:rg_common . '--fixed-strings ' . shellescape(''), | |
\ 1, | |
\ fzf#vim#with_preview( | |
\ { 'dir': fnamemodify(expand(<q-args>), ':p:h'), | |
\ 'options': '--delimiter : --nth 4..' }, | |
\ 'right:50%'), | |
\ <bang>0) | |
command! -bang -nargs=* Rgr | |
\ call fzf#vim#grep( | |
\ s:rg_common . shellescape(<q-args>), | |
\ 1, | |
\ fzf#vim#with_preview({ 'options': '--delimiter : --nth 4..' }, | |
\ 'right:50%'), | |
\ <bang>0) | |
nnoremap <silent> <Space>/ :Rg!<CR> | |
vnoremap <silent> <Space>/ :<C-U>Rg!<Space><C-R>=<SID>GetVisualSelection()<CR><CR> | |
nnoremap <silent> <Space>hh :Helptags!<CR> | |
nnoremap <silent> <Space>fr :History!<CR> | |
" nnoremap <silent> <Space>// :Rg!<CR> | |
" nnoremap <silent> <Space>ff :Files!<CR> | |
nnoremap <silent> <Space><Space> :Files!<CR> | |
"" }}} | |
"" Linting & ALE {{{ | |
Plug 'dense-analysis/ale' | |
let g:ale_linter_aliases = {'svelte': ['css', 'javascript']} | |
let g:ale_linters = {'svelte': ['stylelint', 'eslint']} | |
let g:ale_fixers = { | |
\ 'svelte': ['eslint', 'prettier', 'prettier_standard'], | |
\ 'javascript': ['prettier'] | |
\ } | |
"" }}} | |
call plug#end() | |
"" Colors {{{ | |
colorscheme monokai | |
set termguicolors | |
lua require'colorizer'.setup() | |
"" }}} | |
"" Settings {{{ | |
set timeoutlen=550 ttimeoutlen=0 | |
let mapleader = " " | |
filetype plugin indent on | |
syntax enable | |
set hidden | |
set noswapfile | |
set title | |
set mouse=a | |
set scrolloff=999 | |
set number | |
set expandtab | |
set tabstop=2 | |
set shiftwidth=2 | |
set splitbelow | |
set splitright | |
set cursorline | |
set ignorecase | |
set smartindent | |
set virtualedit=block | |
set lazyredraw | |
set whichwrap+=<,>,h,l,[,] | |
set autowrite | |
set autoread | |
set autowriteall | |
set gdefault | |
set inccommand=split | |
set grepprg=rg\ --no-heading\ --vimgrep | |
set grepformat=%f:%l:%c:%m | |
set synmaxcol=1500 | |
set nobackup | |
set autoindent | |
set nowritebackup | |
set signcolumn=yes | |
"" }}} | |
"" StatusLine and TabLine {{{ | |
" set tabline=%!crystalline#bufferline() | |
" set showtabline=2 | |
function! LinterStatus() abort | |
let l:counts = ale#statusline#Count(bufnr('')) | |
let l:all_errors = l:counts.error + l:counts.style_error | |
let l:all_non_errors = l:counts.total - l:all_errors | |
return l:counts.total == 0 ? 'it just works ¯\_(ツ)_/¯' : printf( | |
\ 'Warn:%d Error:%d', | |
\ l:all_non_errors, | |
\ l:all_errors | |
\) | |
endfunction | |
function! TabLine() | |
let l:vimlabel = has('nvim') ? 'NVIM IS BEST VIM ' : 'VIM IS OK ' | |
return crystalline#bufferline(2, len(l:vimlabel), 1) . '%=%#CrystallineTab# ' . l:vimlabel | |
endfunction | |
let g:crystalline_tabline_fn = 'TabLine' | |
set showtabline=2 | |
function! StatusLine(...) | |
return crystalline#mode() . crystalline#right_mode_sep('') | |
\ . ' %f%h%w%m%r ' . crystalline#right_sep('', 'Fill') . ' %{fugitive#head()} %= %{LinterStatus()} ' | |
\ . crystalline#left_sep('', 'Fill') . ' %{&ft} col:%3c %{noscrollbar#statusline()} ' | |
endfunction | |
let g:crystalline_enable_sep = 1 | |
let g:crystalline_statusline_fn = 'StatusLine' | |
let g:crystalline_theme = 'default' | |
set laststatus=2 | |
"" }}} | |
"" Highlight trailing whitespace {{{ | |
function! s:MatchExtraWhitespace(enabled) | |
match ExtraWhitespace /\s\+$/ | |
endfunction | |
highlight link ExtraWhitespace Error | |
augroup ExtraWhitespace | |
autocmd! | |
autocmd BufWinEnter * call s:MatchExtraWhitespace(1) | |
autocmd FileType * call s:MatchExtraWhitespace(1) | |
autocmd InsertEnter * call s:MatchExtraWhitespace(0) | |
autocmd InsertLeave * call s:MatchExtraWhitespace(1) | |
autocmd BufWinLeave * call clearmatches() | |
augroup END | |
"" }}} | |
"" Specific FileType stuff {{{ | |
augroup TextFormatting | |
autocmd! | |
autocmd FileType vim | |
\ setlocal fdm=marker foldlevel=0 | |
augroup END | |
" Open help windows vertically | |
autocmd FileType help wincmd L | |
"" }}} | |
"" Folding {{{ | |
hi Folded guibg=#272822 guifg=#ffd866 | |
set foldlevel=99 | |
set foldnestmax=4 | |
set fdm=syntax | |
function! MyFoldText() | |
let line = getline(v:foldstart) | |
let nucolwidth = &fdc + &number * &numberwidth | |
let windowwidth = winwidth(0) - nucolwidth - 7 | |
let foldedlinecount = v:foldend - v:foldstart | |
" expand tabs into spaces | |
let onetab = strpart(' ', 0, &tabstop) | |
let line = substitute(line, '\t', onetab, 'g') | |
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) | |
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) | |
return line . ' ⸬' . repeat(" ",fillcharcount) . foldedlinecount . ' ⸬ ' | |
endfunction | |
set foldtext=MyFoldText() | |
"" }}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment