Consistently tab-indent Vimscript

This commit is contained in:
Danielle McLean 2023-10-14 19:49:26 +11:00
parent b006557730
commit 2dc8a5a61c
Signed by: 00dani
GPG key ID: 52C059C3B22A753E
6 changed files with 223 additions and 217 deletions

6
.editorconfig Normal file
View file

@ -0,0 +1,6 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
indent_style = tab

View file

@ -1,87 +1,87 @@
vim9script vim9script
const dark = { const dark = {
bg0: ['#282828', 235], bg0: ['#282828', 235],
bg1: ['#3c3836', 237], bg1: ['#3c3836', 237],
bg2: ['#504945', 239], bg2: ['#504945', 239],
bg4: ['#7c6f64', 243], bg4: ['#7c6f64', 243],
fg1: ['#ebdbb2', 187], fg1: ['#ebdbb2', 187],
fg4: ['#a89984', 137], fg4: ['#a89984', 137],
green: ['#98971a', 100], green: ['#98971a', 100],
yellow: ['#d79921', 172], yellow: ['#d79921', 172],
blue: ['#458588', 66], blue: ['#458588', 66],
aqua: ['#689d6a', 71], aqua: ['#689d6a', 71],
orange: ['#d65d0e', 166], orange: ['#d65d0e', 166],
red: ['#fb4934', 203], red: ['#fb4934', 203],
} }
const light = { const light = {
bg0: ['#fbf1c7', 230], bg0: ['#fbf1c7', 230],
bg1: ['#ebdbb2', 187], bg1: ['#ebdbb2', 187],
bg2: ['#d5c4a1', 187], bg2: ['#d5c4a1', 187],
bg4: ['#a89984', 137], bg4: ['#a89984', 137],
fg1: ['#3c3836', 237], fg1: ['#3c3836', 237],
fg4: ['#7c6f64', 243], fg4: ['#7c6f64', 243],
green: ['#98971a', 100], green: ['#98971a', 100],
yellow: ['#d79921', 172], yellow: ['#d79921', 172],
blue: ['#458588', 66], blue: ['#458588', 66],
aqua: ['#689d6a', 71], aqua: ['#689d6a', 71],
orange: ['#d65d0e', 166], orange: ['#d65d0e', 166],
red: ['#9d0006', 124], red: ['#9d0006', 124],
} }
def ToCrystalline(fg: list<any>, bg: list<any>): list<any> def ToCrystalline(fg: list<any>, bg: list<any>): list<any>
return [ return [
[fg[1], bg[1]], [fg[1], bg[1]],
[fg[0], bg[0]], [fg[0], bg[0]],
'' ''
] ]
enddef enddef
def MakeTheme(c: dict<list<any>>): dict<list<any>> def MakeTheme(c: dict<list<any>>): dict<list<any>>
var theme = { var theme = {
A: ToCrystalline(c.bg0, c.bg4), A: ToCrystalline(c.bg0, c.bg4),
B: ToCrystalline(c.fg4, c.bg2), B: ToCrystalline(c.fg4, c.bg2),
Fill: ToCrystalline(c.fg4, c.bg1), Fill: ToCrystalline(c.fg4, c.bg1),
InactiveA: ToCrystalline(c.bg4, c.bg1), InactiveA: ToCrystalline(c.bg4, c.bg1),
InactiveB: ToCrystalline(c.bg4, c.bg1), InactiveB: ToCrystalline(c.bg4, c.bg1),
InactiveFill: ToCrystalline(c.bg4, c.bg1), InactiveFill: ToCrystalline(c.bg4, c.bg1),
InsertModeA: ToCrystalline(c.bg0, c.blue), InsertModeA: ToCrystalline(c.bg0, c.blue),
InsertModeFill: ToCrystalline(c.fg4, c.bg2), InsertModeFill: ToCrystalline(c.fg4, c.bg2),
VisualModeA: ToCrystalline(c.bg0, c.orange), VisualModeA: ToCrystalline(c.bg0, c.orange),
ReplaceModeA: ToCrystalline(c.bg0, c.aqua), ReplaceModeA: ToCrystalline(c.bg0, c.aqua),
ReplaceModeFill: ToCrystalline(c.fg4, c.bg2), ReplaceModeFill: ToCrystalline(c.fg4, c.bg2),
TerminalModeA: ToCrystalline(c.bg0, c.green), TerminalModeA: ToCrystalline(c.bg0, c.green),
Modified: ToCrystalline(c.red, c.bg1), Modified: ToCrystalline(c.red, c.bg1),
InsertModeModified: ToCrystalline(c.red, c.bg2), InsertModeModified: ToCrystalline(c.red, c.bg2),
TabSel: ToCrystalline(c.bg0, c.fg4), TabSel: ToCrystalline(c.bg0, c.fg4),
ModifiedSel: ToCrystalline(c.bg1, c.fg4), ModifiedSel: ToCrystalline(c.bg1, c.fg4),
} }
theme->extend({ theme->extend({
Tab: theme.Fill, Tab: theme.Fill,
NormalModeModified: theme.Modified, NormalModeModified: theme.Modified,
CommandModeModified: theme.Modified, CommandModeModified: theme.Modified,
VisualModeModified: theme.Modified, VisualModeModified: theme.Modified,
ReplaceModeModified: theme.InsertModeModified, ReplaceModeModified: theme.InsertModeModified,
}) })
return theme return theme
enddef enddef
export def GetThemeColours(): dict<list<any>> export def GetThemeColours(): dict<list<any>>
return &background ==# 'dark' ? dark : light return &background ==# 'dark' ? dark : light
enddef enddef
export def SetTheme(): void export def SetTheme(): void
GetThemeColours()->MakeTheme()->g:crystalline#GenerateTheme() GetThemeColours()->MakeTheme()->g:crystalline#GenerateTheme()
enddef enddef

View file

@ -9,21 +9,21 @@ enddef
# These are really clever - minpac will actually be loaded on the fly only # These are really clever - minpac will actually be loaded on the fly only
# when you need to update or clean your packages, rather than all the time. # when you need to update or clean your packages, rather than all the time.
command! PackUpdate source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#update() command! PackUpdate source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#update()
command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#clean() command! PackClean source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#clean()
command! PackStatus source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#status() command! PackStatus source $XDG_CONFIG_HOME/vim/plugins.vim | minpac#status()
# If the pack directory doesn't exist, we haven't installed any packages yet, # If the pack directory doesn't exist, we haven't installed any packages yet,
# so let's call PackUpdate. # so let's call PackUpdate.
if !isdirectory($XDG_CACHE_HOME .. '/vim/pack') if !isdirectory($XDG_CACHE_HOME .. '/vim/pack')
PackUpdate PackUpdate
endif endif
if has('gui_running') || has('termguicolors') if has('gui_running') || has('termguicolors')
if $COLORTERM == 'truecolor' if $COLORTERM == 'truecolor'
&t_8f = "\<Esc>[38:2:%lu:%lu:%lum" &t_8f = "\<Esc>[38:2:%lu:%lu:%lum"
&t_8b = "\<Esc>[48:2:%lu:%lu:%lum" &t_8b = "\<Esc>[48:2:%lu:%lu:%lum"
endif endif
set termguicolors set termguicolors
endif endif
set background=dark set background=dark
@ -39,7 +39,7 @@ nnoremap <C-t> :Files<CR>
packadd! editorconfig packadd! editorconfig
if exists('+belloff') if exists('+belloff')
set belloff+=ctrlg set belloff+=ctrlg
endif endif
set completeopt+=menuone set completeopt+=menuone
@ -49,30 +49,30 @@ set modelines=5
set showcmd set showcmd
set wildmode=longest,full set wildmode=longest,full
if has('patch-8.2.4325') if has('patch-8.2.4325')
set wildoptions+=pum set wildoptions+=pum
endif endif
set tabstop=2 shiftwidth=2 set tabstop=2 shiftwidth=2
if exists('+breakindent') if exists('+breakindent')
set breakindent breakindentopt=sbr set breakindent breakindentopt=sbr
endif endif
if exists('+relativenumber') if exists('+relativenumber')
set relativenumber set relativenumber
else else
set number set number
endif endif
for dir_name in ['backup', 'swap', 'undo'] for dir_name in ['backup', 'swap', 'undo']
EnsureDir($XDG_STATE_HOME .. '/vim/' .. dir_name) EnsureDir($XDG_STATE_HOME .. '/vim/' .. dir_name)
endfor endfor
set backupdir=.,$XDG_STATE_HOME/vim/backup set backupdir=.,$XDG_STATE_HOME/vim/backup
set directory=.,$XDG_STATE_HOME/vim/swap set directory=.,$XDG_STATE_HOME/vim/swap
if exists('+undofile') if exists('+undofile')
set undofile set undofile
set undodir=$XDG_STATE_HOME/vim/undo set undodir=$XDG_STATE_HOME/vim/undo
endif endif
g:csv_no_conceal = 1 g:csv_no_conceal = 1
@ -87,9 +87,9 @@ nmap <silent> <C-k> <Plug>(ale_previous_wrap)
nmap <silent> <C-j> <Plug>(ale_next_wrap) nmap <silent> <C-j> <Plug>(ale_next_wrap)
g:mucomplete#can_complete = { g:mucomplete#can_complete = {
default: { default: {
omni: (t) => strlen(&l:omnifunc) > 0 && t =~# '\m\k\%(\k\|\.\)$' omni: (t) => strlen(&l:omnifunc) > 0 && t =~# '\m\k\%(\k\|\.\)$'
} }
} }
import "./statusline.vim" import "./statusline.vim"

View file

@ -1,161 +1,161 @@
vim9script vim9script
const lspServers = [ const lspServers = [
{ {
name: 'dockerfile-langserver', name: 'dockerfile-langserver',
filetype: 'dockerfile', filetype: 'dockerfile',
path: expand('~/.local/bin/docker-langserver'), path: expand('~/.local/bin/docker-langserver'),
args: ['--stdio'], args: ['--stdio'],
install: 'npm install -g dockerfile-language-server-nodejs', install: 'npm install -g dockerfile-language-server-nodejs',
}, },
{ {
name: 'lua-language-server', name: 'lua-language-server',
filetype: 'lua', filetype: 'lua',
path: '/usr/local/bin/lua-language-server', path: '/usr/local/bin/lua-language-server',
args: [], args: [],
install: 'brew install lua-language-server', install: 'brew install lua-language-server',
}, },
{ {
name: 'taplo', name: 'taplo',
filetype: 'toml', filetype: 'toml',
path: '/usr/local/bin/taplo', path: '/usr/local/bin/taplo',
args: ['lsp', 'stdio'], args: ['lsp', 'stdio'],
install: 'brew install taplo', install: 'brew install taplo',
}, },
{ {
name: 'tilt-lsp', name: 'tilt-lsp',
filetype: 'bzl', filetype: 'bzl',
path: '/usr/local/bin/tilt', path: '/usr/local/bin/tilt',
args: ['lsp', 'start'], args: ['lsp', 'start'],
install: 'brew install tilt', install: 'brew install tilt',
}, },
{ {
name: 'typescript-language-server', name: 'typescript-language-server',
filetype: ['javascript', 'typescript'], filetype: ['javascript', 'typescript'],
path: '/usr/local/bin/typescript-language-server', path: '/usr/local/bin/typescript-language-server',
args: ['--stdio'], args: ['--stdio'],
install: 'brew install typescript-language-server', install: 'brew install typescript-language-server',
}, },
{ {
name: 'phpactor', name: 'phpactor',
filetype: 'php', filetype: 'php',
path: expand('~/bin/phpactor'), path: expand('~/bin/phpactor'),
args: ['language-server'], args: ['language-server'],
initializationOptions: { initializationOptions: {
'language_server_configuration.auto_config': false, 'language_server_configuration.auto_config': false,
}, },
install: 'curl -Lo phpactor https://github.com/phpactor/phpactor/releases/latest/download/phpactor.phar && chmod u+x phpactor && mv phpactor ~/bin', install: 'curl -Lo phpactor https://github.com/phpactor/phpactor/releases/latest/download/phpactor.phar && chmod u+x phpactor && mv phpactor ~/bin',
}, },
{ {
name: 'pylsp', name: 'pylsp',
filetype: 'python', filetype: 'python',
path: '/usr/local/bin/pylsp', path: '/usr/local/bin/pylsp',
args: [], args: [],
install: 'brew install python-lsp-server', install: 'brew install python-lsp-server',
}, },
{ {
name: 'solargraph', name: 'solargraph',
filetype: 'ruby', filetype: 'ruby',
path: '/usr/local/bin/solargraph', path: '/usr/local/bin/solargraph',
args: ['stdio'], args: ['stdio'],
install: 'brew install solargraph', install: 'brew install solargraph',
}, },
{ {
name: 'vim-language-server', name: 'vim-language-server',
filetype: 'vim', filetype: 'vim',
path: expand('~/.local/bin/vim-language-server'), path: expand('~/.local/bin/vim-language-server'),
args: ['--stdio'], args: ['--stdio'],
install: 'npm install -g vim-language-server', install: 'npm install -g vim-language-server',
}, },
{ {
name: 'vscode-json-language-server', name: 'vscode-json-language-server',
filetype: ['json', 'jsonc'], filetype: ['json', 'jsonc'],
path: expand('~/.local/bin/vscode-json-language-server'), path: expand('~/.local/bin/vscode-json-language-server'),
args: ['--stdio'], args: ['--stdio'],
workspaceConfig: {json: { workspaceConfig: {json: {
format: {enable: true}, format: {enable: true},
validate: {enable: true}, validate: {enable: true},
schemas: g:SchemaStore#Schemata(), schemas: g:SchemaStore#Schemata(),
}}, }},
install: 'npm install -g vscode-langservers-extracted', install: 'npm install -g vscode-langservers-extracted',
}, },
{ {
name: 'yaml-language-server', name: 'yaml-language-server',
filetype: 'yaml', filetype: 'yaml',
path: expand('~/.local/bin/yaml-language-server'), path: expand('~/.local/bin/yaml-language-server'),
args: ['--stdio'], args: ['--stdio'],
workspaceConfig: {yaml: { workspaceConfig: {yaml: {
format: {enable: true, singleQuote: true}, format: {enable: true, singleQuote: true},
schemaStore: {enable: true, url: 'https://www.schemastore.org/api/json/catalog.json'}, schemaStore: {enable: true, url: 'https://www.schemastore.org/api/json/catalog.json'},
}}, }},
install: 'npm install -g yaml-language-server', install: 'npm install -g yaml-language-server',
}, },
] ]
const lspOptions = { const lspOptions = {
aleSupport: true, aleSupport: true,
ignoreMissingServer: true, ignoreMissingServer: true,
} }
command! -nargs=0 -bar LspInstall Install() command! -nargs=0 -bar LspInstall Install()
def InstalledServers(): list<dict<any>> def InstalledServers(): list<dict<any>>
return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1) return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 1)
enddef enddef
def MissingServers(): list<dict<any>> def MissingServers(): list<dict<any>>
return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0) return lspServers->deepcopy()->filter((_, server): bool => executable(server.path) == 0)
enddef enddef
export def LazyConfigure(): void export def LazyConfigure(): void
autocmd VimEnter * ++once Configure() autocmd VimEnter * ++once Configure()
enddef enddef
export def Configure(): void export def Configure(): void
final installedServers = InstalledServers() final installedServers = InstalledServers()
if len(lspServers) != len(installedServers) if len(lspServers) != len(installedServers)
echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.' echo $'{len(lspServers) - len(installedServers)} language servers are configured, but not installed. You may want to run :LspInstall.'
endif endif
g:LspAddServer(installedServers) g:LspAddServer(installedServers)
g:LspOptionsSet(lspOptions) g:LspOptionsSet(lspOptions)
enddef enddef
export def Install(): void export def Install(): void
const missingServers = MissingServers() const missingServers = MissingServers()
if empty(missingServers) if empty(missingServers)
echo $"All {len(lspServers)} configured language servers are already installed." echo $"All {len(lspServers)} configured language servers are already installed."
return return
endif endif
# The installScript runs every missing server's install command, regardless # The installScript runs every missing server's install command, regardless
# of whether any fail in the process. The script's exit status is the number # of whether any fail in the process. The script's exit status is the number
# of failed installations. # of failed installations.
const installScript = "failed=0\n" .. missingServers->copy() const installScript = "failed=0\n" .. missingServers->copy()
->map((_, server): string => $"\{ {server.install}; \} || failed=$((failed + 1))") ->map((_, server): string => $"\{ {server.install}; \} || failed=$((failed + 1))")
->join("\n") .. "\nexit $failed\n" ->join("\n") .. "\nexit $failed\n"
const term = term_start('sh', {exit_cb: (job: job, status: number): void => { const term = term_start('sh', {exit_cb: (job: job, status: number): void => {
# If any installations failed, keep the terminal window open so we can # If any installations failed, keep the terminal window open so we can
# troubleshoot. If they all worked fine, close the terminal and reload the # troubleshoot. If they all worked fine, close the terminal and reload the
# LSP configuration. # LSP configuration.
if status == 0 if status == 0
execute 'bdelete' job->ch_getbufnr('out') execute 'bdelete' job->ch_getbufnr('out')
Configure() Configure()
endif endif
}}) }})
# We prefer term_sendkeys() over sh -c because that will display each # We prefer term_sendkeys() over sh -c because that will display each
# command in the terminal as it's being executed, making it easier to # command in the terminal as it's being executed, making it easier to
# understand exactly what the install script is doing. # understand exactly what the install script is doing.
term->term_sendkeys(installScript) term->term_sendkeys(installScript)
enddef enddef

