Skip to content

Instantly share code, notes, and snippets.

@imvaskii
Last active April 19, 2020 13:03
Show Gist options
  • Save imvaskii/3adfb391b2bffafcebb0d764a4694e62 to your computer and use it in GitHub Desktop.
Save imvaskii/3adfb391b2bffafcebb0d764a4694e62 to your computer and use it in GitHub Desktop.
set shell=/usr/bin/bash
if &compatible
set nocompatible
endif
" Declare the general config group for autocommand
if has("autocmd")
augroup vimrc
autocmd!
" Creates parent dir if not exists.
autocmd BufWritePre * :silent !mkdir -p %:p:h
autocmd BufWritePre * :silent Neoformat
autocmd! BufWritePost,BufEnter * Neomake
autocmd BufWritePost,TextChanged,TextChangedI * call lightline#update()
let excludeFile = ['md']
autocmd FileType * if index(excludeFile, &ft)< 0 | setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
augroup numbertoggle
autocmd!
autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber
augroup END
" Format JSON content.
augroup json
" autocmd BufWritePre *.json :%!python -m json.tool<CR>
augroup END
end
" ctags
if executable("ctags")
command! MakeTags !ctags -R .
else
command! MakeTags !exctags -R .
endif
" mdcat
if executable("mdcat")
command! Mdcat !mdcat % | less -R
endif
" +----------------+
" | general config |
" +----------------+
" used for autocomplete when adding dash
set iskeyword+=\-
" set the directory where the swap file will be saved
set backupdir=~/.config/nvim/backup//
set directory=~/.config/nvim/swap//
" save undo trees in files
set undofile
set undodir=~/.config/nvim/undo//
" set line number
" set number
" relative / hybrid line number switch
set number relativenumber
" the copy goes to the clipboard
set clipboard+=unnamedplus
" use 4 spaces instead of tab (to replace existing tab use :retab)
" copy indent from current line when starting a new line
set autoindent
set expandtab
set tabstop=4
set softtabstop=4
set shiftwidth=4
" Save session
exec 'nnoremap <Leader>ss :mksession! ~/.config/nvim/sessions/*.vim<C-D><BS><BS><BS><BS><BS>'
" Reload session
exec 'nnoremap <Leader>sl :so ~/.config/nvim/sessions/*.vim<C-D><BS><BS><BS><BS><BS>'
" when at 3 spaces, and I hit > ... go to 4, not 7
set shiftround
" number of undo saved in memory
set undolevels=10000 " How many undos
set undoreload=10000 " number of lines to save for undo
" Use case insensitive search, except when using capital letters
set ignorecase
set smartcase
" set list
set list listchars=tab:\┆\ ,trail:·,nbsp:±
" doesn't prompt a warning when opening a file
" and the current file was written but not saved
" https://nvie.com/posts/how-i-boosted-my-vim/#change-vim-behaviour
set hidden
" doesn't display the mode status
set noshowmode
" Keep cursor more in middle when scrolling down / up
" set scrolloff=999
" no swap file! This is just annoying
set noswapfile
" write automatically when quitting buffer
set autowrite
" Fold related
set foldlevelstart=0 " Start with all folds closed
" Set foldtext
set foldtext=general#FoldText()
" set Foldmethod.
" set foldmethod=indent
set foldmethod=manual
" Show the substitution LIVE
" set inccommand=nosplit
" Better ex autocompletion
" set wildmode=list:longest,full
set wildmenu
set wildoptions+=pum
" Transparency for floating window. 0 disabled, 100 full transparent.
set winblend=0
" Pseudo transparency for popmup menu
set pumblend=0
" set signcolumn=yes:2
" Show the substitution LIVE
set inccommand=nosplit
" for vertical pane in git diff tool
set diffopt+=vertical
" Popup menu color
highlight Pmenu guibg='00010a' guifg=white
" enable the mouse - who needs a mouse??
" set mouse=a
" Enable Emoji
set emoji
" performance tweaks
set lazyredraw
let vimplug_path=expand('~/.config/nvim/autoload/plug.vim')
" Vim-Plug installation
if ! filereadable(vimplug_path)
if ! executable("curl")
echoerr "ERROR: curl not installed."
endif
echo "Installing Vim-Plug...\n"
silent exec "!\curl -fLo ". vimplug_path ." \
--create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
autocmd VimEnter *PlugInstall
endif
" +----------------+
" | install plugin |
" +----------------+
call plug#begin('~/.config/nvim/plugged')
" snippet engine + snippets
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'luochen1990/rainbow'
" vifm is love ❤
Plug 'vifm/vifm.vim'
" Tender colors
Plug 'jacoborus/tender.vim'
" Devicons
Plug 'ryanoasis/vim-devicons'
" Vim smooth scrolling.
Plug 'psliwka/vim-smoothie'
" Autopairs
Plug 'jiangmiao/auto-pairs'
" nmap with message Multiple cursors
Plug 'terryma/vim-multiple-cursors'
" vim todo list.
Plug 'aserebryakov/vim-todo-lists'
" search string in folders.
Plug 'mileszs/ack.vim'
" Save vim sessions.
Plug 'tpope/vim-obsession'
" wrapper for git.
Plug 'tpope/vim-fugitive'
" Git branch: a fugitive extension fro git branch.
Plug 'sodapopcan/vim-twiggy'
" display git diff in the left gutter
Plug 'mhinz/vim-signify'
" surrounding text objects with whatever you want (paranthesis, quotes, html tags...)
Plug 'tpope/vim-surround'
" the . command can repeat whatever you want!
" http://vimcasts.org/episodes/creating-repeatable-mappings-with-repeat-vim/
Plug 'tpope/vim-repeat'
" Keystroke to comment automatically depending on the file you're in
Plug 'tpope/vim-commentary'
" Highlight briefly every yank text
Plug 'machakann/vim-highlightedyank'
" Colors for i3 config file
Plug 'PotatoesMaster/i3-vim-syntax', {'for': '~/.config/i3/config'}
" Match more stuff with % (html tag, LaTeX...)
Plug 'andymass/vim-matchup'
" Syntax highlight and stuff.
Plug 'neomake/neomake'
" camel case motion
" Plug 'chaoren/vim-wordmotion'
" Vim easy motion.
" eg: \\s - to search for a char.
Plug 'easymotion/vim-easymotion'
" Formatting code
Plug 'sbdchd/neoformat'
"Editorconfig
Plug 'editorconfig/editorconfig-vim'
" golang development
Plug 'fatih/vim-go', {'for': 'go'} " general plugin
" Plug 'godoctor/godoctor.vim', {'for': 'go'} " refactoring
Plug 'sebdah/vim-delve', {'for': 'go'} " debugger
" Align plugin
Plug 'junegunn/vim-easy-align'
" nginx syntax colors
" Plug 'chr4/nginx.vim'
" php
Plug 'joonty/vdebug'
" Add tmux completion for COC
" Plug 'wellle/tmux-complete.vim'
Plug 'benmills/vimux'
Plug 'benmills/vimux-golang'
" autocompletion.
Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'Shougo/echodoc.vim'
" outliner
Plug 'majutsushi/tagbar'
Plug 'liuchengxu/vista.vim'
" Nerdtree + modifications
Plug 'scrooloose/nerdtree', {'on': ['NERDTreeToggle', 'NERDTreeFind']}
" status bar
Plug 'itchyny/lightline.vim'
" lightline neomake status
Plug 'sinetoami/lightline-neomake'
" Undo tree
Plug 'simnalamburt/vim-mundo'
" registers
Plug 'bfredl/nvim-miniyank'
"display the result when searching
Plug 'henrik/vim-indexed-search'
" fzf - poweful fuzzy finder
Plug '${HOME}/.fzf/bin/fzf' " ┐
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' } " │ fzf
" display the hexadecimal colors - useful for css and color config
Plug 'ap/vim-css-color'
" Split arrays in PHP / struct in Go / other things
Plug 'AndrewRadev/splitjoin.vim'
" Better CSV file view.
Plug 'chrisbra/csv.vim', { 'for': '**/*.csv' }
" cmus player api handler in vim
Plug 'azadkuh/vim-cmus'
" similar to emacs Magit.
Plug 'jreybert/vimagit'
" Gruvbox theme.
Plug 'morhetz/gruvbox'
" Plug 'sainnhe/gruvbox-material'
" vim web-api & gist
Plug 'mattn/webapi-vim'
Plug 'mattn/gist-vim'
" Groovy
Plug 'vim-scripts/groovy.vim', { 'for': '**/*.groovy' }
" Buffer manger
Plug 'pacha/vem-tabline'
Plug 'DrCracket/painless-digraph'
call plug#end()
"-----------------------------------------------------------------
" Rainbox parens.
"-----------------------------------------------------------------
let g:rainbow_active=1
"-----------------------------------------------------------------
" Theme
"-----------------------------------------------------------------
" colorscheme
" colo tender
syntax enable
colo gruvbox
"-----------------------------------------------------------------
if (has("termguicolors"))
set termguicolors
endif
" For Neovim 0.1.3 and 0.1.4
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
" Transparent background
hi Normal ctermfg=White ctermbg=Black guibg=NONE
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" Gruvbox material colorscheme
"-----------------------------------------------------------------
" set termguicolors
" colo gruvbox-material
let g:gruvbox_material_background='hard'
let g:gruvbox_material_transparent_background=1
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" NERDTree Config.
"-----------------------------------------------------------------
let g:NERDTreeShowLineNumbers=0
let g:webdevicons_enable_nerdtree = 0
let g:WebDevIconsNerdTreeAfterGlyphPadding = ' '
let g:webdevicons_conceal_nerdtree_brackets = 1
let g:WebDevIconsUnicodeDecorateFolderNodes = 1
let g:DevIconsEnableFoldersOpenClose = 1
let g:WebDevIconsNerdTreeGitPluginForceVAlign = 1
if exists('g:loaded_webdevicons')
call webdevicons#refresh()
endif
" NERDTreeToggle
nmap <silent><leader>k :NERDTreeToggle<CR> :echomsg "NERDTreeToggle"<CR>
" NERDTree Reveal file.
nmap <silent><leader>rk :NERDTreeFind<CR>
"-----------------------------------------------------------------
let g:gist_show_private = 1
"-----------------------------------------------------------------
" Magit cofigs.
"-----------------------------------------------------------------
let g:magit_show_magit_mapping='mg'
"-----------------------------------------------------------------
" vim-go configs.
"-----------------------------------------------------------------
set splitbelow
let g:go_list_type = "quickfix"
let g:go_term_enabled = 1
let g:go_term_mode = "split"
let g:go_term_height= 10
" let g:go_term_width= 30
let g:go_fmt_command = "goimports" " Replaces gofmt.
let g:go_auto_type_info = 1
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" Vdebug options.
"-----------------------------------------------------------------
" GlobalVariables: [[[1
" IndentCont: indent count when type <CR> and then \
let g:vim_indent_cont = 2
" QuickfixHeight:
let g:quickfix_height = 9
"-----------------------------------------------------------------
"
"-----------------------------------------------------------------
" vim-easy-align
"-----------------------------------------------------------------
" Align GitHub-flavored Markdown tables
" au FileType markdown vmap <Leader><Bslash> :EasyAlign*<Bar><Enter>
" 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)
"-----------------------------------------------------------------
" Python Configs.
"-----------------------------------------------------------------
if exists($VIRTUAL_ENV)
if filereadable("$VIRTUAL_ENV/bin/python2")
let g:python_host_prog = "$VIRTUAL_ENV/bin/python2"
endif
if filereadable("$VIRTUAL_ENV/bin/python3")
let g:python3_host_prog = "$VIRTUAL_ENV/bin/python3"
endif
else
let g:python_host_prog = "$VIRTUAL_ENV/bin/python2"
let g:python3_host_prog = "$VIRTUAL_ENV/bin/python3"
endif
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" Ruby
"-----------------------------------------------------------------
let g:ruby_host_prog = '/usr/bin/ruby'
let g:coc_node_path = '/usr/bin/node'
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" COC configs.
"-----------------------------------------------------------------
" list extensions
let g:coc_global_extensions = [
\ 'coc-lists',
\ 'coc-prettier',
\ 'coc-eslint',
\ 'coc-snippets',
\ 'coc-emmet',
\ 'coc-yank',
\ 'coc-highlight',
\ 'coc-tsserver',
\ 'coc-python',
\ 'coc-html',
\ 'coc-json',
\ 'coc-yaml',
\ 'coc-markdownlint',
\ 'coc-css',
\ 'coc-sh',
\ 'coc-go',
\ 'coc-gocode',
\ 'coc-phpls',
\ 'coc-omni',
\ 'coc-tag',
\ 'coc-ultisnips',
\ 'coc-syntax',
\ 'coc-vimlsp',
\]
"-----------------------------------------------------------------
"---------------------------------------------------------------
" tagbar config.
"---------------------------------------------------------------
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
"---------------------------------------------------------------
"---------------------------------------------------------------
" TODO list config.
"---------------------------------------------------------------
let g:VimTodoListsDatesEnabled =1
let g:VimTodoListsDatesFormat = "%a %b, %Y"
"---------------------------------------------------------------
"---------------------------------------------------------------
" Lang server options.
"---------------------------------------------------------------
" let g:LanguageClient_serverCommands = { 'sh': ['bash-language-server', 'start'] }
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" Vdebug options.
"-----------------------------------------------------------------
let g:vdebug_options = {
\ 'port' : 9010,
\ 'timeout' : 20,
\ 'server' : '',
\ 'on_close' : 'stop',
\ 'break_on_open' : 0,
\ 'ide_key' : 'PHP_XDEBUG',
\ 'debug_window_level' : 0,
\ 'debug_file_level' : 0,
\ 'debug_file' : '',
\ 'path_maps' : { "/var/www/html/web": "/home/bhaskark/Sites/cre-news-reskin/web"},
\ 'watch_window_style' : 'expanded',
\ 'marker_default' : '⬦',
\ 'marker_closed_tree' : '▸',
\ 'marker_open_tree' : '▾',
\ 'sign_breakpoint' : '▷',
\ 'sign_current' : '▶',
\ 'continuous_mode' : 1
\}
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" Light line configs.
"-----------------------------------------------------------------
" Lightline color
let g:lightline = {
\ 'enable': { 'tabline': 0 },
\ 'active': {
\ 'left': [
\ [ 'mode', 'paste' ],
\ [ 'gitbranch', 'readonly', 'filename', 'modified' ]
\ ],
\ 'right': [
\ [ 'syntastic', 'lineinfo' ],
\ [ 'percent' ],
\ [ 'fileformat', 'fileencoding', 'filetype' ],
\ [ 'gutentags' ],
\ [ 'neomake_warnings', 'neomake_errors', 'neomake_infos', 'neomake_ok' ]
\ ]
\ },
\ 'component': {
\ 'lineinfo': '⭡ %3l:%-2v'
\ },
\ 'component_function': {
\ 'gitbranch': 'fugitive#head',
\ 'syntastic': 'SyntasticStatuslineFlag',
\ 'filetype': 'BufferFileType',
\ 'fileformat': 'BufferFileFormat',
\ },
\ 'component_expand': {
\ 'syntastic': 'SyntasticStatuslineFlag',
\ 'neomake_infos': 'lightline#neomake#infos',
\ 'neomake_warnings': 'lightline#neomake#warnings',
\ 'neomake_errors': 'lightline#neomake#errors',
\ 'neomake_ok': 'lightline#neomake#ok',
\ },
\ 'component_type': {
\ 'syntastic': 'error',
\ 'neomake_warnings': 'warning',
\ 'neomake_errors': 'error',
\ 'neomake_ok': 'left',
\ },
\ 'separator': { 'left': '', 'right': '' },
\ 'subseparator': { 'left': '', 'right': '' },
\ 'colorscheme' : 'tender',
\ }
function! BufferFileType()
return winwidth(0)>70?(strlen(&filetype)? WebDevIconsGetFileTypeSymbol():'no ft'):''
endfunction
function! BufferFileFormat()
return winwidth(0)>70?(&fileformat.''.WebDevIconsGetFileFormatSymbol()):''
endfunction
" function! Fishabspath() abort
" return system('source ~/.oh-my-zsh/plugins/shrink-path/shrink-path.plugin.zsh && shrink_path -f')
" endfunction
"-----------------------------------------------------------------
" Fzf Configuration
" This is the default extra key bindings
"-----------------------------------------------------------------
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.local/share/fzf-history'
let $FZF_DEFAULT_COMMAND = 'rg --files --hidden --follow --glob "!.git/*"'
function! RipgrepFzf(query, fullscreen)
let command_fmt = 'rg --column --line-number --no-heading --color=always --smart-case %s || true'
let initial_command = printf(command_fmt, shellescape(a:query))
let reload_command = printf(command_fmt, '{q}')
let spec = {'options': ['--phony', '--query', a:query, '--bind', 'change:reload:'.reload_command]}
call fzf#vim#grep(initial_command, 1, fzf#vim#with_preview(spec), a:fullscreen)
endfunction
command! -nargs=* -bang RG call RipgrepFzf(<q-args>, <bang>0)
" floating fzf window with borders
function! CreateCenteredFloatingWindow()
let width = min([&columns - 4, max([80, &columns - 20])])
let height = min([&lines - 4, max([20, &lines - 10])])
let top = ((&lines - height) / 2) - 1
let left = (&columns - width) / 2
let opts = {'relative': 'editor', 'row': top, 'col': left, 'width': width, 'height': height, 'style': 'minimal'}
let top = "╭" . repeat("─", width - 2) . "╮"
let mid = "│" . repeat(" ", width - 2) . "│"
let bot = "╰" . repeat("─", width - 2) . "╯"
let lines = [top] + repeat([mid], height - 2) + [bot]
let s:buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(s:buf, 0, -1, v:true, lines)
call nvim_open_win(s:buf, v:true, opts)
set winhl=Normal:Floating
let opts.row += 1
let opts.height -= 2
let opts.col += 2
let opts.width -= 4
call nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
au BufWipeout <buffer> exe 'bw '.s:buf
endfunction
" Files + devicons + floating fzf
function! Fzf_files()
function! s:files()
let l:files = split(system($FZF_DEFAULT_COMMAND), '\n')
return l:files
" return s:prepend_icon(l:files)
endfunction
function! s:prepend_icon(candidates)
let l:result = []
for l:candidate in a:candidates
let l:filename = fnamemodify(l:candidate, ':p:t')
let l:icon = WebDevIconsGetFileTypeSymbol(l:filename, isdirectory(l:filename))
call add(l:result, printf('%s %s', l:icon, l:candidate))
endfor
return l:result
endfunction
function! s:edit_file(lines)
if len(a:lines) < 2 | return | endif
" map passed expect key to command
let l:cmd = get({
\ 'ctrl-v': 'vertical split',
\ 'ctrl-s': 'split',
\ 'ctrl-t': 'tabe',
\ }, a:lines[0], 'e')
" example arg lines: ['ctrl-s', ' composer.json']
for l:item in a:lines[1:]
" replace icon+<space> from 2nd index
" let l:filepath = substitute(l:item, '\zs[^ ]* ', '', '' )
let l:filepath = trim(l:item)
execute 'silent ' . l:cmd . ' '. l:filepath
endfor
endfunction
let l:fzf_preview_option = '--preview "bat --style=numbers,changes --color=always {+1}" '
let l:fzf_files_option = '--expect=ctrl-s,ctrl-v,ctrl-s --multi --bind=ctrl-a:select-all,ctrl-d:deselect-all'
call fzf#run({
\ 'source' : s:files(),
\ 'sink*': function('s:edit_file'),
\ 'options': '-m --reverse ' . l:fzf_preview_option . l:fzf_files_option,
\ 'down': '40%',
\ 'window': 'call CreateCenteredFloatingWindow()'})
endfunction
nnoremap <silent> <leader>zf :call Fzf_files()<CR>
" Buffers + floating fzf
function! Fzf_buffers()
function! s:buflist()
redir => ls
silent ls
redir END
let l:rawlist = split(ls, '\n')
let l:cbuffers = []
for l:line in l:rawlist
" \zs : anything, sets start of match.
" \ze : anything, sets end of match.
let l:fpath = matchstr(l:line, '"\zs[^"]\+\ze"')
let l:lnu = matchstr(l:line, 'line\zs [0-9]*' )
let l:filepath = expand(l:fpath)
" if filereadable(l:filepath)
let l:cbuffers += [l:filepath . ' ' . l:lnu]
" endif
endfor
return l:cbuffers
endfunction
function! s:bufopen(lines)
" map passed expect key to command
let l:cmd = get({
\ 'ctrl-v': 'vertical split',
\ 'ctrl-s': 'split',
\ 'ctrl-t': 'tabe',
\ }, a:lines[0], 'e')
" arg lines: ['ctrl-s', '/home/bhaskar/.config/nvim/init.vim 753']
for l:item in a:lines[1:]
" replace icon+<space> from 2nd index
let l:filepath =matchstr(l:item, '\zs[^0-9]*')
let l:linenum =matchstr(l:item, '\zs[0-9]*')
execute 'silent ' . l:cmd . ' '. l:linenum . ' '. l:filepath
endfor
endfunction
let l:fzf_preview_option = '--preview "bat --style=numbers,changes --color=always -r {+2}: {1}" '
let l:fzf_buffer_option = '--expect=ctrl-s,ctrl-v,ctrl-s --multi --bind=ctrl-a:select-all,ctrl-d:deselect-all'
call fzf#run({
\ 'source' : <sid>buflist(),
\ 'sink*' : function('s:bufopen'),
\ 'options': '-m --reverse '. l:fzf_preview_option . l:fzf_buffer_option,
\ 'down': '40%',
\ 'window': 'call CreateCenteredFloatingWindow()'})
endfunction
nnoremap <silent> <Leader><Enter> :call Fzf_buffers()<CR>
"-----------------------------------------------------------------
" moving around in panes
function! WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
exec "wincmd ".a:key
endif
endfunction
nnoremap <silent> <C-h> :call WinMove('h')<CR>
nnoremap <silent> <C-j> :call WinMove('j')<CR>
nnoremap <silent> <C-k> :call WinMove('k')<CR>
nnoremap <silent> <C-l> :call WinMove('l')<CR>
"-----------------------------------------------------------------
" General Neomake
"-----------------------------------------------------------------
call neomake#configure#automake('nrwi', 1500)
let g:neomake_error_sign = {'text': '☠', 'texthl': 'NeomakeErrorSign'}
let g:neomake_warning_sign = {'text': '⚠', 'texthl': 'NeomakeWarningSign'}
let g:neomake_message_sign = {'text': '➤', 'texthl': 'NeomakeMessageSign'}
let g:neomake_info_sign = {'text': 'ℹ', 'texthl': 'NeomakeInfoSign'}
"
let g:neomake_virtualtext_prefix = '➤ '
"will only place signs
let g:neomake_highlight_lines=0
" open list automatically.
let g:neomake_open_list = 0
let g:neomake_verbose = 1
let g:neomake_html_enabled_markers = ['htmlhint']
let g:neomake_yaml_enabled_markers = ['yamllint']
let g:neomake_php_enabled_makers = ['php', 'phpcs']
let g:neomake_php_phpcs_args_standard = '/home/bhaskar/.config/php-coding-standard/DG/ruleset.xml'
let g:neomake_go_enabled_makers = ['go']
let g:neomake_sh_enabled_makers = ['shellcheck']
let g:neomake_zshrc_enabled_makers = ['shellcheck']
let g:neomake_python_enabled_markers = ["autopep8", "yapf"]
" let g:neomake_highlight_lines = 1
"-----------------------------------------------------------------
" Neoformat
"-----------------------------------------------------------------
let g:neoformat_python_autopep8 = {
\ 'exe': 'autopep8',
\ 'args': ['-s 4', '-E'],
\ 'replace': 1,
\ 'stdin': 1,
\ 'env': ["DEBUG=1"],
\ 'valid_exit_codes': [0, 23],
\ 'no_append': 1,
\ }
let g:neoformat_python_yapf = {
\ 'exe': 'yapf',
\ 'stdin': 1,
\}
let g:neoformat_enabled_python = ['yapf', 'autopep8']
let g:neoformat_enabled_php = ['phpcbf']
let g:neoformat_php_phpcbf = {
\ 'exe': 'phpcbf',
\ 'args': ['--standard=/home/bhaskar/.config/php-coding-standard/DG/ruleset.xml'],
\ 'stdin':1,
\ 'env': ["DEBUG=1"],
\ 'valid_exit_codes': [0, 1],
\ }
let g:neoformat_enabled_yaml = ['prettier']
let g:neoformat_yaml_prettier = {
\ 'exe': 'prettier',
\ 'args': ['--stdin', '--stdin-filepath', '"%:p"', '--parser', 'yaml'],
\ 'stdin': 1
\}
let g:neoformat_enabled_sh = ['shfmt']
let g:neoformat_enabled_html = ['tidy']
let g:neoformat_enabled_xml = ['tidy']
let g:neoformat_enabled_json = ['jq']
" let g:neoformat_enabled_go = ['gofmt'] " used goimports in vim-go.
let g:neoformat_enabled_sql = ['sqlfmt']
let g:neoformat_enabled_javascript = ['eslint_d']
let g:neoformat_enabled_markdown = ['prettier']
let g:neoformat_enabled_yaml = ['prettier']
let g:neoformat_yaml_prettier = {
\ 'exe': 'prettier',
\ 'args': ['--stdin', '--stdin-filepath', '"%:p"', '--parser', 'yaml'],
\ 'stdin': 1
\}
"-----------------------------------------------------------------
" Keybindings
"-----------------------------------------------------------------
"-----------------------------------------------------------------
" vimux keybindings: Golang
"-----------------------------------------------------------------
map <leader>gr :wa<CR> :GoRun<CR>
map <leader>gtr :wa<CR> :GolangRun<CR>
map <leader>rgt :wa<CR> :GolangTestCurrentPackage<CR>
"-----------------------------------------------------------------
"Terminal-related configurations.
tnoremap <C-w>h <C-\><C-N><C-w>h
tnoremap <C-w>j <C-\><C-N><C-w>j
tnoremap <C-w>k <C-\><C-N><C-w>k
tnoremap <C-w>l <C-\><C-N><C-w>l
map <silent> <leader>t <Esc>:15split term://bash<CR>
map <silent> <leader>h :nohlsearch<CR>
" COC Autocompletion stuff----------
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
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.
if exists('*complete_info')
inoremap <expr> <cr> complete_info()["selected"] != "-1" ? "\<C-y>" : "\<C-g>u\<CR>"
else
imap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
endif
" Use `[g` and `]g` to navigate diagnostics
nmap <silent> [g <Plug>(coc-diagnostic-prev)
nmap <silent> ]g <Plug>(coc-diagnostic-next)
" 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
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
augroup mygroup
autocmd!
" Setup formatexpr specified filetype(s).
autocmd FileType typescript,json setl formatexpr=CocAction('formatSelected')
" Update signature help on jump placeholder.
autocmd User CocJumpPlaceholder call CocActionAsync('showSignatureHelp')
augroup end
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
" Vista coc
map <silent> <space>v <Esc>:Vista finder coc<CR>
" disable vim-go :GoDef short cut (gd)
" this is handled by LanguageClient [LC]
let g:go_def_mapping_enabled = 0
" Remap keys for gotos
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)
" END COC Autocompletion stuff----------
" +----------------+
" RG Find toggle
nnoremap <Leader>rg :RG<space>
" ACK find
cnoreabbrev Ack Ack!
nnoremap <Leader>f :Ack!<space>
" Add trailing dots for PHP comments.
cnoreabbrev addDot %s/^\s\+\/\/.*[^.]$/\0./gc
cnoreabbrev spaceSlash %s/^\s\+\/\/\(\S\)/\/\/ \1/gc
inoremap JJ <Esc>
inoremap jj <Esc>
inoremap jJ <Esc>
inoremap Jj <Esc>
nnoremap <silent> <leader>w <C-w>
map <silent> <leader>c<space> :CmusPlay<CR>
map <silent> <leader>ck :CmusPause<CR>
map <silent> <leader>cn :CmusNext<CR>
map <silent> <leader>cp :CmusPrev<CR>
nnoremap <leader>e :FZF<CR>
nnoremap <leader>b :buffers<CR>
nnoremap <silent> <leader>bd :bdelete<CR>
" Write file.
map <silent> <leader>z<Esc> :w<CR>
" Open todo.
map <silent> <leader>td :vsplit $HOME/list.todo<CR>
" Edit vimrc.
map <silent> <leader>ve :e $HOME/.config/nvim/init.vim<CR>
map <silent> <leader>vr :so $HOME/.config/nvim/init.vim<CR> :echomsg "init.vim sourced!"<CR>
map <silent> <leader>VR :so $HOME/.config/nvim/init.vim<CR> :echomsg "init.vim sourced!"<CR>
map <silent> <leader>VE :e $HOME/.config/nvim/init.vim<CR>
" resize vertical split windows.
map <silent> <leader>w+ :vertical resize +5<CR>
map <silent> <leader>w- :vertical resize -5<CR>
" Vem shift buffer
nmap <leader>sbh <Plug>vem_move_buffer_left-
nmap <leader>sbl <Plug>vem_move_buffer_right_
" Vem select buffer
nmap <leader>bh <Plug>vem_prev_buffer-
nmap <leader>bl <Plug>vem_next_buffer-
nmap <leader>bx :bdelete<CR><CR>
" Painless Digraph
map <silent> <leader>de <Plug>(PainlessdigraphEnable)
map <silent> <Leader>dd <Plug>(PainlessdigraphDisable)
map <silent> <Leader>dt <Plug>(PainlessdigraphToggle)
" change to current file directory.
nnoremap <leader>cd :cd %:p:h<CR>:pwd<CR>
"-------------------
" Move lines with alt+movement
"-------------------
" Normal mode
" nnoremap <C-j> :m .+1<CR>==
" nnoremap <C-k> :m .-2<CR>==
" Insert mode
inoremap <C-j> <ESC>:m .+1<CR>==gi
inoremap <C-k> <ESC>:m .-2<CR>==gi
" Visual mode
" vnoremap <C-k> :m '<-2<CR>gv=gv
" vnoremap <C-j> :m '>+1<CR>gv=gv
"-------------------
" keep original yanked text after pasting
vnoremap <leader>p "_dP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment