set nocompatible filetype off call plug#begin('~/.local/share/nvim/plugged') " === plugins === function! Cond(Cond, ...) let opts = get(a:000, 0, {}) return a:Cond ? opts : extend(opts, { 'on': [], 'for': [] }) endfunction " editing plugins Plug 'godlygeek/tabular', Cond(!exists('g:vscode')) Plug 'nathanaelkane/vim-indent-guides', Cond(!exists('g:vscode')) Plug 'tpope/vim-commentary', Cond(!exists('g:vscode')) Plug 'airblade/vim-gitgutter', Cond(!exists('g:vscode')) " ui Plug 'sickill/vim-monokai', Cond(!exists('g:vscode')) Plug 'itchyny/lightline.vim', Cond(!exists('g:vscode')) " lang integrations Plug 'lepture/vim-jinja', Cond(!exists('g:vscode')) Plug 'fatih/vim-go', Cond(!exists('g:vscode')) Plug 'hashivim/vim-terraform', Cond(!exists('g:vscode')) Plug 'editorconfig/editorconfig-vim', Cond(!exists('g:vscode')) Plug 'rust-lang/rust.vim', Cond(!exists('g:vscode')) Plug 'rodjek/vim-puppet', Cond(!exists('g:vscode')) " helpers "" distraction free writing Plug 'junegunn/limelight.vim', Cond(!exists('g:vscode')) Plug 'junegunn/goyo.vim', Cond(!exists('g:vscode')) Plug 'reedes/vim-pencil', Cond(!exists('g:vscode')) "" markdown Plug 'suan/vim-instant-markdown', Cond(!exists('g:vscode')) Plug 'dense-analysis/ale', Cond(!exists('g:vscode')) Plug 'neoclide/coc.nvim', Cond(!exists('g:vscode'), {'branch': 'release'}) call plug#end() filetype plugin indent on " == formatting == set tabstop=4 set smarttab set softtabstop=4 set shiftround set shiftwidth=4 set autoindent set expandtab set smartindent set formatoptions=tcqjron "set formatoptions= " == ui == set cursorline set showcmd set number set wildmode=list:longest set lazyredraw set wildmenu set noshowmatch set colorcolumn=80 set laststatus=2 set matchtime=5 set mouse=a set mousehide set noerrorbells set noshowmode set numberwidth=2 set relativenumber set shortmess=rtiF set ruler set scrolloff=7 set title set titlestring="" set ttyfast " == searching == set hlsearch set incsearch set gdefault set ignorecase set magic set smartcase " == folding == set foldenable set foldmethod=indent set foldnestmax=2 set foldlevelstart=2 " == backups == set nobackup set backupcopy=no set nowritebackup " == swap == set swapfile set updatecount=200 set updatetime=300 " == undo == set undolevels=1000 set undoreload=10000 set undodir=~/.vim/undo set undofile " == environment / directories == set autochdir set directory=/var/tmp,/tmp set viewdir=~/.vim/view " == misc == set autoread set confirm set encoding=utf-8 set history=1000 set modeline set modelines=5 set notildeop set wildignore=*.swp,*.bak,*.pyc,*~,*.o set hidden " == editing == set backspace=indent,eol,start " set esckeys set matchpairs=(:),{:},[:],<:> set notimeout set ttimeout set timeoutlen=1000 set ttimeoutlen=0 set virtualedit=block set whichwrap=b,s " == line breaking == set linebreak set wrap set wrapscan " == to use guicolors in terminal == set termguicolors " === keybinds === set pastetoggle= set signcolumn=yes let maplocalleader = "รถ" let mapleader = "\" " map w: w! " nnoremap w :w nmap za map , : vnoremap y y`] vnoremap p p`] nnoremap p p`] nnoremap , :nohlsearch noremap gV `[v`] map Y y$ map j gj map k gk map N Nzz map n nzz inoremap jj " no more ex mode nnoremap Q " Use // in visual mode to search for selection " https://vim.fandom.com/wiki/Search_for_visually_selected_text vnoremap // y/\V=escape(@",'/\') if exists('g:vscode') xmap gc VSCodeCommentary nmap gc VSCodeCommentary omap gc VSCodeCommentary nmap gcc VSCodeCommentaryLine else nnoremap h nnoremap j nnoremap k nnoremap l nmap :bnext nmap :bprev nnoremap m :InstantMarkdownPreview nnoremap u :GundoToggle nnoremap d :diffupdate nmap :Goyo:TogglePencil nmap w :Goyo:TogglePencil:set colorcolumn= nmap c :%w !xclip -selection clipboard nmap x :r !xclip -out -selection -clipboard nmap f :Autoformat nnoremap v vl syntax enable silent! colorscheme monokai highlight Comment guifg=#64d86b highlight SpecialComment guifg=#64d86b highlight Todo guibg=#a9ebad let g:lightline = { \ 'colorscheme': 'wombat', \ 'active': { \ 'left': [ [ 'mode', 'paste' ], \ [ 'readonly', 'filename', 'modified', 'helloworld' ] ], \ 'right': [ [ 'gitbranch' ], \ [ 'lineinfo' ], \ [ 'percent' ], \ [ 'fileformat', 'fileencoding', 'filetype', 'charvaluehex' ], \ [ 'directory' ] ], \ }, \ 'component_function': { \ 'gitbranch': 'fugitive#head', \ 'directory': 'LightLineFilename', \ }, \ 'component': { \ }, \ } function! LightLineFilename() return fnamemodify(expand('%F'), ":~:h") endfunction " == pencil == let g:pencil#textwidth = 80 let g:pencil#autoformat = 1 let g:pencil#wrapModeDefault = 'hard' let g:pencil#map#suspend_af = 'K' " == goyo == let g:goyo_width = 100 let g:goyo_height = "90%" let g:goyo_linenr = 0 autocmd! User GoyoEnter Limelight autocmd! User GoyoLeave Limelight! " == limelight == let g:limelight_default_coefficient = 0.5 let g:ale_linters = {'rust': ['rust-analyzer']} " === functions === function! DeleteTrailingWS() exe "normal mz" %s/\s\+$//e exe "normal `z" endfunction autocmd BufWritePre * :call DeleteTrailingWS() autocmd FileType yaml set shiftwidth=2 autocmd FileType toml set shiftwidth=2 autocmd FileType html setl shiftwidth=2 let g:instant_markdown_autostart = 0 let g:terraform_align = 1 let g:terraform_fmt_on_save=1 let g:rustfmt_autosave = 1 inoremap \ coc#pum#visible() ? coc#pum#next(1) : \ CheckBackspace() ? "\" : \ coc#refresh() inoremap coc#pum#visible() ? coc#pum#prev(1) : "\" " Make to accept selected completion item or notify coc.nvim to format " u breaks current undo, please make your own choice. inoremap coc#pum#visible() ? coc#pum#confirm() \: "\u\\=coc#on_enter()\" function! CheckBackspace() abort let col = col('.') - 1 return !col || getline('.')[col - 1] =~# '\s' endfunction " Use to trigger completion. if has('nvim') inoremap coc#refresh() else inoremap coc#refresh() endif if has('nvim') inoremap coc#refresh() else inoremap coc#refresh() endif " https://stackoverflow.com/a/8585343 map q :bpspbnbd nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) endif