View file

@ -1,11 +1,11 @@
vim9script vim9script
silent! packadd minpac silent! packadd minpac
if !exists('g:loaded_minpac') if !exists('g:loaded_minpac')
silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac silent !git clone https://github.com/k-takata/minpac.git $XDG_CACHE_HOME/vim/pack/minpac/opt/minpac
augroup minpac { augroup minpac {
autocmd! autocmd!
autocmd VimEnter * call minpac#update() autocmd VimEnter * call minpac#update()
} }
endif endif
packadd minpac packadd minpac
@ -17,7 +17,7 @@ minpac#add('prabirshrestha/async.vim')
minpac#add('lifepillar/vim-gruvbox8') minpac#add('lifepillar/vim-gruvbox8')
if !isdirectory($VIMRUNTIME .. '/pack/dist/opt/editorconfig') if !isdirectory($VIMRUNTIME .. '/pack/dist/opt/editorconfig')
minpac#add('editorconfig/editorconfig-vim') minpac#add('editorconfig/editorconfig-vim')
endif endif
minpac#add('direnv/direnv.vim') minpac#add('direnv/direnv.vim')
@ -74,7 +74,7 @@ minpac#add('fpob/nette.vim')
minpac#add('leafOfTree/vim-svelte-plugin') minpac#add('leafOfTree/vim-svelte-plugin')
if executable('task') if executable('task')
minpac#add('farseer90718/vim-taskwarrior') minpac#add('farseer90718/vim-taskwarrior')
endif endif
minpac#add('pedrohdz/vim-yaml-folds') minpac#add('pedrohdz/vim-yaml-folds')
@ -83,8 +83,8 @@ minpac#add('alx741/yesod.vim')
minpac#add('pbrisbin/vim-syntax-shakespeare') minpac#add('pbrisbin/vim-syntax-shakespeare')
if has('macunix') if has('macunix')
minpac#add('rizzatti/dash.vim') minpac#add('rizzatti/dash.vim')
# We rename this plugin to make sure it loads AFTER vim-polyglot, # We rename this plugin to make sure it loads AFTER vim-polyglot,
# since it won't work properly if it's loaded first. # since it won't work properly if it's loaded first.
minpac#add('itspriddle/vim-marked', {name: 'zzvim-marked'}) minpac#add('itspriddle/vim-marked', {name: 'zzvim-marked'})
endif endif

