My first lua config

Directories are self explanatory

+ ui/* for ui stuff
+ statusbar in ui
+ keymap/* for keymaps
+ general for very minimal, required stuff
This commit is contained in:
Just Midi 2021-08-09 07:44:56 +00:00
commit 4989797e91
8 changed files with 622 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
plugins/*
.hidden/*

25
README.md Normal file
View File

@ -0,0 +1,25 @@
# Vim Config
My vim config written in lua designed for *smol boi minimal vibes*
Most of the code is in separate modules. Each will later be its own true plugin.
## OLD
### TODO
Remove colemak w/ opt-in
```sh
sh -c 'curl -fLo \
"${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
```
`pip3 install --user pynvim``
```vim
:PlugInstall
:UpdateRemotePlugins
```
> /usr/share/dict/words
Install `words`

3
init.lua Executable file
View File

@ -0,0 +1,3 @@
require('general')
require('keymap')
require('ui')

29
lua/general.lua Executable file
View File

@ -0,0 +1,29 @@
-- see `:help` for any questions
-- use `&<var>` to show value of vimscript variable
-- API --
local o = vim.o -- options
local go = vim.go -- only-global options
local bo = vim.bo -- buffer local options
local wo = vim.wo -- window local options
local cmd = vim.cmd -- vim commands
local fn = vim.fn -- vim functions
local opt = vim.opt -- vim option object
local g = vim.g -- global variables
local b = vim.b -- buffer local variables
local w = vim.w -- window local variables
local t = vim.t -- tab local variables
local v = vim.v -- variables
local env = vim.env -- environment variables
vim.g.mapleader = ' '
o.mouse = '' -- mouse off
bo.fileformat = 'unix'
o.hidden = true

6
lua/keymap/functional.lua Executable file
View File

@ -0,0 +1,6 @@
function bind(f,...)
local args={...}
return function(...)
return f(unpack(args),...)
end
end

331
lua/keymap/init.lua Executable file
View File

@ -0,0 +1,331 @@
-- see `:help` for any questions
-- use `&<var>` to show value of vimscript variable
require('keymap/functional')
-- API --
local o = vim.o -- options
local go = vim.go -- only-global options
local bo = vim.bo -- buffer local options
local wo = vim.wo -- window local options
local cmd = vim.cmd -- vim commands
local fn = vim.fn -- vim functions
local opt = vim.opt -- vim option object
local g = vim.g -- global variables
local b = vim.b -- buffer local variables
local w = vim.w -- window local variables
local t = vim.t -- tab local variables
local v = vim.v -- variables
local env = vim.env -- environment variables
local layouts = {
'qwerty',
'colemak'
}
local layout = layouts[2]
local map = vim.api.nvim_set_keymap
local function modes_map(modes)
local functions = {}
for _,mode in pairs(modes) do
table.insert(functions, bind(map,mode))
end
return functions
end
local function keys_modes_map(modes, new_keys, old_keys)
for i = 1, #new_keys do
for _,f in pairs(modes_map(modes)) do
f(new_keys[i], old_keys[i], {noremap = true})
end
end
end
local nvo = {'n','v','o'}
if layout == 'qwerty' then
--
-- Qwerty: General Bindings
--
-- Splits
for _,key in pairs({'j','k','l','J','K','L'}) do
for _,f in pairs(modes_map({'n', 'v'})) do
f('<Leader>w'..key, '<C-W>'..key, {noremap = true})
end
end
--
-- Qwerty: Plugin Bindings
--
-- NERDTree defaults
vim.g.NERDTreeMapOpenSplit = 'i' -- i
vim.g.NERDTreeMapPreviewSplit = 'I' -- gi
vim.g.NERDTreeMapJumpFirstChild = 'K' -- K
vim.g.NERDTreeMapJumpLastChild = 'J' -- J
vim.g.NERDTreeMapJumpNextSibling = '<C-j>' -- <C-J>.
vim.g.NERDTreeMapJumpPrevSibling = '<C-k>' -- <C-K>
vim.g.NERDTreeMapChangeRoot = 'l' -- C
-- see "All layout" bindings too
elseif layout == 'colemak' then
--
-- Colemak: General Bindings
--
-- Motion
-- up(e) down(n) left(h) right(i)
keys_modes_map(
nvo,
{'h','n','e','i'},
{'h','j','k','l'}
)
-- word(y) WORD(Y) back(l) BACK(L) end(u) END(U)
keys_modes_map(
nvo,
{'l','L','u','U','y','Y'},
{'b','B','e','E','w','W'}
)
-- (a)ppend (r)eplace in(s)ert change(w)
keys_modes_map(
{'n'},
{'s','S'}, -- see Visual Line Mode Patch
{'i','I'}
)
keys_modes_map(
nvo,
{'w','W'},
{'c','C'}
)
-- (c)opy (p)aste cut(x,d)
keys_modes_map(
nvo,
{'c','C'},
{'y','Y'}
)
-- (u)ndo (r)edo
local c_undo_redo = {'z','gz','Z'}
keys_modes_map(
{'n'},
c_undo_redo,
{'u','U','<C-R'}
)
local q_x_undo = ':<C-U>undo<CR>'
keys_modes_map(
{'x'},
c_undo_redo,
{
q_x_undo,
q_x_undo,
':<C-U>redo<CR>'
}
)
-- Visual Line Mode Patch
vim.cmd([[
xnoremap <silent> <expr> s (mode() =~# "[V]" ? "\<C-V>0o$I" : "I")
xnoremap <silent> <expr> S (mode() =~# "[V]" ? "\<C-V>0o$I" : "I")
]])
-- (g)oto
-- ge = visual line up
-- gn = visual line down
keys_modes_map(
nvo,
{'ge','gn'},
{'gk','gj'}
)
-- Search
-- (f)ind (F)ind (t)il (T)il next(k) prev(K)
keys_modes_map(
nvo,
{'k','K'},
{'n','N'}
)
-- Text Objects
-- inner(s) (a)
map('o', 's', 'i', {noremap = true})
-- Folds
keys_modes_map(
{'n','x'},
{'j','jn','je','jo','jc','ja'},
{'z','zn','ze','zo','zc','za'}
)
-- Help(B)
map('n', 'B', 'K', {noremap = true})
-- Splits
local split = {
colemak = {'n','e','i','N','E','I'},
qwerty = {'j','k','l','J','K','L'}
}
for i = 1, #split.colemak do
for _,f in pairs(modes_map({'n','v'})) do
f('<Leader>w'..split.colemak[i], '<C-W>'..split.qwerty[i], {noremap = true})
end
end
-- Screen / Scroll / Page
-- H = top screen
-- M = mid screen
-- I = bottom screen
-- E = half page up
-- N = half page down
keys_modes_map(
{'n','v'},
{'I','E', 'N'},
{'L','<C-U>','<C-D>'}
)
--
-- Colemak: Plugin Bindings
--
-- NERDTree defaults
vim.g.NERDTreeMapOpenSplit = 's' -- i
vim.g.NERDTreeMapPreviewSplit = 'S' -- gi
vim.g.NERDTreeMapJumpFirstChild = 'E' -- K
vim.g.NERDTreeMapJumpLastChild = 'N' -- J
vim.g.NERDTreeMapJumpNextSibling = '<C-n>' -- <C-J>.
vim.g.NERDTreeMapJumpPrevSibling = '<C-e>' -- <C-K>
vim.g.NERDTreeMapChangeRoot = 'i' -- C
-- see "All layout" bindings too
end
--
-- All layouts: General Bindings
--
-- Splits
for _,key in pairs({'h','H','t','q',''}) do
for _,f in pairs(modes_map({'n', 'v'})) do
if key ~= 't' then
f('<Leader>w'..key, '<C-W>'..key, {noremap = true})
else
f('<Leader>wt', '<C-W>T', {noremap = true})
end
end
end
-- Search
keys_modes_map(
{'n','v'},
{'/', '?'},
{'q/i','q?i'}
)
-- Remove left over search highlights
map('n', '<Leader><space>', ':nohlsearch<CR>', {noremap = true})
-- Move current line to center of screen
map('n', '<Leader>m', 'z.', {noremap = true})
-- Buffers
local buffer_keys = {
new = {'<tab>','<S-tab','<BS>'},
old = {'n', 'p', 'd'}
}
for i = 1, #buffer_keys.new do
for _,f in pairs(modes_map({'n','v','x'})) do
f(
'<Leader>'..buffer_keys.new[i],
':b'..buffer_keys.old[i]..'<CR>',
{noremap = true}
)
end
end
-- Command mode
keys_modes_map(
{'n', 'v', 'x'},
{':', ';;', ';e', ';h', ';v'},
{'q:i','q:i!','q:ie term://','q:isp term://','q:ivs term://'}
)
-- Filetype specific
cmd('autocmd FileType zig lua zig_maps()')
function zig_maps()
map('n', '<Leader>ft', ':vertical !zig test %<CR>', {noremap = true})
map('n', '<Leader>fr', ':vertical !zig run %<CR>', {noremap = true})
end
--
-- All layouts: Plugin Bindings
--
-- LSP
function lsp_shortcuts()
local lsp_commands = {
new = {'d','r','f','t','x','a','c','C','h','s','m'},
old = {
'#textDocument_definition', -- d
'#textDocument_rename', -- r
'#textDocument_formatting', -- f
'#textDocument_typeDefinition', -- t
'#textDocument_references', -- x
'_workspace_applyEdit', -- a
'#textDocument_completion', -- c
'#textDocument_codeAction', -- C
'#textDocument_hover', -- h
'_textDocument_documentSymbol', -- s
'_contextMenu' -- m
}
}
for i = 1, #lspcommands.new do
for _,f in pairs(modes_map({'n'})) do
f('<Leader>l'..key_pair.new[i],
':call LanguageClient'..key_pair.old[i]..'()<CR>', {noremap = true})
end
end
end
-- NERDTree defaults
map('n', '<Leader>n', ':NERDTree<CR>', {noremap = true})
vim.g.NERDTreeMapActivateNode = 'o' -- o
vim.g.NERDTreeMapPreview = 'go' -- go
vim.g.NERDTreeMapOpenInTab = 't' -- t
vim.g.NERDTreeMapOpenInTabSilent = 'T' -- T
vim.g.NERDTreeMapOpenVSplit = 'v' -- s
vim.g.NERDTreeMapPreviewVSplit = 'V' -- gs
vim.g.NERDTreeMapCustomOpen = '<CR>' -- <CR>
vim.g.NERDTreeMapOpenRecursively = 'O' -- O
vim.g.NERDTreeMapCloseDir = 'x' -- x
vim.g.NERDTreeMapCloseChildren = 'X' -- X
vim.g.NERDTreeMapOpenExpl = '<C-o>' -- e
vim.g.NERDTreeMapDeleteBookmark = 'd' -- D
vim.g.NERDTreeMapJumpRoot = 'P' -- P
vim.g.NERDTreeMapJumpParent = 'p' -- p
vim.g.NERDTreeMapUpdir = 'h' -- u
vim.g.NERDTreeMapUpdirKeepOpen = 'H' -- U
vim.g.NERDTreeMapRefresh = 'r' -- r
vim.g.NERDTreeMapRefreshRoot = 'R' -- R
vim.g.NERDTreeMapMenu = 'm' -- m
vim.g.NERDTreeMapChdir = 'c' -- cd
vim.g.NERDTreeMapCWD = 'C' -- CD
vim.g.NERDTreeMapToggleHidden = '.' -- I
vim.g.NERDTreeMapToggleFilters = 'F' -- f
vim.g.NERDTreeMapToggleFiles = 'f' -- F
vim.g.NERDTreeMapToggleBookmarks = 'b' -- B
vim.g.NERDTreeMapQuit = 'q' -- q
vim.g.NERDTreeMapToggleZoom = 'z' -- A
vim.g.NERDTreeMapHelp = '?' -- ?
-- Limelight
map('n', '<Leader>ul', ':call LimelightToggle()<CR>', {noremap = true})
-- Transparent
map('n', '<Leader>ut', ':TransparentToggle<CR>', {noremap = true})

113
lua/ui/init.lua Executable file
View File

@ -0,0 +1,113 @@
-- see `:help` for any questions
-- use `&<var>` to show value of vimscript variable
require('ui/statusbar')
-- API --
local o = vim.o -- options
local go = vim.go -- only-global options
local bo = vim.bo -- buffer local options
local wo = vim.wo -- window local options
local cmd = vim.cmd -- vim commands
local fn = vim.fn -- vim functions
local opt = vim.opt -- vim option object
local g = vim.g -- global variables
local b = vim.b -- buffer local variables
local w = vim.w -- window local variables
local t = vim.t -- tab local variables
local v = vim.v -- variables
local env = vim.env -- environment variables
o.showcmd = true
wo.cursorline = true
cmd 'filetype plugin indent on'
o.lazyredraw = true
o.showmatch = true -- matching bracket
-- Completion Menu
o.wildmenu = true
o.wildmode = 'list:longest,full'
-- Character Representation
o.sbr = '' -- line wrap character
o.list = true
opt.listchars = { -- white space representation
tab = '',
trail = '',
nbsp = '',
extends = '',
precedes = ''
}
-- Hybrid Numbers
function hybrid_numbers(x)
wo.number = true
wo.relativenumber = x
end
cmd([[
autocmd BufEnter,FocusGained,InsertLeave * lua hybrid_numbers(true)
autocmd BufLeave,FocusLost,InsertEnter * lua hybrid_numbers(false)
]])
-- Search
o.incsearch = true -- show matching patterns
o.hlsearch = true -- highlight all patterns
-- Status Bar
o.laststatus = 2 -- always visible
vim.o.statusline = "%!luaeval('status_bar()')"
-- Tabs
local indent_size = 4 --change to filetype
opt.expandtab = true -- tab key inserts spaces
opt.tabstop = indent_size
opt.shiftwidth = indent_size
opt.softtabstop = 0 -- to disable
opt.smarttab = true
--adjust to filetype
function no_ro_retab()
if vim.inspect(opt.readonly:get()) == false then
cmd '%retab'
end
end
cmd 'autocmd BufReadPost,BufWritePre,BufWritePost,BufNewFile * lua no_ro_retab()'
-- Text Width
wo.wrap = true
wo.linebreak = true
bo.textwidth = 70
bo.formatoptions = table.concat({
'j', -- remove comment when joining lines
'w', -- non-white space at end of line means end of paragraph
'c', -- insert comment when auto wrapping textwidth
'r', -- insert comment after hitting <enter>
'o', -- insert comment after hitting "o"
'q', -- format comments with "gq"
'l' -- long lines are not broken in insert mode
})
cmd([[
autocmd BufEnter * highlight OverLength ctermbg=darkgrey guibg=#592929
autocmd BufEnter * match OverLength /\%71v.*/
]]) --rewrite in lua
--WIP
-- Filetype: txt, md, tex
-- break lines, autowrap, autoformat, recognize numbered lists
--fix before enabling
--autocmd BufRead,BufNewFile *.md,*.txt,*.tex set fo-=l
--autocmd BufRead,BufNewFile *.md,*.txt,*.tex set fo+=tan

113
lua/ui/statusbar.lua Executable file
View File

@ -0,0 +1,113 @@
-- see `:help` for any questions
-- use `&<var>` to show value of vimscript variable
-- API --
local o = vim.o -- options
local go = vim.go -- only-global options
local bo = vim.bo -- buffer local options
local wo = vim.wo -- window local options
local cmd = vim.cmd -- vim commands
local fn = vim.fn -- vim functions
local opt = vim.opt -- vim option object
local g = vim.g -- global variables
local b = vim.b -- buffer local variables
local w = vim.w -- window local variables
local t = vim.t -- tab local variables
local v = vim.v -- variables
local env = vim.env -- environment variables
--Later generalize into plugin
-- read from bottom up to understand `status_bar()`
local function file_state()
if vim.bo.modified then
return "+"
elseif vim.bo.readonly then
return "-"
end
return ""
end
local function diagnostics()
local buffer_number = vim.fn.bufnr('%')
local severity_levels = {
-- level,prefix
errors = {'Error', 'E:'},
warnings = {'Warning', 'W:'},
info = {'Information', 'I:'},
hints = {'Hint', 'H:'}
}
local out = ''
for _,v in pairs(severity_levels) do
local d = vim.lsp.diagnostic.get_count(
buffer_number,
v[1] -- level
)
if d > 0 then
out = out .. v[2] .. d .. ' '
end
end
return out
end
local function highlight(group, color)
cmd('highlight ' .. group .. ' cterm='..color .. ' gui='..color)
end
highlight('StatusLine', 'bold,reverse')
highlight('StatusLineDark', 'bold')
local light_highlight = '%#StatusLine#'
local dark_highlight = '%#StatusLineDark#'
function section(items)
local out = ''
for _,item in pairs(items) do
if item ~= '' and item ~= nil then
if out == '' then
out = item
else
out = out .. ' | ' .. item
end
end
end
return ' ' .. out .. ' '
end
function sections(items)
local out = {}
local n = 1
for _,item in pairs(items) do
if item == '%=' then
table.insert(out, item)
n = 1 -- reset coloring at different parts
else
if (n % 2) == 1 then
table.insert(out, light_highlight..section(item))
else
table.insert(out, dark_highlight..section(item))
end
n = n + 1
end
end
return out
end
function status_bar()
return table.concat(sections({
-- Stage Left
{'%f', file_state()},
{diagnostics()},
'%=',
-- Stage Right
{
vim.b.gitsigns_status,
vim.bo.filetype
},
{'%p%%'},
{'%c,%l'}
}))
end