Skip to content

Instantly share code, notes, and snippets.

@elhenro elhenro/.vimrc
Last active Nov 15, 2019

What would you like to do?
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 hidden
set ignorecase
set smartcase
set splitbelow
set splitright
set noshowmode
" hightlight similar words
" set hlsearch
"set incsearch
set grepprg=ag\ --vimgrep\ $*
set grepformat=%f:%l:%c:%m
set cpoptions=ces$
set cursorline
" hide lineNumbers background
highlight clear LineNr
" move cursor freely
set virtualedit=all
" if $TERM == "xterm-256color"
" set t_Co=256
" endif
" no swape file. disable annoying warning
set noswapfile
let mapleader = ","
imap jj <Esc>
cabb W w
cabb Q q
cabb Wq wq
cabb WQ wq
" 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 'maksimr/vim-jsbeautify'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'pangloss/vim-javascript'
Plug 'ptzz/lf.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'sickill/vim-pasta'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-surround'
Plug 'vim-scripts/Toggle'
Plug 'w0rp/ale'
Plug 'zxqfl/tabnine-vim'
Plug 'haya14busa/incsearch.vim'
Plug 'fxn/vim-monochrome'
Plug 'xolox/vim-misc'
Plug 'xolox/vim-colorscheme-switcher'
call plug#end()
" colorscheme hackerman
" colorscheme serape
" colorscheme midnight
" colorscheme pablo
" colorscheme monochrome
colorscheme monotone
" 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 = 1
let g:ale_sign_column_always = 0
let g:ale_linters = {'javascript': ['eslint'],}
let g:ale_fixers = {'javascript': ['eslint'],}
" git gutter colors
highlight GitGutterAdd ctermfg=green
highlight GitGutterChange ctermfg=yellow
highlight GitGutterDelete ctermfg=red
highlight GitGutterChangeDelete ctermfg=yellow
let g:gitgutter_sign_added = '🔸'
let g:gitgutter_sign_modified = '🔸'
let g:gitgutter_sign_removed = '🔹'
let g:gitgutter_sign_removed_first_line = '🔺'
let g:gitgutter_sign_modified_removed = '🔻'
nmap <leader>+ :GitGutterLineHighlightsToggle<CR>
nmap <leader>_ :GitGutterFold<CR>
" nmap ]h <Plug>(GitGutterNextHunk)
" nmap [h <Plug>(GitGutterPrevHunk)
nmap ]h :GitGutterNextHunk<CR>
nmap [h :GitGutterPrevHunk<CR>
" git blame toggler
function! s:ToggleBlame()
if &l:filetype ==# 'fugitiveblame'
nnoremap gb :call <SID>ToggleBlame()<CR>
" remove word hightlight when in insert mode
" autocmd InsertEnter * :let @/=""
" nmap <leader>/ :let @/=""<cr>
" rofi
" Strip the newline from the end of a string
function! Chomp(str)
return substitute(a:str, '\n$', '', '')
" Find a file and pass it to cmd
function! DmenuOpen(cmd)
let fname = Chomp(system("git ls-files | rofi -dmenu -i -l 20 -p " . a:cmd))
if empty(fname)
execute a:cmd . " " . fname
nmap <leader>r :call DmenuOpen("e")<cr>
nmap <leader>rb :call DmenuOpenBuffers("b")<cr>
nmap <leader>rv :call DmenuOpen("vsplit")<cr>
nmap <leader>rs :call DmenuOpen("split")<cr>
" js beautify shortcut
nmap <leader>jb :call JsBeautify()<cr>
" goyo
nmap <leader>gy :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!
let g:goyo_width = 99
" let g:goyo_height = 100
let g:goyo_margin_top = 0
let g:goyo_margin_bottom = 0
function! s:goyo_leave()
" Quit Vim if this is the only remaining buffer
" if b:quitting && len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
if b:quitting
if b:quitting_bang
autocmd! User GoyoEnter call <SID>goyo_enter()
autocmd! User GoyoLeave call <SID>goyo_leave()
" On window resize, if goyo is active, do <c-w>= to resize the window
autocmd VimResized * if exists('#goyo') | exe "normal \<c-w>=" | endif
" lf
" function! LF()
" let temp = tempname()
" exec 'silent !lf -selection-path=' . shellescape(temp)
" if !filereadable(temp)
" redraw!
" return
" endif
" let names = readfile(temp)
" if empty(names)
" redraw!
" return
" endif
" exec 'edit ' . fnameescape(names[0])
" for name in names[1:]
" exec 'argadd ' . fnameescape(name)
" endfor
" redraw!
" endfunction
" command! -bar LF call LF()
" nmap <leader>lf :LF<cr>
" nmap <leader>k :LF<cr>
" 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
let s:hidden_all = 0
set showmode
set ruler
set laststatus=2
set showcmd
" 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
" hide colorscheme background
" hi Normal guibg=NONE ctermbg=NONE
highlight Normal guibg=black guifg=white
set background=dark
" hide line number background and make less flashy
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE
" search in visual
vnoremap // y/<C-R>"<CR>
" nerdCommenter space delimiter // ,
let NERDSpaceDelims=1
" incsearch hightlight plugin
set hlsearch
map / <Plug>(incsearch-forward)
map ? <Plug>(incsearch-backward)
map g/ <Plug>(incsearch-stay)
let g:incsearch#auto_nohlsearch = 1
map n <Plug>(incsearch-nohl-n)
map N <Plug>(incsearch-nohl-N)
map * <Plug>(incsearch-nohl-*)
map # <Plug>(incsearch-nohl-#)
map g* <Plug>(incsearch-nohl-g*)
map g# <Plug>(incsearch-nohl-g#)
" replace under cursor
nnoremap <Leader>s :%s/\\<<C-r><C-w>\\>//gc<Left><Left><Left>
nnoremap <Leader>ss :%s/\\<<C-r><C-w>\\>//g<Left><Left>
" replace selection
vnoremap <C-r> "hy:%s/<C-r>h//gc<left><left><left>
noremap <Leader>v "hy:%s/<C-r>h//gc<left><left><left>
" hightlight open brackets
hi link MatchOpen Error
" automatically strip trailing spaces
autocmd BufWritePre *.js :%s/\s\+$//e
autocmd BufWritePre *.sh :%s/\s\+$//e
" cycle through colorschemes
nmap <Leader>q :NextColorScheme<CR>
" hide empty line ~s
highlight EndOfBuffer ctermfg=black ctermbg=black
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.