16
vimrc
View file

@ -1,20 +1,20 @@
vim9script vim9script
const xdg = { const xdg = {
XDG_CONFIG_HOME: '~/.config', XDG_CONFIG_HOME: '~/.config',
XDG_CACHE_HOME: '~/.cache', XDG_CACHE_HOME: '~/.cache',
XDG_DATA_HOME: '~/.local/share', XDG_DATA_HOME: '~/.local/share',
XDG_STATE_HOME: '~/.local/state', XDG_STATE_HOME: '~/.local/state',
} }
for [key, default] in items(xdg) for [key, default] in items(xdg)
if !has_key(environ(), key) if !has_key(environ(), key)
setenv(key, expand(default)) setenv(key, expand(default))
endif endif
endfor endfor
set runtimepath=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after,$XDG_CACHE_HOME/vim/after set runtimepath=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$XDG_CONFIG_HOME/vim/after,$XDG_CACHE_HOME/vim/after
set viminfo+=n$XDG_STATE_HOME/vim/viminfo set viminfo+=n$XDG_STATE_HOME/vim/viminfo
if exists('+packpath') if exists('+packpath')
set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim set packpath^=$XDG_CONFIG_HOME/vim,$XDG_CACHE_HOME/vim
endif endif
g:netrw_home = $XDG_CACHE_HOME .. '/vim/netrw' g:netrw_home = $XDG_CACHE_HOME .. '/vim/netrw'