repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

refactored to use `vim.opt` API

0db40d19f395ff05cf6b8b6b4845d081a940a80f

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

unsigned

Browse filesCompare with HEAD

Changed files (7)

neovim/init.lua

Modified
29 29 -- `config` is for configuration code itself and plugins.
30 30 -- `cache` is for fleeting, temporary data.
31 31 local data_path = vim.fn.stdpath 'data'
32 -local config_path = vim.fn.stdpath 'config'
33 -local cache_path = vim.fn.stdpath 'cache'
32 +-- local config_path = vim.fn.stdpath 'config'
33 +-- local cache_path = vim.fn.stdpath 'cache'
35 35 local autocommand = require 'autocommand'
43 43 cheatsheet 'Stuff for bugabinga to remember about NeoVim'
44 44 cheatsheet ''
45 45 local settings = require 'general_editor_settings'
46 -settings(cheatsheet, autocommand, data_path)
46 +settings(autocommand, data_path)
47 47 -- when started with '--headless', there will be no attached UIs
48 48 local non_interactive = #vim.api.nvim_list_uis() == 0
49 49 -- Put the plugins module into the global scope, so that it can be used more easily in commands
52 52 require 'keybinds'(cheatsheet)
54 54 -- some file specific settings
55 -require'filetype.yaml'(autocommand)
56 -require'filetype.ansi_c'(autocommand)
55 +require 'filetype.yaml'(autocommand)
56 +require 'filetype.ansi_c'(autocommand)
57 +local _, setup_mkdir = require 'mkdir'()
58 +setup_mkdir(autocommand)
58 60 -- Commands have no nvim API yet, so we use vimscript...
59 61 cheatsheet ':WhatHighlight => This command shows the highlight group under the cursor'

neovim/lua/general_editor_settings.lua

