dotfiles/vim/vimrc.symlink

290 lines
5.9 KiB
Text

" vim: set ft=vim
set nocompatible
set encoding=utf-8
scriptencoding utf-8
" Plugins
call plug#begin()
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug '/opt/homebrew/opt/fzf'
Plug 'junegunn/fzf.vim'
Plug 'SirVer/ultisnips'
Plug 'yegappan/lsp'
Plug 'vim-pandoc/vim-pandoc-syntax'
Plug 'quarto-dev/quarto-vim'
Plug 'HerringtonDarkholme/yats.vim'
call plug#end()
" Language config
let g:pandoc#syntax#conceal#use = 0
let g:r_indent_align_args = 0
" Syntax and colors and things
filetype plugin indent on
syntax on
" Disable Swapping
set nobackup nowritebackup noswapfile
" Statusline
" e.g. - [foobar.rs] - [rust] ----
set laststatus=2
set statusline=-[%.30t]-%y-
set fillchars=stl:—,eob:\
set fillchars+=stlnc:—
set fillchars+=vert:\|
" Hide intro message
set shortmess+=
set nowrap
" Relative numbering with absolute anchor
set number relativenumber
set signcolumn=number
set cursorline cursorlineopt=both
" Keep buffers open in memory when not visible
set hidden
" Keep buffers up to date with external changes
set autoread
set backspace=indent,eol,start
" Show invisibles
set list
set listchars=tab:‣\ ,trail:·,extends:◣,precedes:◢,nbsp:○
" Disable folding
set foldmethod=manual
set nofoldenable
" Search fixes
set ignorecase smartcase incsearch hlsearch gdefault
" Show incomplete command-based changes in realtime
set showcmd
" And breathe...
set scrolloff=5
" I think left to write, top to bottom
set splitright splitbelow
" Basic whitespace
set nojoinspaces
set expandtab
set shiftwidth=4
set softtabstop=4
set autoindent
" Show me when my lines are too long
"
" I wish to limit my lines to 80 characters long. However, Vim creates
" the n+1th character when you have n characters in a line. Hence, when
" my line is 80 characters long, I see the red line. So, this is set to
" 82, meaning that I only see the line when my lines actually are too long.
call matchadd('ColorColumn', '\%82v', 100)
" Mappings etc
let mapleader = "\<space>"
let localmapleader = "\\"
" Use jk to escape back to normal
inoremap jk <esc>
inoremap <esc> <nop>
" Hide search highlights
nnoremap <esc> :noh<cr>
nnoremap <leader>/ :noh<cr>
" Switch between recent buffers
nnoremap <leader><leader> <c-^>
" Fix shift-semicolon to write
noremap ; :
" Make it easier to use registers
nnoremap ' "
" I should map these to something useful
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
noremap <up> <nop>
noremap <down> <nop>
noremap <left> <nop>
noremap <right> <nop>
" Case control
nnoremap <leader>u viwU
nnoremap <leader>l viwu
" Moving lines around
nnoremap - ddp==
nnoremap _ :-1d<cr>pk==
" Quick access vimrc
nnoremap <leader>ev :tabedit $MYVIMRC<cr>
nnoremap <leader>es :so $MYVIMRC<cr>
" Pane management
nnoremap <c-j> <c-w><c-j>
nnoremap <c-k> <c-w><c-k>
nnoremap <c-h> <c-w><c-h>
nnoremap <c-l> <c-w><c-l>
inoremap <c-j> <esc><c-w><c-j>
inoremap <c-k> <esc><c-w><c-k>
inoremap <c-h> <esc><c-w><c-h>
inoremap <c-l> <esc><c-w><c-l>
" FZF
nnoremap <leader>o :Files<cr>
nnoremap <leader>b :Buffers<cr>
nnoremap <leader>f :Rg<cr>
nnoremap <leader>g :RG<cr>
let g:fzf_vim = {}
let g:fzf_vim.preview_window = []
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val, "lnum": 1 }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
augroup FZF
autocmd!
autocmd FileType fzf tmap <buffer> jk <c-c>
augroup END
" Focus mode
function! Zoom()
if exists('g:is_zoomed')
unlet g:is_zoomed
execute "wincmd ="
else
let g:is_zoomed = 'true'
execute "wincmd _"
execute "wincmd \|"
endif
endfunc
nnoremap <leader>z :call Zoom()<cr>
" Make directories in a filename if they don't exist.
function! EnsureDirExists ()
let required_dir = expand("%:h")
if !isdirectory(required_dir)
try
call mkdir( required_dir, 'p' )
catch
echom "Could not create directory"
exit
endtry
endif
endfunction
augroup AutoMkdir
autocmd!
autocmd BufNewFile * :call EnsureDirExists()
augroup END
" LSP and other completion
nnoremap aa :LspDiag current<cr>
nnoremap ga :LspDiag nextWrap<cr>
nnoremap gA :LspDiag prevWrap<cr>
augroup Lsp
autocmd!
let lspOptions = #{ ultisnips: v:true }
autocmd User LspSetup call LspOptionsSet(lspOptions)
let lspServers = [#{
\ name: 'r',
\ filetype: ['r', 'rmd', 'quarto'],
\ path: '/usr/local/bin/R',
\ args: ['-s', '-e languageserver::run()']
\ }]
autocmd User LspSetup call LspAddServer(lspServers)
augroup END
" File Running
function! PreviewQuarto()
call ClosePreview()
echom 'Starting preview job'
let b:file = expand('%')
let b:preview_job = job_start(
\ ['quarto', 'preview', b:file],
\ )
endfunc
function! ClosePreview()
if exists("b:preview_job")
echo 'Killing existing job...'
call job_stop(b:preview_job)
endif
endfunc
nnoremap <leader>r :echo 'No preview configured'<cr>
nmap <F5> <leader>r
augroup Previews
autocmd!
autocmd Filetype quarto nnoremap <buffer> <leader>r :call PreviewQuarto()<cr>
augroup END
augroup TextFormatting
autocmd!
autocmd FileType make,go setl noet sw=8 sts=8 ts=8
autocmd FileType r,quarto,rmd setl et sw=2 sts=2 ts=2
augroup END
" Show syntax highlighting groups for word under cursor
"
" This is useful for finding rogue elements I forgot in my colour
" scheme.
nnoremap <leader>\ :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val,"name")')
endfunc
" Open syntax file for current
" Syntax highlighting
colorscheme mpwb