Skip to content

Instantly share code, notes, and snippets.

@elhenro
Last active January 22, 2021 16:33
Show Gist options
  • Save elhenro/aa32db7aab49c91e1157081e0e002991 to your computer and use it in GitHub Desktop.
Save elhenro/aa32db7aab49c91e1157081e0e002991 to your computer and use it in GitHub Desktop.
elhenro vimrc
set encoding=utf-8
set expandtab
set shiftwidth=2
set tabstop=2
set mouse=a
set number
set autoread
set diffopt+=iwhite
set nocompatible
set hidden
set ignorecase
set smartcase
set splitbelow
set splitright
set noshowmode
set hlsearch
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
set cpoptions=ces$
set cursorline
set ruler
" move cursor freely
set virtualedit=all
" if $TERM == "xterm-256color"
" set t_Co=256
" endif
set showtabline=0
set noswapfile
let mapleader = ","
imap jj <Esc>
cabb W w
cabb Q q
cabb Wq wq
cabb WQ wq
cabb E e
" easier split navigation
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" toggle numbers
nmap <leader>nu :set nu!<cr>
" block arrow keys
noremap <Up> <NOP>
noremap <Down> <NOP>
noremap <Left> <NOP>
noremap <Right> <NOP>
map <Esc><Esc> :w<CR>
nmap <leader>nw :set wrap!<cr>
call plug#begin('~/.vim/plugged')
" Plug 'airblade/vim-gitgutter'
Plug 'eslint/eslint'
Plug 'isruslan/vim-es6'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/goyo.vim'
Plug 'pangloss/vim-javascript'
Plug 'leafgarland/typescript-vim'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'HerringtonDarkholme/yats.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'tpope/vim-fugitive'
Plug 'rbong/vim-flog'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-unimpaired'
Plug 'dense-analysis/ale'
Plug 'vimwiki/vimwiki'
Plug 'tpope/vim-repeat'
Plug 'jamessan/vim-gnupg'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'maksimr/vim-jsbeautify'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'alok/notational-fzf-vim'
Plug 'wesQ3/vim-windowswap'
Plug 'preservim/nerdtree'
Plug 'ptzz/lf.vim'
if has('nvim') || has('patch-8.0.902')
Plug 'mhinz/vim-signify'
else
Plug 'mhinz/vim-signify', { 'branch': 'legacy' }
endif
Plug 'tpope/vim-vinegar',
Plug 'puremourning/vimspector'
Plug 'tyru/skk.vim'
call plug#end()
" ale
let g:ale_sign_error = '🔴'
let g:ale_sign_warning = '🟡'
highlight ALEErrorSign ctermbg=NONE ctermfg=red
highlight ALEWarningSign ctermbg=NONE ctermfg=yellow
let g:ale_fix_on_save = 1
let g:airline#extensions#ale#enabled = 0
let g:ale_sign_column_always = 1
let g:ale_linters = {'javascript': ['eslint'],}
let g:ale_fixers = {'javascript': ['eslint'],}
let b:ale_linters = {'javascript': ['prettier', 'eslint']}
" ale navigate between erorrs quickly
nmap <silent> <Leader>en <Plug>(ale_previous_wrap)
nmap <silent> <Leader>ep <Plug>(ale_next_wrap)
" git gutter colors
"highlight GitGutterAdd ctermfg=green
"highlight GitGutterChange ctermfg=yellow
"highlight GitGutterDelete ctermfg=red
"highlight GitGutterChangeDelete ctermfg=yellow
"nmap <leader>+ :GitGutterLineHighlightsToggle<CR>
"nmap <leader>_ :GitGutterFold<CR>
"nmap ]h :GitGutterNextHunk<CR>
"nmap [h :GitGutterPrevHunk<CR>
"nmap ,gn :GitGutterNextHunk<CR>
"nmap ,gp :GitGutterPrevHunk<CR>
"nmap ,gs :GitGutterStageHunk<CR>
"nmap ,gu :GitGutterUndoHunk<CR>
nmap ,gu :SignifyHunkUndo<CR>
function! s:ToggleBlame()
if &l:filetype ==# 'fugitiveblame'
close
else
Gblame
endif
endfunction
nnoremap gb :call <SID>ToggleBlame()<CR>
" js beautify shortcut
nmap <leader>jb :call JsBeautify()<cr>
" goyo
nmap <leader>gy :Goyo 120x100%<cr>
nmap <leader>gyy :Goyo<cr>
" autocmd VimEnter * Goyo " autostart goyo
" ensure to leave, even with Goyo open
function! s:goyo_enter()
let b:quitting = 0
let b:quitting_bang = 0
autocmd QuitPre <buffer> let b:quitting = 1
cabbrev <buffer> q! let b:quitting_bang = 1 <bar> q!
endfunction
let g:goyo_margin_top = 0
let g:goyo_margin_bottom = 0
function! s:goyo_leave()
" quit if only remaining buffer
" if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting
if b:quitting_bang
qa!
else
qa
endif
endif
endfunction
autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()
" resize window
autocmd VimResized * if exists('#goyo') | exe "normal \<c-w>=" | endif
" insert space in normal mode
nnoremap <space> i<space><esc>
let s:hidden_all = 0
function! ToggleHiddenAll()
if s:hidden_all == 0
let s:hidden_all = 1
set noshowmode
set noruler
" set laststatus=0
set noshowcmd
else
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
endif
endfunction
" hide statusline
autocmd VimEnter * call ToggleHiddenAll()
nmap <Leader>ha :call ToggleHiddenAll()<CR>
" ** fzf shortcuts
"" fzf search files
" nmap <Leader>f :Files<CR>
nmap <Leader>F :Files<CR>
nmap <leader>z :Rg<cr>
" fzf search buffers
nmap <Leader>b :Buffers<CR>
" " fzf search file history
nmap <Leader>h :History<CR>
" " fzf search help pages
nmap <Leader>H :Helptags!<CR>
" " fzf search commands
nmap <Leader>C :Commands<CR>
" " fzf search history
nmap <Leader>: :History:<CR>
" fzf search keymappings
nmap <Leader>M :Maps<CR>
" fzf search gitfiles
nmap <leader>p :call fzf#vim#gitfiles('', fzf#vim#with_preview('right'))<CR>
" ctrl+g ripgrep
nnoremap <C-g> :Rg<Cr>
nnoremap <C-f> :Ag<Cr>
" format json files
" com! FormatJSON %!python -m json.tool
" nmap <Leader>fj :FormatJSON<CR>
" hide cursorline
hi clear CursorLine
augroup CLClear
autocmd! ColorScheme * hi clear CursorLine
augroup END
hi CursorLineNR cterm=bold
augroup CLNRSet
autocmd! ColorScheme * hi CursorLineNR cterm=bold
augroup END
" nerdCommenter space delimit
let NERDSpaceDelims=1
" hightlight open brackets
hi link MatchOpen Error
" automatically strip trailing spaces
autocmd BufWritePre *.js :%s/\s\+$//e
autocmd BufWritePre *.sh :%s/\s\+$//e
" hide empty line ~s
"highlight EndOfBuffer ctermfg=black ctermbg=black
let g:ycm_path_to_python_interpreter = '/usr/bin/python'
" vimwiki
set nocompatible
filetype plugin on
syntax on
let g:vimwiki_list = [{'path': '~/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]
"au FileType vimwiki set syntax=markdown.pandoc
"let g:pandoc#filetypes#pandoc_markdown = 0
"let g:vimwiki_ext2syntax = {'.md': 'markdown'}
"let g:vimwiki_folding='expr'
let g:vimwiki_folding=''
nmap <Leader>id :IndentGuidesToggle<CR>
" hide ~ on blank lines
"nmap <F7> :hi EndOfBuffer ctermfg=black ctermbg=black<CR>
" switch buffer from terminal split
tnoremap <leader>b <C-w>:Buffers<CR>
" ,tt to open terminal pane
nmap <Leader>tt :ter ++curwin<CR>
" hide split-bar
autocmd VimEnter highlight StatusLine ctermfg=bg ctermbg=bg guibg=bg guifg=bg
autocmd VimEnter highlight StatusLineNC ctermfg=bg ctermbg=bg guibg=bg guifg=bg
" also hide '|' char in vertical split-bar
set fillchars+=vert:\
" autosave buffer on focus loss
augroup AutoWrite
autocmd! BufLeave * :update
augroup END
" quicksave stroke
noremap <Leader><Leader> :update<CR>
" insert date
nmap <Leader>da i<C-R>=strftime("%Y-%m-%d %a %I:%M %p")<CR><Esc>
highlight clear LineNr
"
" gpg encr
let g:GPGPreferArmor=1
let g:GPGDefaultRecipients=["<GPG_KEY_HERE>"]
let r_indent_align_args = 0
" colo gruvbox
" colo gruvbox-material
colo gruvbox
" coc
set hidden
set nobackup
set nowritebackup
set cmdheight=2
set updatetime=300
set shortmess+=c
set signcolumn=yes
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
"syntax sync minlines=10000
" signify
" default updatetime 4000ms is not good for async update
"set updatetime=100
"highlight SignColumn ctermbg=black
" Center screen on search next/prev
nnoremap n nzz
nnoremap N Nzz
nnoremap { {zz
nnoremap } }zz
" less padding
set noshowmode
set noruler
set laststatus=0
set noshowcmd
set cmdheight=1
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
let g:netrw_banner = 0
"let g:netrw_browse_split = 2
let g:netrw_browse_split = 4
" open newtr as project drawer
nmap <Leader>mm :Vexplore<cr>
" resize shortcuts
" resize big steps with leader
nnoremap <silent> <Leader>+ :exe "vertical resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> <Leader>- :exe "vertical resize " . (winheight(0) * 2/3)<CR>
" resize small steps w + and - directly
if bufwinnr(1)
map + <C-W>+
map - <C-W>-
endif
" remove black lines bug in kitty
let &t_ut=''
" coc snippets
imap <C-l> <Plug>(coc-snippets-expand)
inoremap <silent><expr> <TAB>
\ pumvisible() ? coc#_select_confirm() :
\ coc#expandableOrJumpable() ? "\<C-r>=coc#rpc#request('doKeymap', ['snippets-expand-jump',''])\<CR>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
let g:coc_snippet_next = '<tab>'
" count * word occurences
map ,* *<C-O>:%s///gn<CR>
let g:nv_search_paths = ['~/vimwiki/']
let g:nv_default_extension = '.md'
let g:nv_create_note_key = 'ctrl-x'
let g:nv_ignore_pattern = ['*.gpg']
let g:nv_create_note_window = 'edit'
nmap <Leader>nv :NV!<cr>
" fim fugitive shortcuts
nmap <Leader>gd :Gdiff<cr>
nmap <Leader>dp :diffput<cr>
nmap <Leader>gs :Gstatus<cr>
nmap <Leader>gf :Flog<cr>
nmap <Leader>co :Git checkout
nmap <Leader>gp :Git pull<cr>
nmap <Leader>gc ::Gcommit -v -q<CR>
" do not resize other split panes on close
set noea
" window swap
let g:windowswap_map_keys = 0 "prevent default bindings
nnoremap <silent> <leader>yw :call WindowSwap#MarkWindowSwap()<CR>
nnoremap <silent> <leader>pw :call WindowSwap#DoWindowSwap()<CR>
nnoremap <silent> <leader>ws :call WindowSwap#EasyWindowSwap()<CR>
"replace all occurences of word under cursor
nnoremap <Leader>s :%s/\<<C-r><C-w>\>/
set laststatus=2
" coc typescript
let g:coc_global_extensions = [ 'coc-tsserver' ]
" let g:typescript_compiler_binary = 'tsc'
let g:typescript_compiler_options = '--lib es6'
" GoTo code navigation.
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)
"nerdtree
nmap <silent> <Leader>ne :NERDTreeToggle<CR>
"japanese
let g:skk_initial_mode = 'hira'
let g:skk_script = '~/vim/skk/skk.vim'
set completeopt=menuone,preview
set thesaurus=~/vim/skk/skk-jisyo-utf-8.l
function! ToogleMode()
if 'hira' ==# g:skk_initial_mode
let g:skk_initial_mode = 'kata'
else
let g:skk_initial_mode = 'hira'
endif
execute "source " . g:skk_script
endfunction
set laststatus=2
" typescript files fix syntax hightlighting
autocmd BufNewFile,BufRead *.ts set syntax=typescript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment