" Plugins --------------------------------------------------------- if empty(glob('~/.vim/autoload/plug.vim')) silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim autocmd VimEnter * PlugInstall --sync | source $MYVIMRC endif call plug#begin('~/.vim/bundle') Plug 'vimwiki/vimwiki' Plug 'mattn/webapi-vim' Plug 'mattn/gist-vim' " automatic closing of quotes, parenthesis, brackets, etc Plug 'jiangmiao/auto-pairs' Plug 'dylanaraps/wal.vim' " tables " Plug 'dhruvasagar/vim-table-mode' " i3 syntax Plug 'https://github.com/PotatoesMaster/i3-vim-syntax' " fzf Plug 'junegunn/fzf' | Plug 'junegunn/fzf.vim' " Git wrapper Plug 'https://github.com/tpope/vim-fugitive' " tabular Plug 'godlygeek/tabular' Plug 'plasticboy/vim-markdown', { 'for': 'markdown' } Plug 'tbabej/taskwiki' Plug 'nelstrom/vim-markdown-folding' " sandwiched textobject Plug 'machakann/vim-sandwich' " enhance in-buffer search Plug 'junegunn/vim-slash' " status line Plug 'itchyny/lightline.vim' " Show git diff in the gutter Plug 'airblade/vim-gitgutter' " distraction-free mode Plug 'junegunn/goyo.vim' Plug 'junegunn/rainbow_parentheses.vim' Plug 'thinca/vim-quickrun' "Plug 'lambdalisue/gina.vim' Plug 'ervandew/supertab' Plug 'tpope/vim-eunuch' call plug#end() " format ------------------------------------------------------------ set autoindent set backup set nu set showmatch set title set tabstop=4 set shiftwidth=4 set softtabstop=4 set expandtab set wildmenu set wildmode=full set incsearch " highlight search term as you type set ignorecase set noshowmode " syntax set t_Co=256 " enable is better than `on`, doesn't reset colors when sourcing config file syntax enable set modeline set ls=2 set backspace=indent,eol,start set complete-=i set smarttab " conceal symbols such as *italics* and **bold** set conceallevel=2 " Always show statusline set laststatus=2 set colorcolumn=80 let s:error_sign = '✘' " set background=dark set foldenable set foldmethod=indent set foldlevelstart=0 set hidden set wildignorecase " set transparent background and colorscheme function! NoBackground() abort highlight Normal ctermbg=none guibg=none highlight NonText ctermbg=none guibg=none highlight LineNr ctermbg=none guibg=none endfunction augroup transparentBg autocmd! autocmd colorscheme * call NoBackground() augroup END augroup numbertoggle autocmd! autocmd BufEnter,FocusGained,InsertLeave * set relativenumber autocmd BufLeave,FocusLost,InsertEnter * set norelativenumber augroup END colorscheme wal " maps -------------------------------------------------------------- " space as leader let mapleader = "\" " comma for folding nnoremap , za vnoremap , za " make gist with leader-g nnoremap gi :Gist -a nnoremap G :Gist " quit without saving with leader-q nnoremap q :q! " Y copy to the end of line nnoremap Y y$ vmap y "+y vmap d "+d nmap p "+p nmap P "+P vmap p "+p vmap P "+P " open file under cursor with default app nnoremap gO :!xdg-open " insert current date nnoremap "=strftime("%Y.%m.%d %a")P inoremap =strftime("%Y.%m.%d %a") " display a column at 80 char nnoremap :let &cc = &cc == '' ? '80' : '' " source init.vim nnoremap :set spell! nnoremap :!chmod +x % nnoremap :so ~/.config/nvim/init.vim " move lines up and down with Ctrl + j/k in normal, insert and visual mode nnoremap :m .+1== nnoremap :m .-2== inoremap :m .+1==gi inoremap :m .-2==gi vnoremap :m '>+1gv=gv vnoremap :m '<-2gv=gv= " mappings for terminal mode if has('nvim') tnoremap tnoremap h tnoremap j tnoremap k tnoremap l nnoremap h nnoremap j nnoremap k nnoremap l nnoremap :close endif " remap tab for following links in vimwiki nnoremap n VimwikiNextLink " fugitive binds nnoremap gw :Gwrite nnoremap gs :Gstatus nnoremap gc :Gcommit nnoremap gp :Gpush " Disable swap files set noswapfile set nobackup set nowritebackup if !&diff set undodir=~/.vim/undodir set undofile endif " remember cursor position when opening a file " augroup resCur " autocmd! " autocmd BufReadPost * call setpos(".", getpos("'\'")) " augroup END " text width 80 for specific file formats augroup Formatting autocmd! autocmd BufNew,BufRead *.txt,*.py setlocal formatoptions=cqt textwidth=80 \ colorcolumn=80 wrapmargin=0 augroup END " set .md and .markdown to use markdown filetype augroup markdown autocmd BufNewFile,BufReadPost *.md,*markdown set filetype=markdown \ formatoptions=cqt textwidth=137 wrapmargin=0 let g:markdown_fenced_languages = ['html', 'python', 'bash=sh'] augroup END autocmd FileType python nnoremap :exec '!python' \shellescape(@%, 1) command! -buffer RunPy3Script split | resize 15 | terminal python3 % nnoremap :RunPy3Script " Markdown-compatible tables let g:table_mode_corner='|' " folding let g:vimwiki_folding = 'expr' " folding based on expression let g:markdown_folding_level = 0 let g:markdown_fold_style = 'nested' " fzf settings ------------------------------------------------------- " This is the default extra key bindings let g:fzf_action = { \ 'ctrl-t': 'tab split', \ 'ctrl-x': 'split', \ 'ctrl-v': 'vsplit' } " Default fzf layout " - down / up / left / right let g:fzf_layout = { 'down': '~40%' } " Customize fzf colors to match your color scheme let g:fzf_colors = \ { 'fg': ['fg', 'Normal'], \ 'bg': ['bg', 'Normal'], \ 'hl': ['fg', 'Comment'], \ 'fg+': ['Normal'], \ 'bg+': ['Normal'], \ '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' " [Buffers] Jump to the existing window if possible let g:fzf_buffers_jump = 1 let g:fzf_commits_log_options = '--graph --colors=always \--format="%C(auto)%h%d %s %C(black)%C(bold)%cr"' " Open file with fzf noremap f :FZF ~/ noremap wf :FZF ~/Documents/vimwiki noremap / :Rg noremap b :Buffers " Insert mode completion imap (fzf-complete-file-rg) imap (fzf-complete-path) imap (fzf-complete-line) imap (fzf-complete-word) " Advanced customization using autoload functions inoremap fzf#vim#complete#word({'left': '15%'}) " Replace the default dictionary completion with fzf-based fuzzy completion inoremap fzf#complete('cat /usr/share/dict/words') " ripgrep for fzf " " --column: Show column number " --line-number: Show line number " --no-heading: Do not show file headings in results " --fixed-strings: Search term as a literal string " --ignore-case: Case insensitive search " --no-ignore: Do not respect .gitignore, etc... " --hidden: Search hidden files and folders " --follow: Follow symlinks " --glob: Additional conditions for search (in this case ignore everything in " the .git/ folder) " --color: Search color options " Search for files containing a term command! -bang -nargs=* Rg \ call fzf#vim#grep( \ 'rg --column --line-number --no-heading --no-ignore --smart-case --hidden \ --color=always '.shellescape(), 1, \ 0 ? fzf#vim#with_preview('up:60%') \ : fzf#vim#with_preview('right:50%:hidden', '?'), \ 0) " use ripgrep for grepprg (vim search) set grepprg=rg\ --vimgrep autocmd! FileType fzf autocmd FileType fzf set laststatus=0 noshowmode noruler \| autocmd BufLeave set laststatus=2 showmode ruler " vimwiki settings ---------------------------------------------------------- let g:vimwiki_list = [{'path': '~/Documents/vimwiki/', \ 'syntax': 'markdown', 'ext': '.md'}] " code syntax highlight in code blocks let wiki = {} let wiki.automatic_nested_syntaxes = 1 " alternating header colors let g:vimwiki_hl_headers = 1 let g:vimwiki_url_maxsave=1 let g:lightline = { \ 'colorscheme': 'wal', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'gitbranch', 'readonly', 'absolutepath', 'modified' ] ], \ 'right': [ [ 'lineinfo' ], [ 'percent', 'wordcount' ], \ [ 'filetype' ] ] \ }, \ 'component_function': { \ 'gitbranch': 'fugitive#head', \ 'wordcount': 'WordCount', \ }, \ } let g:gist_put_url_to_clipboard_after_post = 1 " follow symlinks always " https://www.reddit.com/r/vim/comments/1x5rhh/how_to_follow_symlinks/cfbck18/ function! MyFollowSymlink(...) if exists('w:no_resolve_symlink') && w:no_resolve_symlink return endif let fname = a:0 ? a:1 : expand('%') if fname =~ '^\w\+:/' " do no mess with fugitive:// etc return endif let fname = simplify(fname) let resolvedfile = resolve(fname) if resolvedfile == fname return endif let resolvedfile = fnameescape(resolvedfile) "echohl WarningMsg | echomsg 'Resolving syminlk' fname '=>' resolvedfile | "\ echohl None exec 'file ' . resolvedfile endfunction command! FollowSymlink call MyfollowSymlink() command! ToggleFollowSymlink let w:no_resolve_symlink = !get(w:, \ 'no_resolve_symlink', 0) | echo "w:no_resolve_symlink =>" \ w:no_resolve_symlink augroup FollowSymlinks au BufReadPost * call MyFollowSymlink(expand('')) augroup END " tests ----------------------------------------------------------------------- " https://gist.github.com/cormacrelf/d0bee254f5630b0e93c3 function! WordCount() let currentmode = mode() if !exists("g:lastmode_wc") let g:lastmode_wc = currentmode endif " if we modify file, open a new buffer, be in visual ever, or switch modes " since last run, we recompute. if &modified || !exists("b:wordcount") || currentmode =~? '\c.*v' || \ currentmode != g:lastmode_wc let g:lastmode_wc = currentmode let l:old_position = getpos('.') let l:old_status = v:statusmsg execute "silent normal g\" if v:statusmsg == "--No lines in buffer--" let b:wordcount = 0 else let s:split_wc = split(v:statusmsg) if index(s:split_wc, "Selected") < 0 let b:wordcount = str2nr(s:split_wc[11]) else let b:wordcount = str2nr(s:split_wc[5]) endif let v:statusmsg = l:old_status endif call setpos('.', l:old_position) return b:wordcount else return b:wordcount endif endfunction highlight ColorColumn ctermbg=18 inoremap pumvisible() ? "\" : "\u\" inoremap pumvisible() ? '' : \ '=pumvisible() ? "\Down>" : ""' "inoremap pumvisible() ? "'' : "\ '=pumvisible() ? "\Down>" : ""' filetype plugin on autocmd FileType * \ if &omnifunc != '' | \ call SuperTabChain(&omnifunc, "") | \ endif autocmd VimEnter * RainbowParentheses