Created
July 6, 2022 15:47
-
-
Save dblanken/4c8dda42d8d2580d8176f8d6d9e78556 to your computer and use it in GitHub Desktop.
Vim9 .vimrc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is a small proof of concept of using vim9script for a vimrc | |
vim9script | |
source $VIMRUNTIME/defaults.vim | |
set number relativenumber | |
set signcolumn=yes | |
set laststatus=2 | |
g:mapleader = ' ' | |
g:localmapleader = '\\' | |
packadd minpac | |
minpac#init() | |
minpac#add('tpope/vim-bundler') | |
minpac#add('tpope/vim-commentary') | |
minpac#add('tpope/vim-dispatch') | |
minpac#add('tpope/vim-endwise') | |
minpac#add('tpope/vim-eunuch') | |
minpac#add('tpope/vim-flagship') | |
minpac#add('tpope/vim-fugitive') | |
minpac#add('tpope/vim-git') | |
minpac#add('tpope/vim-markdown') | |
minpac#add('tpope/vim-projectionist') | |
minpac#add('tpope/vim-ragtag') | |
minpac#add('tpope/vim-rails') | |
minpac#add('tpope/vim-rake') | |
minpac#add('tpope/vim-repeat') | |
minpac#add('tpope/vim-rhubarb') | |
minpac#add('tpope/vim-sleuth') | |
minpac#add('tpope/vim-speeddating') | |
minpac#add('tpope/vim-surround') | |
minpac#add('tpope/vim-unimpaired') | |
minpac#add('tpope/vim-vinegar') | |
minpac#add('Shougo/deoplete.nvim') | |
minpac#add('SirVer/ultisnips') | |
minpac#add('airblade/vim-gitgutter') | |
minpac#add('chriskempson/base16-vim') | |
minpac#add('christoomey/vim-tmux-navigator') | |
minpac#add('dense-analysis/ale') | |
minpac#add('godlygeek/tabular') | |
minpac#add('godlygeek/tabular') | |
minpac#add('honza/vim-snippets') | |
minpac#add('ludovicchabant/vim-gutentags') | |
minpac#add('mattn/emmet-vim') | |
minpac#add('roxma/nvim-yarp') | |
minpac#add('roxma/vim-hug-neovim-rpc') | |
minpac#add('sheerun/vim-polyglot') | |
minpac#add('tribela/vim-transparent') | |
minpac#add('vim-pandoc/vim-pandoc') | |
minpac#add('vim-pandoc/vim-pandoc-syntax') | |
minpac#add('vim-ruby/vim-ruby') | |
minpac#add('vim-test/vim-test') | |
minpac#add('vimwiki/vimwiki') | |
minpac#add('kana/vim-textobj-user') | |
minpac#add('nelstrom/vim-textobj-rubyblock') | |
minpac#add('junegunn/fzf.vim') | |
set rtp+=/usr/local/opt/fzf | |
# minpac | |
command! PackUpdate source $MYVIMRC | minpac#update() | |
command! PackClean source $MYVIMRC | minpac#clean() | |
command! PackStatus packadd minpac#status() | |
augroup AutoUpdate | |
au! | |
autocmd BufWritePost .vimrc PackUpdate | |
augroup END | |
# vim-test | |
nmap <silent> <leader>t :TestNearest<CR> | |
nmap <silent> <leader>T :TestFile<CR> | |
nmap <silent> <leader>a :TestSuite<CR> | |
nmap <silent> <leader>l :TestLast<CR> | |
g:test#strategy = 'dispatch' | |
# base16-vim | |
if filereadable(expand("~/.vimrc_background")) | |
g:base16colorspace = 256 | |
source ~/.vimrc_background | |
endif | |
# vim-wiki | |
g:vimwiki_list = [ | |
{ 'path': '~/vimwiki', 'ext': '.md', 'syntax': 'markdown' }, | |
{ 'path': '~/code/vimwiki', 'ext': '.md', 'syntax': 'markdown' } | |
] | |
# deoplete, ultisnips, endwise | |
g:deoplete#enable_at_startup = 0 | |
augroup deopleter | |
au! | |
autocmd InsertEnter * call deoplete#enable() | |
augroup END | |
# Must set trigger to no-op so we can handle it | |
g:UltiSnipsExpandTrigger = "<nop>" | |
g:UltiSnipsJumpForwardTrigger = "<Tab>" | |
g:UltiSnipsJumpBackwardTrigger = "<S-Tab>" | |
# This is a variable that ultisnips will set when | |
# UltiSnips#ExpandSnippetOrJump() is called. | |
# 1 = It expanded or jumped | |
# 0 = It did nothing | |
g:ulti_expand_or_jump_res = 0 | |
# We define our own function that attemps the expand or jump, and if nothing | |
# happened, we return just a regular return. | |
def g:ExpandSnippetOrCarriageReturn(): string | |
var snippet = UltiSnips#ExpandSnippetOrJump() | |
if g:ulti_expand_or_jump_res > 0 | |
return snippet | |
else | |
return "\<CR>" | |
endif | |
enddef | |
# Make sure we don't allow endwise to do its own magic to CR. | |
g:endwise_no_mappings = 1 | |
# Obligitory check last character was space function | |
# get the column number before the current | |
# if col is zero, return 1 so we know it was a space | |
# if col is not zero, get the character before and return 1 if it's a space | |
def g:Check_last_char_was_space(): number | |
var col = col('.') - 1 | |
return !col || getline('.')[col - 1] =~ '\s' | |
enddef | |
# If tab is pressed: | |
# and pull up menu is visible: | |
# C-n to traverse list | |
# else | |
# if we are at the beginning of the line or the character before is a space, | |
# then allow a tab (no autocomplete needed) | |
# if we are not at the beginning of the line and the character before is not | |
# a space, attempt a deoplete completion. | |
inoremap <silent><expr> <TAB> pumvisible() ? "\<C-n>" : g:Check_last_char_was_space() ? "\<TAB>" : deoplete#mappings#manual_complete() | |
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"| # Shift-Tab is previous entry if completion menu open. | |
# If CR is pressed: | |
# if the pull up menu is visible | |
# We attempt to expand the snippet or jump | |
# otherwise | |
# We CR with our own endwise call | |
inoremap <expr> <CR> pumvisible() ? "\<C-R>=g:ExpandSnippetOrCarriageReturn()\<CR>" : "\<CR>\<C-R>=EndwiseDiscretionary()\<CR>" | |
# fzf | |
nnoremap <silent> <Leader>ff :Files<CR> | |
nnoremap <silent> <Leader>fg :Ag / | |
# vim-gitgutter | |
nmap ]h <Plug>(GitGutterNextHunk) | |
nmap [h <Plug>(GitGutterPrevHunk) | |
# Instead of using GitGutterGetHunkSummary, we need to make the call directly | |
# since that function is not defined when this is ran. | |
def g:GitStatus(): string | |
var [a: number, m: number, r: number] = gitgutter#hunk#summary(winbufnr(0)) | |
return printf('+%d ~%d -%d', a, m, r) | |
enddef | |
# ALE | |
g:ale_echo_msg_format = '[%linter%] %s [%severity%]' | |
nnoremap <silent> ]d <Plug>(ale_next) | |
nnoremap <silent> [d <Plug>(ale_previous) | |
g:ale_fix_on_save = 1 | |
g:ale_ruby_rubocop_executable = 'bundle' | |
g:ale_ruby_reek_executable = 'bundle' | |
g:ale_ruby_rails_best_practices_executable = 'bundle' | |
g:ale_linters = { | |
'ruby': ['reek', 'rails_best_practices', 'rubocop'] | |
} | |
g:ale_fixers = { | |
'ruby': ['trim_whitespace', 'remove_trailing_lines', 'rubocop'] | |
} | |
g:ale_running = 0 | |
augroup ALEProgress | |
autocmd! | |
autocmd User ALELintPre g:ale_running = 1 | redrawstatus | |
autocmd User ALELintPost g:ale_running = 0 | redrawstatus | |
augroup END | |
def g:LinterStatus(): string | |
var counts = ale#statusline#Count(bufnr('')) | |
var all_errors = counts.error + counts.style_error | |
var all_non_errors = counts.total - all_errors | |
return counts.total == 0 ? 'OK' : printf( | |
'%dW %dE', | |
all_non_errors, | |
all_errors) | |
enddef | |
def g:LintingStatus(): string | |
if g:ale_running == 1 | |
return "[linting]" | |
else | |
return "" | |
endif | |
enddef | |
# vim-flagship | |
augroup Flagships | |
au! | |
autocmd User Flags call Hoist("buffer", "GitStatus") | |
autocmd User Flags call Hoist("buffer", "LinterStatus") | |
autocmd User Flags call Hoist("buffer", "LintingStatus") | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment