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:
commit
4989797e91
8 changed files with 622 additions and 0 deletions
113
lua/ui/init.lua
Executable file
113
lua/ui/init.lua
Executable 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
113
lua/ui/statusbar.lua
Executable 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
|
Loading…
Add table
Add a link
Reference in a new issue