repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

adds custom tabline to nvim

bcb0237627827168bb789784de18a636a9b97097

Oliver Krylow <o.krylow@isp-insoft.de> ·

unsigned

Browse filesCompare with HEAD

Changed files (7)

indexa/config.windows.toml

Modified
90 90 # Remaining screen width is evenly distributed among other columns.
91 91 [[ui.columns]]
92 92 status = "basename"
93 -width = 12
95 -[[ui.columns]]
96 -status = "size"
97 -width = 10
99 94 [[ui.columns]]
100 95 status = "modified"

neovim/init.lua

Modified
15 15 -- are a pain in the butt right now.
16 16 -- That is why we invent our own abstractions over the current API.
17 17 -- These roughly emulate what we are used to from Vimscript:
18 --- - options => use metaaccessors: vim.o, vim.bo, vim.wo
18 +-- - options => use vim.opt and metaaccessors: vim.o, vim.bo, vim.wo
19 19 -- - commands => use function vim.cmd
20 20 -- - autocommands => use module `autocommand`
21 21 -- - highlights and groups => use plugin colorbuddy
23 --- import `dump` into the global namespace, so that we can use it in a running vim instance: `:lua dump(vim.fn)`
24 -_G.dump = require("dump")
23 +-- import `dump` into the global namespace, so that we can use it in a running vim instance: `:lua Dump(vim.fn)`
24 +Dump = require("dump")
25 25 -- Define some standard path locations where we will put stuff into.
26 26 -- `data` is for persistent data like logs, backups and file states.
27 27 -- `config` is for configuration code itself and plugins.
35 35 -- My cheatsheet is an initial buffer (if none was specified) where I put stuff to remember/learn.
36 36 -- Keybinds, commands, todos are all fair game.
37 37 local cheatsheet, setup_cheatsheet = require("cheatsheet")()
38 --- make cheatsheet globally available for easy access in plugins configurations blocks of packer
39 -_G.cheatsheet = cheatsheet
40 38 cheatsheet("")
41 39 cheatsheet("Stuff for bugabinga to remember about NeoVim")
42 40 cheatsheet("")
43 41 local settings = require("general_editor_settings")
44 42 settings(autocommand, data_path)
45 --- when started with '--headless', there will be no attached UIs
46 -local non_interactive = #vim.api.nvim_list_uis() == 0
47 --- Put the plugins module into the global scope, so that it can be used more easily in commands
48 -_G.plugins = require("plugins")(data_path, non_interactive)
49 44 -- setup my own keybindings
50 45 require("keybinds")(cheatsheet)
55 50 local _, setup_mkdir = require("mkdir")()
56 51 setup_mkdir(autocommand)
58 -cheatsheet(
59 - ":TSHighlightCapturesUnderCursor => This command shows the highlight group under the cursor, when TreeSitter is used"
60 -)
53 +-- Load nvim plugins
54 +-- when started with '--headless', there will be no attached UIs
55 +local non_interactive = #vim.api.nvim_list_uis() == 0
56 +-- Load the plugins module into the global namespace in order to reference them later in keymaps
57 +Plugins = require("plugins")(data_path, non_interactive)
62 59 -- Lazy load the plugin manager packer, when using these commands
63 60 -- cheatsheet':PluginsInstall => Install the specified plugins if they are not already installed'
64 -vim.cmd([[command! PluginsInstall packadd packer.nvim | lua plugins.install()]])
61 +vim.cmd([[command! PluginsInstall packadd packer.nvim | lua Plugins.install()]])
66 62 -- cheatsheet':PluginsUpdate => Update the specified plugins, installing any that are missing'
67 -vim.cmd([[command! PluginsUpdate packadd packer.nvim | lua plugins.update()]])
63 +vim.cmd([[command! PluginsUpdate packadd packer.nvim | lua Plugins.update()]])
69 64 cheatsheet(":PluginsSync => Perform a clean followed by an update")
70 -vim.cmd([[command! PluginsSync packadd packer.nvim | lua plugins.sync()]])
65 +vim.cmd([[command! PluginsSync packadd packer.nvim | lua Plugins.sync()]])
72 66 -- cheatsheet':PluginsClean => Remove any disabled or no longer managed plugins'
73 -vim.cmd([[command! PluginsClean packadd packer.nvim | lua plugins.clean()]])
67 +vim.cmd([[command! PluginsClean packadd packer.nvim | lua Plugins.clean()]])
75 68 -- cheatsheet':PluginsCompile => Compile lazy-loader code and save to path'
76 -vim.cmd([[command! PluginsCompile packadd packer.nvim | lua plugins.compile()]])
69 +vim.cmd([[command! PluginsCompile packadd packer.nvim | lua Plugins.compile()]])
78 70 cheatsheet(":PluginsProfile => Show the measured startup times of plugins")
79 -vim.cmd([[command! PluginsProfile packadd packer.nvim | lua plugins.profile_output()]])
71 +vim.cmd([[command! PluginsProfile packadd packer.nvim | lua Plugins.profile_output()]])
72 +vim.cmd([[command! PluginsStatus packadd packer.nvim | lua Plugins.status()]])
81 -vim.cmd([[command! PluginsStatus packadd packer.nvim | lua plugins.status()]])
74 +autocommand({
75 + compile_lazy_plugin_loading_script_on_save = "BufWritePost plugins.lua source <afile> | PluginsCompile",
76 +})
78 +cheatsheet("")
79 +cheatsheet("Drawing ASCII diagrams with venn.nvim:")
80 +cheatsheet("Activate visual edit: `:set virtualedit=all`")
81 +cheatsheet("Select blocks: `<C-v>`")
82 +cheatsheet("Invoke `:Vbox`")
83 84 -- Should be the last call
84 85 setup_cheatsheet()

neovim/lua/filetype/ansi_c.lua

Modified
1 1 return function(autocommand)
2 - autocommand{ setup_build_for_dotfiles_boottripper = [[ BufRead bootstripper.c set makeprg=../build.bat ]]}
3 2 end

neovim/lua/general_editor_settings.lua

Modified
9 9 -- show status line and tabline
10 10 vim.opt.laststatus = 2
11 11 vim.opt.showtabline = 2
12 + -- set tabline to a custom rendering
13 + vim.opt.tabline = [[%!v:lua.require'tabline'()]]
12 14 -- convert tabs to spaces
13 15 vim.opt.expandtab = true
14 16 -- Keep indentation of new lines in line with previuos lines

neovim/lua/keybinds.lua

Modified
4 4 -- Set up all my favorite keybindings and list them in my cheatsheet.
5 5 -- This module assumes a lot of pre configured state, i.e. already installed and enabled plugins.
6 6 -- The benefit of assembling all keybinds here is, that they are easy to find.
7 7 -- But unfortunataly, by collecting them here, they are placed "far" from their logical place, i.e. the plugins configuration.
8 8 return function(cheatsheet)
9 9 -- Delegator over nvim_set_keymap, that sets some default options
10 + -- TODO expose this function as module
10 11 local map = function(mode, left_hand_side, right_hand_side, options)
11 12 local default_options = { noremap = true, unique = true }
12 13 if options then
20 21 map("n", "<LEADER><F10>", [[<CMD>PluginsSync<CR>]])
21 22 cheatsheet("LEADER + F10 => Sync nvim plugins configuration!")
23 - -- Change behaviour of :terminal to be less like a vim buffer and more what I am used to
24 - map("t", "<ESC>", "<C-\\><C-n>")
25 - map("t", "<C-w>", "<ESC><C-w>")
27 - -- Clear highlighted search results whenever ESC is hit
28 - map("n", "<ESC>", ":nohlsearch<CR>", { unique = false, silent = true })
30 - map("n", "<LEADER>t", [[<CMD>Telescope tabs<CR>]])
31 - cheatsheet("LEADER + t => Select a tab")
33 24 map("n", "<LEADER>b", [[<CMD>Telescope buffers<CR>]])
34 25 cheatsheet("LEADER + b => Select a buffer")
39 30 map("n", "<LEADER>e", [[<CMD>NvimTreeToggle<CR>]])
40 31 cheatsheet("LEADER + e => Toggle file explorer")
33 + map("n", "<LEADER>t", [[<CMD>TroubleToggle<CR>]])
34 + cheatsheet("LEADER + t => Toggle the Trouble window.")
36 + cheatsheet("")
42 38 --Open up a URL under the cursor
43 39 local opener_program = ""
54 50 map("n", "gx", [[<CMD>lua require'spawn'(']] .. opener_program .. [[',{ vim.fn.expand('<cfile>') } )<CR>]])
55 51 cheatsheet("gx => Open URL under cursor")
57 - cheatsheet("<ALT>j => Move line(s) down")
58 - cheatsheet("<ALT>k => Move line(s) up")
53 + cheatsheet("")
54 + cheatsheet("ALT + j => Move line(s) down")
55 + cheatsheet("ALT + k => Move line(s) up")
59 56 map("n", "<A-j>", [[<CMD>move .+1<CR>==]])
60 57 map("n", "<A-k>", [[<CMD>move .-2<CR>==]])
61 58 map("i", "<A-j>", [[<ESC><CMD>move .+1<CR>==gi]])
62 59 map("i", "<A-k>", [[<ESC><CMD>move .-2<CR>==gi]])
63 60 map("x", "<A-j>", [[<ESC><CMD>'<,'>move'>+1<CR>gv=gv]])
64 61 map("x", "<A-k>", [[<ESC><CMD>'<,'>move'<-2<CR>gv=gv]])
63 + -- Change behaviour of :terminal to be less like a vim buffer and more what I am used to
64 + map("t", "<ESC>", "<C-\\><C-n>")
65 + map("t", "<C-w>", "<ESC><C-w>")
67 + -- Clear highlighted search results whenever ESC is hit
68 + map("n", "<ESC>", ":nohlsearch<CR>", { unique = false, silent = true })

neovim/lua/plugins.lua

Modified
30 30 open_fn = require("packer.util").float,
32 32 profile = {
33 - enable = true,
33 + enable = false,
34 34 threshold = 1, -- the amount in ms that a plugins load time must be over for it to be included in the profile
131 131 -- Show the treesitter parse tree.
132 132 -- Lint syntax errors
133 133 -- Show highlight groupsunder cursor
134 - use({ "nvim-treesitter/playground" })
134 + use({
135 + "nvim-treesitter/playground",
136 + config = function()
137 + local cheatsheet = require("cheatsheet")
138 + cheatsheet(
139 + ":TSHighlightCapturesUnderCursor => This command shows the highlight group under the cursor, when TreeSitter is used"
141 + end,
142 + })
136 144 -- Basic integration of ziglang
137 145 use({ "ziglang/zig.vim", opt = true, ft = "zig" })
226 + -- ASCII diagram drawing
227 + use({
228 + "jbyuki/venn.nvim",
229 + opt = true,
230 + command = "VBox",
231 + })
218 234 -- the plugin module always delegates to packer, ensuring that at all times init configures packer correctly
219 235 local plugins = setmetatable({}, {
220 236 __index = function(_, key)

neovim/lua/tabline.lua

Added
new file mode 100644
1 +return function()
2 + local buffer_names_to_ignore = {"NvimTree"}
3 + local get_icon = function(name, extension)
4 + if pcall(require, "nvim-web-devicons") then return require"nvim-web-devicons".get_icon(name ,extension, {default=true}) end
5 + return ""
6 + end
7 + local tabline = ""
8 + for _, buffer_number in pairs(vim.api.nvim_list_bufs()) do
9 + if vim.api.nvim_buf_is_valid(buffer_number) and vim.api.nvim_buf_is_loaded(buffer_number) then
10 + local modified = vim.bo.modified and "" or " "
11 + -- we only care about the last part of the path
12 + local stylish_buffer_name = vim.api.nvim_buf_get_name(buffer_number):match(".-([^\\/]-)$") or ""
13 + if vim.tbl_contains(buffer_names_to_ignore, stylish_buffer_name) then goto continue end
14 + local icon = ""
15 + if stylish_buffer_name == "" then
16 + stylish_buffer_name = "no name"
17 + icon = ""
18 + elseif stylish_buffer_name == "cheatsheet" then
19 + icon = ""
20 + else
21 + local extension = stylish_buffer_name:match("%w+%.(.+)")
22 + icon = get_icon(stylish_buffer_name, extension)
23 + end
24 + stylish_buffer_name = " " .. stylish_buffer_name .. " "
25 + local is_current_buffer = vim.api.nvim_get_current_buf() == buffer_number
26 + tabline = tabline .. "%#TabLine" ..
27 + (is_current_buffer and "Sel" or "") .. "#" ..
28 + " " .. icon .. stylish_buffer_name .. (is_current_buffer and modified or " ")
29 + end
30 + -- goto here to return early from one iteration step of the for loop
31 + ::continue::
32 + end
33 + return tabline .. "%#TabLineFill#"
34 +end