Modified
1 1 -- This function sets up neovim with general configuration options.
2 2 -- "General" means, valid for all use-cases, file types etc.
3 -return function(_, autocommand, data_path)
4 - -- nvim lacks the vimscript equivalent of ":set".
5 - -- "set" does automagic, when setting non-global options,
6 - -- which we try to replicate here.
7 - local _scopes = { global = vim.o, window = vim.wo, buffer = vim.bo }
8 - local set = function(scope, key, value)
9 - -- first, set the option in the given scope
10 - _scopes[scope][key] = value
11 - -- then, if the option was not global, also set it globally.
12 - -- otherwise buffer options only apply to the current buffer.
13 - if scope ~= 'global' then
14 - _scopes['global'][key] = value
15 - end
16 - end
3 +return function(autocommand, data_path)
17 4 -- Setting the width of the tab character to 2
18 5 local tab_size = 2
19 - set('buffer', 'tabstop', tab_size)
20 - set('buffer', 'shiftwidth', tab_size)
21 - set('buffer', 'softtabstop', tab_size)
6 + vim.opt.tabstop = tab_size
7 + vim.opt.shiftwidth = tab_size
8 + vim.opt.softtabstop = tab_size
22 9 -- convert tabs to spaces
23 - set('buffer', 'expandtab', true)
10 + vim.opt.expandtab = true
24 11 -- Keep indentation of new lines in line with previuos lines
25 - set('buffer', 'autoindent', true)
26 - set('buffer', 'copyindent', true)
27 - set('buffer', 'smartindent', true)
12 + vim.opt.autoindent = true
13 + vim.opt.copyindent = true
14 + vim.opt.smartindent = true
15 + -- Do not display the cursorposition, since it can be shown when necesary 'g <C-G>'
16 + vim.opt.ruler = false
17 + -- How many milliseconds must pass before neovim decides I was "idle"
18 + vim.opt.updatetime = 250
19 + -- How long to wait between key sequences in order to chain them. e.g. <LEADER>b
20 + vim.opt.timeoutlen = 350
29 21 -- I do not care for folding
30 - set('window', 'foldenable', false)
31 - set('window', 'cursorline', true)
22 + vim.opt.foldenable = false
23 + vim.opt.cursorline = true
32 24 -- Highlight the cursor line in the current buffer
33 25 autocommand {
34 26 show_cursor_line_in_active_window = {
35 - [[WinLeave * set nocursorline]],
36 - [[WinEnter * set cursorline]],
37 - [[InsertEnter * set nocursorline]],
38 - [[InsertLeave * set cursorline]],
27 + [[WinLeave * lua vim.opt.cursorline = false]],
28 + [[WinEnter * lua vim.opt.cursorline = true]],
29 + [[InsertEnter * lua vim.opt.cursorline = false]],
30 + [[InsertLeave * lua vim.opt.cursorline = true]],
42 33 -- integrate Powershell Core with nvim
43 - set('global', 'shell', 'powershell')
44 - set('global', 'shellquote', '')
45 - set('global', 'shellxquote', '')
46 - set(
47 - 'global',
48 - 'shellcmdflag',
49 - '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command'
50 - )
51 - set('global', 'shellredir', '| Out-File -Encoding UTF8')
52 - set('global', 'shellpipe', '| Out-File -Encoding UTF8')
34 + vim.opt.shell = 'powershell'
35 + vim.opt.shellquote = ''
36 + vim.opt.shellxquote = ''
37 + vim.opt.shellcmdflag = '-NoLogo -NoProfile -NonInteractive -ExecutionPolicy RemoteSigned -Command'
38 + vim.opt.shellredir = '| Out-File -Encoding UTF8'
39 + vim.opt.shellpipe = '| Out-File -Encoding UTF8'
53 40 -- insert whitespace type based on whitespace on previous line
54 - set('global', 'smarttab', true)
55 - set('global', 'hlsearch', true)
56 - set('global', 'ignorecase', true)
57 - set('global', 'smartcase', true)
58 - set('global', 'incsearch', true)
59 - set('global', 'showmatch', true)
60 - set('global', 'hidden', true)
41 + vim.opt.smarttab = true
42 + vim.opt.hlsearch = true
43 + vim.opt.ignorecase = true
44 + vim.opt.smartcase = true
45 + vim.opt.incsearch = true
46 + vim.opt.showmatch = true
47 + vim.opt.hidden = true
61 48 -- Show the effects of substitutions incrementally
62 - set('global', 'inccommand', 'nosplit')
49 + vim.opt.inccommand = 'nosplit'
63 50 -- enable mouse support, in a terminal app... i know crazy...
64 - set('global', 'mouse', 'a')
51 + vim.opt.mouse = 'a'
52 + -- use ripgrep instead of grep
53 + vim.opt.grepprg = 'rg --vimgrep --no-heading --smart-case'
54 + vim.opt.grepformat = '%f:%1:%c:%m'
65 55 -- Show certain whitespace characters
66 - set('window', 'list', true)
67 - set(
68 - 'global',
69 - 'listchars',
70 - 'tab:⯈ ,trail: ,nbsp:␠,extends:⋯,precedes:⋯,space:⸱'
71 - )
72 - set('global', 'scrolloff', 3)
56 + vim.opt.listchars = { tab='⯈ ',trail=' ',nbsp='␠',extends='⋯',precedes='⋯',space='⸱' }
57 + vim.opt.scrolloff = 3
58 + -- make navigation from start of line to end of previous line more natural
59 + vim.opt.whichwrap:append('<>hl')
73 60 -- do not spam the cmdline with every little input
74 - set('global', 'showcmd', false)
75 - set('global', 'wildmode', 'list:longest')
61 + vim.opt.showcmd = false
62 + vim.opt.wildmode = 'list:longest'
76 63 -- Set the current working directory to the parent of the active buffer
77 - set('global', 'autochdir', true)
64 + vim.opt.autochdir = true
78 65 -- Keep track of file changes outside of vim
79 - set('global', 'autoread', true)
66 + vim.opt.autoread = true
80 67 -- Make backups of all touched files in a special directory
81 - set('global', 'backup', true)
82 - set('global', 'writebackup', true)
83 - set('global', 'backupcopy', 'auto')
68 + vim.opt.backup = true
69 + vim.opt.writebackup = true
70 + vim.opt.backupcopy = 'auto'
84 71 -- The magic slash at the end is important.
85 72 -- It tells vim to use the absolute path in encoded form as the backup file
86 73 -- name.
87 - set('global', 'backupdir', data_path .. '/backup/')
88 - local global = vim.o
89 - if vim.fn.empty(vim.fn.glob(global.backupdir)) > 0 then
90 - vim.cmd('!mkdir ' .. global.backupdir)
74 + vim.opt.backupdir = data_path .. '/backup/'
75 + if vim.fn.empty(vim.fn.glob(vim.o.backupdir)) > 0 then
76 + vim.fn.mkdir(vim.o.backupdir, 'p')
92 78 autocommand {
93 - backup_timestamp = [[BufWritePre * let &backupext = '@' . strftime("%F.%H:%M") . '.bak']],
79 + backup_timestamp = [[BufWritePre * lua vim.opt.backupext = '@' .. vim.fn.strftime("%F.%H:%M") .. '.bak']],
95 81 -- set global swap directory, so that swap files do not pollute my workspace
96 - set('global', 'directory', data_path .. '/swap/')
82 + vim.opt.directory = data_path .. '/swap/'
97 83 -- persit undo states across vim restarts
98 - set('buffer', 'undofile', true)
99 - set('global', 'undodir', data_path .. '/undo/')
84 + vim.opt.undofile = true
85 + vim.opt.undodir = data_path .. '/undo/'
100 86 -- ask me to force failed commands
101 - set('global', 'confirm', true)
102 - set('global', 'completeopt', 'menuone,noinsert,noselect')
87 + vim.opt.confirm = true
88 + vim.opt.completeopt = {'menuone', 'noinsert', 'noselect'}
103 89 -- avoid showing messages during automomplete
104 - set('global', 'shortmess', global.shortmess .. 'c')
90 + vim.opt.shortmess:append('c')
105 91 -- open splits below and to the right of current buffers
106 - set('global', 'splitbelow', true)
107 - set('global', 'splitright', true)
92 + vim.opt.splitbelow = true
93 + vim.opt.splitright = true
94 + -- always show the signcolumn, because i don't like jumpy UIs
95 + vim.opt.signcolumn = 'yes'
108 96 -- Use true colors
109 - set('global', 'termguicolors', true)
110 - set('global', 'guifont', 'BlexMono NF:h13:1')
97 + vim.opt.termguicolors = true
98 + vim.opt.lazyredraw = true
99 + vim.opt.guifont = 'BlexMono NF:h13:1'
111 100 -- Set cursor position to last known position, when entering a window
112 101 autocommand {
113 102 restore_cursor_position = [[ BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif ]],
119 108 [[TermClose,TermLeave * stopinsert]],
111 + -- briefly highlight yanked text
112 + autocommand {
113 + highlight_yanked_text = [[TextYankPost * silent! lua vim.highlight.on_yank()]],
122 115 -- Disable some built-in plugins we don't want
123 116 local disabled_built_ins = {
124 117 'gzip',
126 119 'matchit',
127 120 'matchparen',
128 121 'shada_plugin',
129 - 'tarPlugin',
130 122 'tar',
131 - 'zipPlugin',
123 + 'tarPlugin',
132 124 'zip',
125 + 'zipPlugin',
126 + 'netrw',
133 127 'netrwPlugin',
128 + 'spec',
129 + '2html_plugin',
135 131 for _, built_in in ipairs(disabled_built_ins) do
136 132 vim.g['loaded_' .. built_in] = 1
138 - -- briefly highlight yanked text
139 - autocommand {
140 - highlight_yanked_text = [[TextYankPost * silent! lua vim.highlight.on_yank()]],
141 - }
142 - -- use ripgrep instead of grep
143 - set('global', 'grepprg', [[rg --vimgrep --no-heading --smart-case]])
144 - set('global', 'grepformat', '%f:%1:%c:%m')

neovim/lua/keybinds.lua

Modified
19 19 -- Let the <LEADER> key be <SPACE>
20 20 vim.g.mapleader = ' '
22 - map('n', '<LEADER><F12>', [[:lua require('glow').glow('<f-args>')<CR>]])
22 + map('n', '<LEADER><F12>', [[<CMD>lua require('glow').glow('<f-args>')<CR>]])
23 23 cheatsheet 'LEADER + F12 => Render Markdown Preview'
25 - map('n', '<LEADER><F9>', [[:tabnew ~/.config/nvim/init.lua<CR>]])
25 + map('n', '<LEADER><F9>', [[<CMD>tabnew ~/.config/nvim/init.lua<CR>]])
26 26 cheatsheet 'LEADER + F9 => Open nvim configuration in a new tab!'
28 + map('n', '<LEADER><F10>', [[<CMD>PluginsSync<CR>]])
29 + cheatsheet 'LEADER + F10 => Sync nvim plugins configuration!'
28 31 -- Change behaviour of :terminal to be less like a vim buffer and more what I am used to
29 32 map('t', '<ESC>', '<C-\\><C-n>')
30 33 map('t', '<C-w>', '<ESC><C-w>')
32 35 -- Clear highlighted search results whenever ESC is hit
33 36 map('n', '<ESC>', ':nohlsearch<CR>', { unique = false, silent = true })
35 - map('n', '<LEADER>b', [[:Telescope buffers<CR>]])
38 + map('n', '<LEADER>b', [[<CMD>Telescope buffers<CR>]])
36 39 cheatsheet 'LEADER + b => Select a buffer'
37 - map('n', '<LEADER>f', [[:Telescope file_browser<CR>]])
40 + map('n', '<LEADER>f', [[<CMD>Telescope file_browser<CR>]])
38 41 cheatsheet 'LEADER + f => Select a file'
39 - map('n', '<LEADER>e', [[:NvimTreeToggle<CR>]])
42 + map('n', '<LEADER>e', [[<CMD>NvimTreeToggle<CR>]])
40 43 cheatsheet 'LEADER + e => Toggle file explorer'
42 45 --Open up a URL under the cursor

neovim/lua/lsp.lua

Modified
23 23 local map = function(type, key, value)
24 24 vim.api.nvim_buf_set_keymap(buffer_number,type,key,value,{noremap = true, silent = true});
26 - map('n','gD','<CMD>lua vim.lsp.buf.declaration()<CR>')
27 - map('n','gd','<CMD>lua vim.lsp.buf.definition()<CR>')
28 - map('n','K','<CMD>lua vim.lsp.buf.hover()<CR>')
29 - map('n','gr','<CMD>lua vim.lsp.buf.references()<CR>')
30 - map('n','gs','<CMD>lua vim.lsp.buf.signature_help()<CR>')
31 - map('n','gi','<CMD>lua vim.lsp.buf.implementation()<CR>')
32 - map('n','gt','<CMD>lua vim.lsp.buf.type_definition()<CR>')
26 + map('n','<LEADER>gD','<CMD>lua vim.lsp.buf.declaration()<CR>')
27 + map('n','<LEADER>gd','<CMD>lua vim.lsp.buf.definition()<CR>')
28 + map('n','<LEADER>K','<CMD>lua vim.lsp.buf.hover()<CR>')
29 + map('n','<LEADER>gr','<CMD>lua vim.lsp.buf.references()<CR>')
30 + map('n','<LEADER>gs','<CMD>lua vim.lsp.buf.signature_help()<CR>')
31 + map('n','<LEADER>gi','<CMD>lua vim.lsp.buf.implementation()<CR>')
32 + map('n','<LEADER>gt','<CMD>lua vim.lsp.buf.type_definition()<CR>')
33 33 map('n','<LEADER>gw','<CMD>lua vim.lsp.buf.document_symbol()<CR>')
34 34 map('n','<LEADER>gW','<CMD>lua vim.lsp.buf.workspace_symbol()<CR>')
35 35 map('n','<LEADER>ah','<CMD>lua vim.lsp.buf.hover()<CR>')
62 62 print("Unsupported system for sumneko")
64 + local neovim_lua_library = {}
65 + for _, path in pairs(vim.api.nvim_list_runtime_paths()) do
66 + local lua_path = path .. "/lua/";
67 + if vim.fn.isdirectory(lua_path) then
68 + neovim_lua_library[lua_path] = true
69 + end
70 + end
71 + -- This loads the `lua` files from nvim into the runtime.
72 + neovim_lua_library[vim.fn.expand("$VIMRUNTIME/lua")] = true
64 73 --TODO: How to switch this configuration based upon if we are editing neovim configuration or just any Lua file/project?
65 74 lsp.sumneko_lua.setup {
66 75 on_attach = integrate_into_neovim,
74 83 diagnostics = {
75 84 enable = true,
85 + disable = 'trailing-space',
76 86 globals = { 'vim' },
78 88 hint = {
79 89 enable = true,
81 91 workspace = {
82 - library = vim.api.nvim_get_runtime_file("", true),
92 + library = neovim_lua_library,
93 + maxPreload = 10000,
94 + preloadFileSize = 10000,
84 96 telemetry = {
85 97 enable = true,

neovim/lua/mkdir.lua

Added
new file mode 100644
1 +-- Returns two functions.
2 +-- The first function creates any missing intermediate directory for the current buffer.
3 +-- The second function takes in the `autocommand` function and sets up the first function to automatically run before save.
4 +--
5 +-- Setup this module like so:
6 +-- ```
7 +-- local _, setup_mkdir = require'mkdir'()
8 +-- setup_mkdir(autocommand)
9 +-- ```
10 +return function()
11 + return function()
12 + -- base directory of current buffer
13 + local directory = vim.fn.expand("%:p:h")
14 + if vim.fn.isdirectory(directory) == 0 then
15 + vim.fn.mkdir(directory, 'p')
16 + end
17 + end,
18 + function(autocommand)
19 + autocommand{setup_mkdir_before_save = [[ BufWritePre * lua require'mkdir'() ]]}
20 + end
21 +end

neovim/lua/plugins.lua

Modified
44 - autocommand{ compile_plugin_glue = 'BufWritePost plugins.lua PluginsCompile' }
44 + autocommand{ compile_plugins_glue =
45 + {'BufWritePost plugins.lua source <afile> | PluginsCompile' },
46 + {'BufWritePost general_editor_settings.lua source <afile> | PluginsCompile'}
47 + }
45 48 local use = packer.use
46 49 -- reset packer in case we are reloading the whole configuration
47 50 packer.reset()
49 52 -- Packer can manage itself
50 53 use { 'wbthomason/packer.nvim', opt = true }
51 - -- Closes brackets automatically upon hitting Enter
52 - use 'rstacruz/vim-closer'
54 + -- colelction of icons configurations for various plugins
55 + use {
56 + 'yamatsum/nvim-nonicons',
57 + requires = { 'kyazdani42/nvim-web-devicons' }
58 + }
53 59 -- Nice file tree browser
54 60 use {
55 61 'kyazdani42/nvim-tree.lua',
56 - requires = 'kyazdani42/nvim-web-devicons',
62 + requires = { 'kyazdani42/nvim-web-devicons', opt = true},
57 63 config = function()
58 64 vim.g.nvim_tree_side = 'left'
59 65 vim.g.nvim_tree_width = 42
61 67 vim.g.nvim_tree_ignore_ft = {'cheatsheet'}
70 + -- Display popup with possible keybindings to a command
71 + use {
72 + "folke/which-key.nvim",
73 + config = function()
74 + require("which-key").setup{}
75 + end
76 + }
77 + -- Pretty abstraction over quicklist, loclist, messages and lsp diagnostics
78 + use { 'folke/trouble.nvim',
79 + requires = {
80 + {'kyazdani42/nvim-web-devicons', opt = true},
81 + -- pathes in some highlighting groups for LSP diagnostics
82 + -- FIXME should just be done by my theme istead of this plugin...
83 + { 'folke/lsp-colors.nvim' }},
84 + config = function()
85 + require 'trouble'.setup()
86 + require("lsp-colors").setup({
87 + Error = "#f05faf",
88 + Warning = "#c0af68",
89 + Information = "#2db8cf",
90 + Hint = "#19bc90"
91 + })
92 + end
93 + }
64 94 -- NVIM API for defining color schemes
65 95 -- TODO: when profiling, this plugins loading times are high
66 96 -- maybe the cause is that it loads a bunch of files
110 140 requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim' },
112 142 -- Render markdown previews in the terminal
113 - use { 'npxbr/glow.nvim', opt = true, cmd = 'Glow' }
143 + use { 'npxbr/glow.nvim', opt = true, cmd = 'Glow', ft = {'markdown'} }
114 144 -- Type :<number> to jump to line numbers
116 146 'nacro90/numb.nvim',
124 154 -- Repository and API for configuring LSP servers in nvim
125 - use { 'neovim/nvim-lspconfig', config = function()
126 - require'lsp'()
127 - end}
155 + use { 'neovim/nvim-lspconfig',
156 + config = function()
157 + require'lsp'()
158 + end}
128 159 -- Utility functions to glue the status messages of LSP servers with the status line in nvim together
129 160 use 'nvim-lua/lsp-status.nvim'
130 161 -- Deeper integration of JDTLS from Eclipse with nvim
176 + -- Nicer view than :registers, also shows popup on CTRL-R in I-mode
177 + use { 'tversteeg/registers.nvim' }
145 178 -- comment and uncomment lines
147 180 'b3nj5m1n/kommentary',

neovim/lua/theme/java_colors.lua

Modified
1 -return function(Group, groups, colors, styles)
2 - Group.new('javaParen', colors.normal, colors.none, no)
3 - Group.new('javaOperator', colors.normal, colors.none, no)
4 - Group.new('javaVarArg', colors.normal, colors.none, no)
5 - Group.new('javaParen1', colors.normal, colors.none, no)
6 - Group.new('javaParen2', colors.normal, colors.none, no)
7 - Group.new('javaParen3', colors.normal, colors.none, no)
8 - Group.new('javaParen4', colors.normal, colors.none, no)
9 - Group.new('javaParen5', colors.normal, colors.none, no)
10 - Group.new('javaAnnotation', colors.normal, colors.none, no)
11 - Group.new('javaDocTags', colors.normal, colors.none, no)
1 +return function(Group, _groups, colors, styles)
2 + Group.new('javaOperator', colors.normal, colors.none, styles.NONE)
3 + Group.new('javaVarArg', colors.normal, colors.none, styles.NONE)
4 + Group.new('javaParen', colors.normal, colors.none, styles.NONE)
5 + Group.new('javaParen1', colors.normal, colors.none, styles.NONE)
6 + Group.new('javaParen2', colors.normal, colors.none, styles.NONE)
7 + Group.new('javaParen3', colors.normal, colors.none, styles.NONE)
8 + Group.new('javaParen4', colors.normal, colors.none, styles.NONE)
9 + Group.new('javaParen5', colors.normal, colors.none, styles.NONE)
10 + Group.new('javaAnnotation', colors.normal, colors.none, styles.NONE)
11 + Group.new('javaDocTags', colors.normal, colors.none, styles.NONE)
12 12 Group.new(
13 13 'javaCommentTitle',
14 14 colors.important,