diff --git a/.gitignore b/.gitignore index e033bc6..abe261e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -lazy-lock.json +lazy-lock.json diff --git a/.luarc.json b/.luarc.json index a3e20ab..39b1c96 100644 --- a/.luarc.json +++ b/.luarc.json @@ -1,3 +1,3 @@ -{ - "diagnostics.globals": ["vim"], -} +{ + "diagnostics.globals": ["vim"], +} diff --git a/after/ftplugin/asciidoc.lua b/after/ftplugin/asciidoc.lua index bb968e2..1955963 100644 --- a/after/ftplugin/asciidoc.lua +++ b/after/ftplugin/asciidoc.lua @@ -1,3 +1,3 @@ --- Options for AsciiDoc files, mainly used in diary situations --- (pun intended) -vim.opt.textwidth = 80 +-- Options for AsciiDoc files, mainly used in diary situations +-- (pun intended) +vim.opt.textwidth = 80 diff --git a/after/ftplugin/org.lua b/after/ftplugin/org.lua index 27cda45..80bf5e1 100644 --- a/after/ftplugin/org.lua +++ b/after/ftplugin/org.lua @@ -1,13 +1,13 @@ --- make C-CR in insert mode behave like org_meta_return --- in normal mode - -vim.keymap.set( - "i", - "", - - 'lua require("orgmode").action("org_mappings.meta_return")', { - silent = true, - buffer = true, - desc = 'ORG: meta return' - } -) +-- make C-CR in insert mode behave like org_meta_return +-- in normal mode + +vim.keymap.set( + "i", + "", + + 'lua require("orgmode").action("org_mappings.meta_return")', { + silent = true, + buffer = true, + desc = 'ORG: meta return' + } +) diff --git a/after/ftplugin/rust.lua b/after/ftplugin/rust.lua index f2716a8..4b5af54 100644 --- a/after/ftplugin/rust.lua +++ b/after/ftplugin/rust.lua @@ -1,37 +1,37 @@ -local bufnr = vim.api.nvim_get_current_buf() - -vim.keymap.set( - "n", - "x", - function() - vim.cmd.RustLsp({ 'explainError', 'current' }) - end, - { silent = true, buffer = bufnr, desc = 'RustLSP: explain error at cursor' } -) - - --- show run targets -vim.keymap.set( - "n", - "", - function() - vim.cmd.RustLsp({ 'runnables' }) - end, - { silent = true, buffer = bufnr, desc = 'RustLSP: show runnables' } -) - --- run last target -vim.keymap.set( - "n", - "", - function() - vim.cmd.RustLsp({ 'runnables', bang = true }) - end, - { silent = true, buffer = bufnr, desc = 'RustLSP: show runnables' } -) - - --- override signature hover to use RustLsp -vim.keymap.set('n', 'K', ":RustLsp hover actions", { desc = "RustLSP show signature" }) -vim.keymap.set('n', 'J', ":RustLsp joinLines", { desc = "RustLSP join lines" }) - +local bufnr = vim.api.nvim_get_current_buf() + +vim.keymap.set( + "n", + "x", + function() + vim.cmd.RustLsp({ 'explainError', 'current' }) + end, + { silent = true, buffer = bufnr, desc = 'RustLSP: explain error at cursor' } +) + + +-- show run targets +vim.keymap.set( + "n", + "", + function() + vim.cmd.RustLsp({ 'runnables' }) + end, + { silent = true, buffer = bufnr, desc = 'RustLSP: show runnables' } +) + +-- run last target +vim.keymap.set( + "n", + "", + function() + vim.cmd.RustLsp({ 'runnables', bang = true }) + end, + { silent = true, buffer = bufnr, desc = 'RustLSP: show runnables' } +) + + +-- override signature hover to use RustLsp +vim.keymap.set('n', 'K', ":RustLsp hover actions", { desc = "RustLSP show signature" }) +vim.keymap.set('n', 'J', ":RustLsp joinLines", { desc = "RustLSP join lines" }) + diff --git a/colors/lunaperche-sl.vim b/colors/lunaperche-sl.vim index 161d5bf..09f6d0b 100644 --- a/colors/lunaperche-sl.vim +++ b/colors/lunaperche-sl.vim @@ -1,4 +1,4 @@ -runtime colors/lunaperche.vim - -" fix VertSplit for lunaperche -hi VertSplit guifg=#aaaaaa +runtime colors/lunaperche.vim + +" fix VertSplit for lunaperche +hi VertSplit guifg=#aaaaaa diff --git a/init.lua b/init.lua index 9336e3d..7036d64 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,10 @@ +-- adjust proxy on Windows +if vim.loop.os_environ().OS == 'Windows_NT' then + -- TODO move out of the tree and do not check in + vim.fn.setenv("http_proxy", "http://10.167.16.21:80") + vim.fn.setenv("https_proxy", "http://10.167.16.21:80") +end + -- load configurations files from lua/* require('filetype') require('options') diff --git a/lua/colorscheme.lua b/lua/colorscheme.lua index 7b2edd9..e7a71db 100644 --- a/lua/colorscheme.lua +++ b/lua/colorscheme.lua @@ -1,8 +1,8 @@ --- define your colorscheme here -local colorscheme = 'lunaperche-sl' - -local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) -if not is_ok then - vim.notify('colorscheme ' .. colorscheme .. ' not found!') - return -end +-- define your colorscheme here +local colorscheme = 'lunaperche-sl' + +local is_ok, _ = pcall(vim.cmd, "colorscheme " .. colorscheme) +if not is_ok then + vim.notify('colorscheme ' .. colorscheme .. ' not found!') + return +end diff --git a/lua/config/alpha-nvim.lua b/lua/config/alpha-nvim.lua index 1709c7a..f8173bc 100644 --- a/lua/config/alpha-nvim.lua +++ b/lua/config/alpha-nvim.lua @@ -1,109 +1,116 @@ -local alpha = require 'alpha' -local dashboard = require 'alpha.themes.dashboard' - -_Gopts = { - position = 'center', - hl = 'Type', - wrap = 'overflow', -} - --- DASHBOARD HEADER - -local function getGreeting() - local tableTime = os.date '*t' - local datetime = os.date ' %Y-%m-%d-%A  %H:%M:%S ' - local hour = tableTime.hour - local greetingsTable = { - [1] = ' Sleep well', - [2] = ' Good morning', - [3] = ' Good afternoon', - [4] = ' Good evening', - [5] = '󰖔 Good night', - } - local greetingIndex = 0 - if hour == 23 or hour < 7 then - greetingIndex = 1 - elseif hour < 12 then - greetingIndex = 2 - elseif hour >= 12 and hour < 18 then - greetingIndex = 3 - elseif hour >= 18 and hour < 21 then - greetingIndex = 4 - elseif hour >= 21 then - greetingIndex = 5 - end - return datetime .. ' ' .. greetingsTable[greetingIndex] -end - -local logo = [[ - -  - ████ ██████ █████ ██ - ███████████ █████  - █████████ ███████████████████ ███ ███████████ - █████████ ███ █████████████ █████ ██████████████ - █████████ ██████████ █████████ █████ █████ ████ █████ - ███████████ ███ ███ █████████ █████ █████ ████ █████ - ██████ █████████████████████ ████ █████ █████ ████ ██████ - - ]] - -local greeting = getGreeting() -local marginBottom = 0 - --- Split logo into lines -local logoWidth = 0 -for line in logo:gmatch '[^\n]+' do - logoWidth = math.max(logoWidth, #line / 2) -end -logoWidth = 75 -- code above does not work with utf8 strings in lua 5.1 - --- Calculate padding for centering the greeting -local greetingWidth = #greeting - 3 -local padding = math.floor((logoWidth - greetingWidth) / 2) --- Generate spaces for padding -local paddedGreeting = string.rep(' ', padding) .. greeting - - -local userName = "You work as '" .. vim.env.USER .. "'." - --- Calculate padding for centering the username -local userNameWidth = #userName -local padding = math.floor((logoWidth - userNameWidth) / 2) --- Generate spaces for padding -local userNamePadded = string.rep(' ', padding) .. userName - - --- Add margin lines below the padded greeting -local margin = string.rep('\n', marginBottom * 5) - --- Concatenate logo, padded greeting, and margin -local adjustedLogo = logo .. '\n' .. paddedGreeting .. '\n\n' .. userNamePadded .. '\n' .. margin -dashboard.section.header.val = vim.split(adjustedLogo, '\n') - -dashboard.section.buttons.val = { - dashboard.button('d', ' Diary Entry', 'Diary'), - dashboard.button('n', ' New file', ':ene startinsert '), - dashboard.button('s', ' Settings', 'WorkspacesOpen config-nvim'), - dashboard.button('u', '󱐥 Update plugins', 'Lazy update'), - dashboard.button('w', ' Workspaces', 'WorkspacesOpen'), - dashboard.button('q', '󰤆 Quit', 'qa'), -} - --- dashboard.section.footer.val = greeting - -vim.api.nvim_create_autocmd('User', { - pattern = 'LazyVimStarted', - desc = 'Add Alpha dashboard footer', - once = true, - callback = function() - local stats = require('lazy').stats() - local ms = math.floor(stats.startuptime * 100 + 0.5) / 100 - dashboard.section.footer.val = { ' ', ' ', ' ', ' Loaded ' .. stats.count .. ' plugins  in ' .. ms .. ' ms ' } - dashboard.section.header.opts.hl = 'DashboardFooter' - pcall(vim.cmd.AlphaRedraw) - end, -}) - -dashboard.opts.opts.noautocmd = true -alpha.setup(dashboard.opts) +local alpha = require 'alpha' +local dashboard = require 'alpha.themes.dashboard' + +_Gopts = { + position = 'center', + hl = 'Type', + wrap = 'overflow', +} + +-- DASHBOARD HEADER + +local function getGreeting() + local tableTime = os.date '*t' + local datetime = os.date ' %Y-%m-%d-%A  %H:%M:%S ' + local hour = tableTime.hour + local greetingsTable = { + [1] = ' Sleep well', + [2] = ' Good morning', + [3] = ' Good afternoon', + [4] = ' Good evening', + [5] = '󰖔 Good night', + } + local greetingIndex = 0 + if hour == 23 or hour < 7 then + greetingIndex = 1 + elseif hour < 12 then + greetingIndex = 2 + elseif hour >= 12 and hour < 18 then + greetingIndex = 3 + elseif hour >= 18 and hour < 21 then + greetingIndex = 4 + elseif hour >= 21 then + greetingIndex = 5 + end + return datetime .. ' ' .. greetingsTable[greetingIndex] +end + +local logo = [[ + +  + ████ ██████ █████ ██ + ███████████ █████  + █████████ ███████████████████ ███ ███████████ + █████████ ███ █████████████ █████ ██████████████ + █████████ ██████████ █████████ █████ █████ ████ █████ + ███████████ ███ ███ █████████ █████ █████ ████ █████ + ██████ █████████████████████ ████ █████ █████ ████ ██████ + + ]] + +local greeting = getGreeting() +local marginBottom = 0 + +-- Split logo into lines +local logoWidth = 0 +for line in logo:gmatch '[^\n]+' do + logoWidth = math.max(logoWidth, #line / 2) +end +logoWidth = 75 -- code above does not work with utf8 strings in lua 5.1 + +-- Calculate padding for centering the greeting +local greetingWidth = #greeting - 3 +local padding = math.floor((logoWidth - greetingWidth) / 2) +-- Generate spaces for padding +local paddedGreeting = string.rep(' ', padding) .. greeting + +local userName = "You work as '" .. (vim.env.USER or vim.env.USERNAME) .. "'." + +-- Calculate padding for centering the username +local userNameWidth = #userName +local padding = math.floor((logoWidth - userNameWidth) / 2) +-- Generate spaces for padding +local userNamePadded = string.rep(' ', padding) .. userName + + +-- Add margin lines below the padded greeting +local margin = string.rep('\n', marginBottom * 5) + +-- Concatenate logo, padded greeting, and margin +local adjustedLogo = logo .. '\n' .. paddedGreeting .. '\n\n' .. userNamePadded .. '\n' .. margin +dashboard.section.header.val = vim.split(adjustedLogo, '\n') + +local buttons = { + dashboard.button('n', ' New file', ':ene startinsert '), + dashboard.button('s', ' Settings', 'WorkspacesOpen config-nvim'), + dashboard.button('t', '[] Todo List', 'Org agenda t'), + dashboard.button('u', '󱐥 Update plugins', 'Lazy update'), + dashboard.button('w', ' Workspaces', 'WorkspacesOpen'), + dashboard.button('q', '󰤆 Quit', 'qa'), +} + +if vim.loop.os_gethostname() == 'ccflow' then + table.insert(buttons, 1, + dashboard.button('d', ' Diary Entry', 'Diary')) +end + +dashboard.section.buttons.val = buttons + +-- dashboard.section.footer.val = greeting + + +vim.api.nvim_create_autocmd('User', { + pattern = 'LazyVimStarted', + desc = 'Add Alpha dashboard footer', + once = true, + callback = function() + local stats = require('lazy').stats() + local ms = math.floor(stats.startuptime * 100 + 0.5) / 100 + dashboard.section.footer.val = { ' ', ' ', ' ', ' Loaded ' .. stats.count .. ' plugins  in ' .. ms .. ' ms ' } + dashboard.section.header.opts.hl = 'DashboardFooter' + pcall(vim.cmd.AlphaRedraw) + end, +}) + +dashboard.opts.opts.noautocmd = true +alpha.setup(dashboard.opts) diff --git a/lua/config/lualine.lua b/lua/config/lualine.lua index 7109128..92f4353 100644 --- a/lua/config/lualine.lua +++ b/lua/config/lualine.lua @@ -1,41 +1,41 @@ -require("lualine").setup { - options = { - icons_enabled = false, - theme = 'papercolor_light', - component_separators = {}, - section_separators = {}, - disabled_filetypes = { - statusline = {}, - winbar = { "neo-tree" }, - }, - ignore_focus = {}, - always_divide_middle = true, - globalstatus = false, - refresh = { - statusline = 1000, - tabline = 1000, - winbar = 1000, - } - }, - sections = { - lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, - lualine_b = { 'branch', 'diff', 'diagnostics' }, - lualine_c = {}, - lualine_x = { 'encoding', 'fileformat', 'filetype', 'lsp_status' }, - lualine_y = { 'filesize' }, - lualine_z = { 'progress', 'location' } - }, - inactive_sections = { - lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, - lualine_b = {}, - lualine_c = {}, - -- lualine_x = { 'encoding', 'fileformat', 'filetype' }, - lualine_x = {}, - lualine_y = { 'filesize' }, - lualine_z = { 'location' } - }, - tabline = {}, - winbar = {}, -- formerly breadcrumb here - inactive_winbar = {}, - extensions = {} -} +require("lualine").setup { + options = { + icons_enabled = false, + theme = 'papercolor_light', + component_separators = {}, + section_separators = {}, + disabled_filetypes = { + statusline = {}, + winbar = { "neo-tree" }, + }, + ignore_focus = {}, + always_divide_middle = true, + globalstatus = false, + refresh = { + statusline = 1000, + tabline = 1000, + winbar = 1000, + } + }, + sections = { + lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, + lualine_b = { 'branch', 'diff', 'diagnostics' }, + lualine_c = {}, + lualine_x = { 'encoding', 'fileformat', 'filetype', 'lsp_status' }, + lualine_y = { 'filesize' }, + lualine_z = { 'progress', 'location' } + }, + inactive_sections = { + lualine_a = { { 'filename', path = 1, shorting_target = 50 } }, + lualine_b = {}, + lualine_c = {}, + -- lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_x = {}, + lualine_y = { 'filesize' }, + lualine_z = { 'location' } + }, + tabline = {}, + winbar = {}, -- formerly breadcrumb here + inactive_winbar = {}, + extensions = {} +} diff --git a/lua/diary.lua b/lua/diary.lua index 0ee26c2..809cd1e 100644 --- a/lua/diary.lua +++ b/lua/diary.lua @@ -1,24 +1,24 @@ -local diary_open = function(opts) - local date = opts.args ~= '' and opts.args or os.date('%Y-%m-%d') - local year, month = date:match('(%d%d%d%d)-(%d%d)') - local folder = vim.fs.joinpath(vim.env.HOME, string.format('.diary/asciidoc/%s', year)) - vim.fn.mkdir(folder, "p") - local file = string.format('%s/diary-%s-%s.adoc', folder, year, month) - print("file is:", file) - vim.cmd('e ' .. file) - vim.cmd('normal! G') -- go to end of file - - -- NOTE.2025-06-08 [1] and [2] should be replaced with snippet name, but I - -- don't know how -- neither do grok nor chatgpt ... - local snips = require('luasnip') - local asnippets = snips.get_snippets('asciidoc') - if vim.fn.getfsize(file) == 0 then - snips.snip_expand(asnippets[1]) - vim.cmd('normal! G') - end - - vim.cmd('normal! 3o') -- insert some newlines before new entry - snips.snip_expand(asnippets[2]) -end - -vim.api.nvim_create_user_command("Diary", diary_open, { nargs = '?' }) +local diary_open = function(opts) + local date = opts.args ~= '' and opts.args or os.date('%Y-%m-%d') + local year, month = date:match('(%d%d%d%d)-(%d%d)') + local folder = vim.fs.joinpath(vim.env.HOME, string.format('.diary/asciidoc/%s', year)) + vim.fn.mkdir(folder, "p") + local file = string.format('%s/diary-%s-%s.adoc', folder, year, month) + print("file is:", file) + vim.cmd('e ' .. file) + vim.cmd('normal! G') -- go to end of file + + -- NOTE.2025-06-08 [1] and [2] should be replaced with snippet name, but I + -- don't know how -- neither do grok nor chatgpt ... + local snips = require('luasnip') + local asnippets = snips.get_snippets('asciidoc') + if vim.fn.getfsize(file) == 0 then + snips.snip_expand(asnippets[1]) + vim.cmd('normal! G') + end + + vim.cmd('normal! 3o') -- insert some newlines before new entry + snips.snip_expand(asnippets[2]) +end + +vim.api.nvim_create_user_command("Diary", diary_open, { nargs = '?' }) diff --git a/lua/filetype.lua b/lua/filetype.lua index f3c5503..008d280 100644 --- a/lua/filetype.lua +++ b/lua/filetype.lua @@ -1,5 +1,5 @@ -vim.filetype.add({ - extension = { - CON = 'confile', - }, -}) +vim.filetype.add({ + extension = { + CON = 'confile', + }, +}) diff --git a/lua/functions.lua b/lua/functions.lua index 9342e82..066e4f0 100644 --- a/lua/functions.lua +++ b/lua/functions.lua @@ -1,15 +1,15 @@ --- custom defined functions - --- Return the currently, visually selected text range -function SL_get_visual_selection() - vim.cmd([[ execute "normal! \" ]]) - local s_start = vim.fn.getcharpos("'<") - local s_end = vim.fn.getcharpos("'>") - vim.cmd([[ execute "normal! gv" ]]) - - local current_buffer = vim.api.nvim_get_current_buf() - local r = vim.api.nvim_buf_get_text(current_buffer, s_start[2] - 1, s_start[3] - 1, - s_end[2] - 1, s_end[3], {}) - -- print("region might be", current_buffer, s_start[2], s_start[3], s_end[2], s_end[3]) - return table.concat(r, "\n") -end +-- custom defined functions + +-- Return the currently, visually selected text range +function SL_get_visual_selection() + vim.cmd([[ execute "normal! \" ]]) + local s_start = vim.fn.getcharpos("'<") + local s_end = vim.fn.getcharpos("'>") + vim.cmd([[ execute "normal! gv" ]]) + + local current_buffer = vim.api.nvim_get_current_buf() + local r = vim.api.nvim_buf_get_text(current_buffer, s_start[2] - 1, s_start[3] - 1, + s_end[2] - 1, s_end[3], {}) + -- print("region might be", current_buffer, s_start[2], s_start[3], s_end[2], s_end[3]) + return table.concat(r, "\n") +end diff --git a/lua/keybindings.lua b/lua/keybindings.lua index d28c294..b596cbc 100644 --- a/lua/keybindings.lua +++ b/lua/keybindings.lua @@ -1,129 +1,129 @@ --- Setup fzf-lua keybindings and some other searches -local fzf = require('fzf-lua') -vim.keymap.set('n', 'b', fzf.buffers, { desc = "Buffers" }) -vim.keymap.set('n', 'fG', fzf.grep_cword, { desc = "Grep word under cursor" }) -vim.keymap.set('n', 'fT', fzf.treesitter, { desc = "Treesitter symbols" }) -vim.keymap.set('n', 'fc', fzf.commands, { desc = "Commands" }) -vim.keymap.set('n', 'ff', fzf.files, { desc = "Find file" }) -vim.keymap.set('n', 'fg', fzf.live_grep, { desc = "Grep" }) -vim.keymap.set('n', 'fm', fzf.manpages, { desc = "Manpages" }) -vim.keymap.set('n', 'fr', fzf.resume, { desc = "Resume last search" }) -vim.keymap.set('n', 'fs', fzf.blines, { desc = "Search buffer" }) -vim.keymap.set('n', 'f=', fzf.changes, { desc = "Changes" }) -vim.keymap.set('n', 'fR', fzf.registers, { desc = "Registers" }) -vim.keymap.set('n', 'fo', fzf.nvim_options, { desc = "NVim Options" }) -vim.keymap.set('n', 'ft', ":TodoFzfLua", { desc = "Todos" }) -vim.keymap.set('n', 'fl', fzf.git_bcommits, { desc = "Git buffer log" }) - --- use fzf buffer lines as default search -vim.keymap.set('n', '', fzf.blines, { desc = "Search buffer" }) -vim.keymap.set('n', 'z=', fzf.spell_suggest, { desc = "Spelling suggestions" }) - --- open file manager and git -vim.keymap.set('n', 'g', ":Neogit", { desc = "Neogit" }) -vim.keymap.set('n', 'T', ":Neotree reveal", { desc = "Neotree Files" }) -vim.keymap.set('n', 'F', ":Fyler kind=split_left", { desc = "Fyler Files" }) - --- calendar -vim.keymap.set('n', 'c', ":Calendar -split=horizontal -position=below -height=12", - { desc = "Show calendar below" }) -vim.keymap.set('n', 'C', ":Calendar -view=year -split=vertical -width=27", { desc = "Show calendar right" }) - --- Open current file in browser (chromium) -vim.keymap.set('n', 'o', ":silent !chromium '%'", { desc = "Open in browser" }) - -if vim.loop.os_gethostname() == 'ccflow' then - -- Open org file folder in neotree - vim.keymap.set('n', 'of', ':silent :Neotree dir=/home/saschal/Documents/Eigene\\ (Briefe\\ etc.)/org', - { desc = "Open org folder" }) -end - --- toggle colorscheme between dark and light -vim.keymap.set('n', 'm', function() - if vim.opt.background:get() == "dark" then - vim.o.background = "light" - else - vim.o.background = "dark" - end -end, { desc = "Toggle dark/light mode" }) - --- --- configure workspaces --- also add a custom picker to fzf --- -local workspaces = require('workspaces') -local workspaces_fzf_picker = function(opts) - local fzf_lua = require('fzf-lua') - opts = opts or {} - opts.prompt = "Workspaces> " - opts.actions = { - ['default'] = function(selected) - workspaces.open(selected[1]) - end - } - fzf_lua.fzf_exec(function(fzf_cb) - -- NOP - local ws = workspaces.get() - ws = ws or {} - for i = 1, #ws do - fzf_cb(ws[i].name) - end - fzf_cb() -- EOF - end, opts) -end -vim.keymap.set('n', 'w', workspaces_fzf_picker, { desc = "Workspaces" }) - ------------------------------------------- --- --- Window layout save and restore --- ------------------------------------------- - -local layout = require('layout') -vim.keymap.set('n', 'ss', function() - layout.save('default') - print("Window layout saved") -end, { desc = "Save window layout" }) -vim.keymap.set('n', 'sr', function() - layout.restore('default') - print("Window layout restored") -end, { desc = "Restore window layout" }) - ------------------------------------------- --- --- Word higlighting --- ------------------------------------------- -local mywords = require('mywords') -vim.keymap.set('n', 'mm', mywords.hl_toggle, { desc = "Highlight current word" }) -vim.keymap.set('n', 'mr', mywords.hl_toggle_regex, { desc = "Highlight regexp" }) -vim.keymap.set('n', 'mc', mywords.uhl_all, { desc = "Clear all highlights" }) - - ------------------------------------------- --- --- Moving lines up and down --- ------------------------------------------- - -vim.keymap.set('n', '', ":m -2", { desc = "Move current line up" }) -vim.keymap.set('n', '', ":m +1", { desc = "Move current line down" }) - -vim.keymap.set('i', '', ":m -2", { desc = "Move current line up" }) -vim.keymap.set('i', '', ":m +1", { desc = "Move current line down" }) - ------------------------------------------- --- --- Shortcuts which are known from Emacs --- ------------------------------------------- -vim.keymap.set('n', 'q', "gwap", { desc = "Wrap paragraph" }) -vim.keymap.set('n', '', ":silent! nohls", { desc = "Clear search" }) -vim.keymap.set('i', '', 'dW', { desc = "Delete word right" }) - --- horizontally scroll with mouse -vim.keymap.set('n', '', 'zh') -vim.keymap.set('n', '', 'zl') - -vim.keymap.set('i', '', 'zh') -vim.keymap.set('i', '', 'zl') +-- Setup fzf-lua keybindings and some other searches +local fzf = require('fzf-lua') +vim.keymap.set('n', 'b', fzf.buffers, { desc = "Buffers" }) +vim.keymap.set('n', 'fG', fzf.grep_cword, { desc = "Grep word under cursor" }) +vim.keymap.set('n', 'fT', fzf.treesitter, { desc = "Treesitter symbols" }) +vim.keymap.set('n', 'fc', fzf.commands, { desc = "Commands" }) +vim.keymap.set('n', 'ff', fzf.files, { desc = "Find file" }) +vim.keymap.set('n', 'fg', fzf.live_grep, { desc = "Grep" }) +vim.keymap.set('n', 'fm', fzf.manpages, { desc = "Manpages" }) +vim.keymap.set('n', 'fr', fzf.resume, { desc = "Resume last search" }) +vim.keymap.set('n', 'fs', fzf.blines, { desc = "Search buffer" }) +vim.keymap.set('n', 'f=', fzf.changes, { desc = "Changes" }) +vim.keymap.set('n', 'fR', fzf.registers, { desc = "Registers" }) +vim.keymap.set('n', 'fo', fzf.nvim_options, { desc = "NVim Options" }) +vim.keymap.set('n', 'ft', ":TodoFzfLua", { desc = "Todos" }) +vim.keymap.set('n', 'fl', fzf.git_bcommits, { desc = "Git buffer log" }) + +-- use fzf buffer lines as default search +vim.keymap.set('n', '', fzf.blines, { desc = "Search buffer" }) +vim.keymap.set('n', 'z=', fzf.spell_suggest, { desc = "Spelling suggestions" }) + +-- open file manager and git +vim.keymap.set('n', 'g', ":Neogit", { desc = "Neogit" }) +vim.keymap.set('n', 'T', ":Neotree reveal", { desc = "Neotree Files" }) +vim.keymap.set('n', 'F', ":Fyler kind=split_left", { desc = "Fyler Files" }) + +-- calendar +vim.keymap.set('n', 'c', ":Calendar -split=horizontal -position=below -height=12", + { desc = "Show calendar below" }) +vim.keymap.set('n', 'C', ":Calendar -view=year -split=vertical -width=27", { desc = "Show calendar right" }) + +-- Open current file in browser (chromium) +vim.keymap.set('n', 'o', ":silent !chromium '%'", { desc = "Open in browser" }) + +if vim.loop.os_gethostname() == 'ccflow' then + -- Open org file folder in neotree + vim.keymap.set('n', 'of', ':silent :Neotree dir=/home/saschal/Documents/Eigene\\ (Briefe\\ etc.)/org', + { desc = "Open org folder" }) +end + +-- toggle colorscheme between dark and light +vim.keymap.set('n', 'm', function() + if vim.opt.background:get() == "dark" then + vim.o.background = "light" + else + vim.o.background = "dark" + end +end, { desc = "Toggle dark/light mode" }) + +-- +-- configure workspaces +-- also add a custom picker to fzf +-- +local workspaces = require('workspaces') +local workspaces_fzf_picker = function(opts) + local fzf_lua = require('fzf-lua') + opts = opts or {} + opts.prompt = "Workspaces> " + opts.actions = { + ['default'] = function(selected) + workspaces.open(selected[1]) + end + } + fzf_lua.fzf_exec(function(fzf_cb) + -- NOP + local ws = workspaces.get() + ws = ws or {} + for i = 1, #ws do + fzf_cb(ws[i].name) + end + fzf_cb() -- EOF + end, opts) +end +vim.keymap.set('n', 'w', workspaces_fzf_picker, { desc = "Workspaces" }) + +------------------------------------------ +-- +-- Window layout save and restore +-- +------------------------------------------ + +local layout = require('layout') +vim.keymap.set('n', 'ss', function() + layout.save('default') + print("Window layout saved") +end, { desc = "Save window layout" }) +vim.keymap.set('n', 'sr', function() + layout.restore('default') + print("Window layout restored") +end, { desc = "Restore window layout" }) + +------------------------------------------ +-- +-- Word higlighting +-- +------------------------------------------ +local mywords = require('mywords') +vim.keymap.set('n', 'mm', mywords.hl_toggle, { desc = "Highlight current word" }) +vim.keymap.set('n', 'mr', mywords.hl_toggle_regex, { desc = "Highlight regexp" }) +vim.keymap.set('n', 'mc', mywords.uhl_all, { desc = "Clear all highlights" }) + + +------------------------------------------ +-- +-- Moving lines up and down +-- +------------------------------------------ + +vim.keymap.set('n', '', ":m -2", { desc = "Move current line up" }) +vim.keymap.set('n', '', ":m +1", { desc = "Move current line down" }) + +vim.keymap.set('i', '', ":m -2", { desc = "Move current line up" }) +vim.keymap.set('i', '', ":m +1", { desc = "Move current line down" }) + +------------------------------------------ +-- +-- Shortcuts which are known from Emacs +-- +------------------------------------------ +vim.keymap.set('n', 'q', "gwap", { desc = "Wrap paragraph" }) +vim.keymap.set('n', '', ":silent! nohls", { desc = "Clear search" }) +vim.keymap.set('i', '', 'dW', { desc = "Delete word right" }) + +-- horizontally scroll with mouse +vim.keymap.set('n', '', 'zh') +vim.keymap.set('n', '', 'zl') + +vim.keymap.set('i', '', 'zh') +vim.keymap.set('i', '', 'zl') diff --git a/lua/layout.lua b/lua/layout.lua index 434164b..c5f099f 100644 --- a/lua/layout.lua +++ b/lua/layout.lua @@ -1,71 +1,71 @@ --- save and restore current window layout --- inspired by: --- - https://github.com/dedowsdi/.vim/blob/master/autoload/ddd/layout.vim --- - https://vi.stackexchange.com/a/22545/53081 --- --- added cursor position handling - -local M = {} -local layouts = {} -local resize_cmds = {} - -function M.save(name) - layouts[name] = vim.fn.winlayout() - resize_cmds[name] = vim.fn.winrestcmd() - M.add_buf_to_layout(layouts[name]) -end - -function M.add_buf_to_layout(layout) - if layout[1] == "leaf" then - local win_id = layout[2] - table.insert(layout, vim.fn.winbufnr(win_id)) - table.insert(layout, vim.api.nvim_win_get_cursor(win_id)) - else - for _, child_layout in ipairs(layout[2]) do - M.add_buf_to_layout(child_layout) - end - end -end - -function M.restore(name) - if not layouts[name] then - return - end - - -- Create clean window - vim.cmd("new") - vim.cmd("wincmd o") - - -- Recursively restore buffers and cursor positions - M.apply_layout(layouts[name], name) - - -- Resize - vim.cmd(resize_cmds[name]) -end - -function M.apply_layout(layout, name) - if layout[1] == "leaf" then - -- Load buffer for leaf - if vim.fn.bufexists(layout[3]) == 1 then - vim.cmd(string.format("b %d", layout[3])) - -- Restore cursor position - vim.api.nvim_win_set_cursor(vim.fn.win_getid(), layout[4]) - end - else - -- Split cols or rows, split n-1 times - local split_method = layout[1] == "col" and "rightbelow split" or "rightbelow vsplit" - local wins = { vim.fn.win_getid() } - for i = 2, #layout[2] do - vim.cmd(split_method) - table.insert(wins, vim.fn.win_getid()) - end - - -- Recursive into child windows - for index, win_id in ipairs(wins) do - vim.fn.win_gotoid(win_id) - M.apply_layout(layout[2][index], name) - end - end -end - -return M +-- save and restore current window layout +-- inspired by: +-- - https://github.com/dedowsdi/.vim/blob/master/autoload/ddd/layout.vim +-- - https://vi.stackexchange.com/a/22545/53081 +-- +-- added cursor position handling + +local M = {} +local layouts = {} +local resize_cmds = {} + +function M.save(name) + layouts[name] = vim.fn.winlayout() + resize_cmds[name] = vim.fn.winrestcmd() + M.add_buf_to_layout(layouts[name]) +end + +function M.add_buf_to_layout(layout) + if layout[1] == "leaf" then + local win_id = layout[2] + table.insert(layout, vim.fn.winbufnr(win_id)) + table.insert(layout, vim.api.nvim_win_get_cursor(win_id)) + else + for _, child_layout in ipairs(layout[2]) do + M.add_buf_to_layout(child_layout) + end + end +end + +function M.restore(name) + if not layouts[name] then + return + end + + -- Create clean window + vim.cmd("new") + vim.cmd("wincmd o") + + -- Recursively restore buffers and cursor positions + M.apply_layout(layouts[name], name) + + -- Resize + vim.cmd(resize_cmds[name]) +end + +function M.apply_layout(layout, name) + if layout[1] == "leaf" then + -- Load buffer for leaf + if vim.fn.bufexists(layout[3]) == 1 then + vim.cmd(string.format("b %d", layout[3])) + -- Restore cursor position + vim.api.nvim_win_set_cursor(vim.fn.win_getid(), layout[4]) + end + else + -- Split cols or rows, split n-1 times + local split_method = layout[1] == "col" and "rightbelow split" or "rightbelow vsplit" + local wins = { vim.fn.win_getid() } + for i = 2, #layout[2] do + vim.cmd(split_method) + table.insert(wins, vim.fn.win_getid()) + end + + -- Recursive into child windows + for index, win_id in ipairs(wins) do + vim.fn.win_gotoid(win_id) + M.apply_layout(layout[2][index], name) + end + end +end + +return M diff --git a/lua/lsp.lua b/lua/lsp.lua index 7344359..538ec8e 100644 --- a/lua/lsp.lua +++ b/lua/lsp.lua @@ -1,134 +1,134 @@ --- attach using autocommand and setup keybindings -vim.api.nvim_create_autocmd('LspAttach', { - group = vim.api.nvim_create_augroup('sl.lsp', {}), - callback = function(args) - -- See `:help vim.lsp.*` for documentation on any of the below functions - local bufopts = { noremap = true, silent = true, buffer = args.buf } - vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = "LSP show signature", unpack(bufopts) }) - vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, - { desc = "Workspace add folder", unpack(bufopts) }) - vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, - { desc = "Workspace remove folder", unpack(bufopts) }) - vim.keymap.set('n', 'wl', function() - print(vim.inspect(vim.lsp.buf.list_workspace_folders())) - end, { desc = "Workspace list folders", unpack(bufopts) }) - vim.keymap.set('n', 'rn', vim.lsp.buf.rename, { desc = "LSP Rename", unpack(bufopts) }) - vim.keymap.set("n", "f", function() - vim.lsp.buf.format({ async = true }) - end, { desc = "LSP Format buffer", unpack(bufopts) }) - vim.keymap.set("n", 'F', ":silent !dx fmt --file %", { desc = "DX format rsx! regions", unpack(bufopts) }) - vim.keymap.set("v", "f", LSPRangeFormatFunction, { desc = "LSP Format region" }) - - -- 2024-09-09 - some ccflow commands for diagnostics, symbols and code actions - local fzf = require('fzf-lua') - vim.keymap.set('n', 'd', fzf.diagnostics_document, { desc = "Document diagnostics" }) - vim.keymap.set('n', 'D', fzf.diagnostics_workspace, { desc = "Workspace diagnostics" }) - vim.keymap.set('n', 'e', function() - local new_config = not vim.diagnostic.config().virtual_lines - vim.diagnostic.config({ virtual_lines = new_config }) - end, { desc = "Virtual line diagnostics" }) - vim.keymap.set('n', 'E', vim.diagnostic.open_float, { desc = "Popup diagnostics" }) - vim.keymap.set('n', 's', fzf.lsp_document_symbols, { desc = "Doc symbols" }) - vim.keymap.set('n', 'c', fzf.lsp_code_actions, { desc = "Code Actions" }) - vim.keymap.set('n', '[', vim.diagnostic.goto_prev, { desc = "Previous diagnostics" }) - vim.keymap.set('n', ']', vim.diagnostic.goto_next, { desc = "Previous diagnostics" }) - - local gitsigns = require('gitsigns') - vim.keymap.set('n', '=l', ":NeogitLogCurrent", { desc = "Neogit: log for this file" }) - vim.keymap.set('n', '==', gitsigns.preview_hunk_inline, { desc = "Git hunk preview" }) - vim.keymap.set('n', '=B', gitsigns.blame, { desc = "Git blame file" }) - vim.keymap.set('n', '=D', function() gitsigns.diffthis('~') end, { desc = "Git diff this (~)" }) - vim.keymap.set('n', '=R', gitsigns.reset_buffer, { desc = "Git reset file" }) - vim.keymap.set('n', '=S', gitsigns.stage_buffer, { desc = "Git stage file" }) - vim.keymap.set('n', '=[', gitsigns.prev_hunk, { desc = "Git previous hunk" }) - vim.keymap.set('n', '=]', gitsigns.next_hunk, { desc = "Git next hunk" }) - vim.keymap.set('n', '=b', gitsigns.blame_line, { desc = "Git blame line" }) - vim.keymap.set('n', '=d', gitsigns.diffthis, { desc = "Git diff this" }) - vim.keymap.set('n', '=r', gitsigns.reset_hunk, { desc = "Git reset hunk" }) - vim.keymap.set('n', '=s', gitsigns.stage_hunk, { desc = "Git stage hunk" }) - vim.keymap.set('v', '=s', function() gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end, - { desc = "Git stage hunk" }) - - -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) - vim.keymap.set('n', '', fzf.lsp_references, { desc = "Find References" }) - vim.keymap.set('n', '', fzf.lsp_definitions, { desc = "Find References" }) - end -}) - --- lsp format selected range -function LSPRangeFormatFunction() - vim.lsp.buf.format({ - async = true, - range = { - ["start"] = vim.api.nvim_buf_get_mark(0, "<"), - ["end"] = vim.api.nvim_buf_get_mark(0, ">"), - } - }) -end - -local enable_this_lsp = {} -if vim.loop.os_gethostname() == 'ccflow' then - -- VUE and Typescript as of vue-language-server 3.0.x - -- taken from: - -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#vtsls - local vue_language_server_path = '/home/saschal/.config/yarn/global/node_modules' - local vue_plugin = { - name = '@vue/typescript-plugin', - location = vue_language_server_path, - languages = { 'vue' }, - configNamespace = 'typescript', - } - local vtsls_config = { - settings = { - vtsls = { - tsserver = { - globalPlugins = { - vue_plugin, - }, - }, - }, - }, - filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, - } - vim.lsp.config('vtsls', vtsls_config) - - -- enable this list of lsps - enable_this_lsp = { - 'vue_ls', - 'vtsls', - 'gopls', - 'bashls', - 'html', - 'lua_ls', - 'jsonls', -- arch extra: vscode-json-languageserver - 'kotlin_lsp', -- arch aur: kotlin-lsp-bin - 'lemminx', -- arch aur: lemminx - 'clangd', - 'basedpyright', - 'wgsl_analyzer', - } -else - -- any lsp which should be enabled in all situations - enable_this_lsp = { - } -end - -for l in pairs(enable_this_lsp) do - vim.lsp.enable(enable_this_lsp[l]) -end - - --- add autoformat to Dioxus projects -vim.api.nvim_create_autocmd("BufWritePost", { - pattern = "*.rs", - callback = function() - local cwd = vim.lsp.buf.list_workspace_folders() - if not (cwd == nil) then - if vim.fn.filereadable(cwd[1] .. "/Dioxus.toml") == 1 then - local command = "dx fmt --file %" - vim.cmd("silent ! " .. command) - -- vim.notify(command) - end - end - end, -}) +-- attach using autocommand and setup keybindings +vim.api.nvim_create_autocmd('LspAttach', { + group = vim.api.nvim_create_augroup('sl.lsp', {}), + callback = function(args) + -- See `:help vim.lsp.*` for documentation on any of the below functions + local bufopts = { noremap = true, silent = true, buffer = args.buf } + vim.keymap.set('n', 'K', vim.lsp.buf.hover, { desc = "LSP show signature", unpack(bufopts) }) + vim.keymap.set('n', 'wa', vim.lsp.buf.add_workspace_folder, + { desc = "Workspace add folder", unpack(bufopts) }) + vim.keymap.set('n', 'wr', vim.lsp.buf.remove_workspace_folder, + { desc = "Workspace remove folder", unpack(bufopts) }) + vim.keymap.set('n', 'wl', function() + print(vim.inspect(vim.lsp.buf.list_workspace_folders())) + end, { desc = "Workspace list folders", unpack(bufopts) }) + vim.keymap.set('n', 'rn', vim.lsp.buf.rename, { desc = "LSP Rename", unpack(bufopts) }) + vim.keymap.set("n", "f", function() + vim.lsp.buf.format({ async = true }) + end, { desc = "LSP Format buffer", unpack(bufopts) }) + vim.keymap.set("n", 'F', ":silent !dx fmt --file %", { desc = "DX format rsx! regions", unpack(bufopts) }) + vim.keymap.set("v", "f", LSPRangeFormatFunction, { desc = "LSP Format region" }) + + -- 2024-09-09 - some ccflow commands for diagnostics, symbols and code actions + local fzf = require('fzf-lua') + vim.keymap.set('n', 'd', fzf.diagnostics_document, { desc = "Document diagnostics" }) + vim.keymap.set('n', 'D', fzf.diagnostics_workspace, { desc = "Workspace diagnostics" }) + vim.keymap.set('n', 'e', function() + local new_config = not vim.diagnostic.config().virtual_lines + vim.diagnostic.config({ virtual_lines = new_config }) + end, { desc = "Virtual line diagnostics" }) + vim.keymap.set('n', 'E', vim.diagnostic.open_float, { desc = "Popup diagnostics" }) + vim.keymap.set('n', 's', fzf.lsp_document_symbols, { desc = "Doc symbols" }) + vim.keymap.set('n', 'c', fzf.lsp_code_actions, { desc = "Code Actions" }) + vim.keymap.set('n', '[', vim.diagnostic.goto_prev, { desc = "Previous diagnostics" }) + vim.keymap.set('n', ']', vim.diagnostic.goto_next, { desc = "Previous diagnostics" }) + + local gitsigns = require('gitsigns') + vim.keymap.set('n', '=l', ":NeogitLogCurrent", { desc = "Neogit: log for this file" }) + vim.keymap.set('n', '==', gitsigns.preview_hunk_inline, { desc = "Git hunk preview" }) + vim.keymap.set('n', '=B', gitsigns.blame, { desc = "Git blame file" }) + vim.keymap.set('n', '=D', function() gitsigns.diffthis('~') end, { desc = "Git diff this (~)" }) + vim.keymap.set('n', '=R', gitsigns.reset_buffer, { desc = "Git reset file" }) + vim.keymap.set('n', '=S', gitsigns.stage_buffer, { desc = "Git stage file" }) + vim.keymap.set('n', '=[', gitsigns.prev_hunk, { desc = "Git previous hunk" }) + vim.keymap.set('n', '=]', gitsigns.next_hunk, { desc = "Git next hunk" }) + vim.keymap.set('n', '=b', gitsigns.blame_line, { desc = "Git blame line" }) + vim.keymap.set('n', '=d', gitsigns.diffthis, { desc = "Git diff this" }) + vim.keymap.set('n', '=r', gitsigns.reset_hunk, { desc = "Git reset hunk" }) + vim.keymap.set('n', '=s', gitsigns.stage_hunk, { desc = "Git stage hunk" }) + vim.keymap.set('v', '=s', function() gitsigns.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') }) end, + { desc = "Git stage hunk" }) + + -- vim.keymap.set('n', 'gr', vim.lsp.buf.references, bufopts) + vim.keymap.set('n', '', fzf.lsp_references, { desc = "Find References" }) + vim.keymap.set('n', '', fzf.lsp_definitions, { desc = "Find References" }) + end +}) + +-- lsp format selected range +function LSPRangeFormatFunction() + vim.lsp.buf.format({ + async = true, + range = { + ["start"] = vim.api.nvim_buf_get_mark(0, "<"), + ["end"] = vim.api.nvim_buf_get_mark(0, ">"), + } + }) +end + +local enable_this_lsp = {} +if vim.loop.os_gethostname() == 'ccflow' then + -- VUE and Typescript as of vue-language-server 3.0.x + -- taken from: + -- https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#vtsls + local vue_language_server_path = '/home/saschal/.config/yarn/global/node_modules' + local vue_plugin = { + name = '@vue/typescript-plugin', + location = vue_language_server_path, + languages = { 'vue' }, + configNamespace = 'typescript', + } + local vtsls_config = { + settings = { + vtsls = { + tsserver = { + globalPlugins = { + vue_plugin, + }, + }, + }, + }, + filetypes = { 'typescript', 'javascript', 'javascriptreact', 'typescriptreact', 'vue' }, + } + vim.lsp.config('vtsls', vtsls_config) + + -- enable this list of lsps + enable_this_lsp = { + 'vue_ls', + 'vtsls', + 'gopls', + 'bashls', + 'html', + 'lua_ls', + 'jsonls', -- arch extra: vscode-json-languageserver + 'kotlin_lsp', -- arch aur: kotlin-lsp-bin + 'lemminx', -- arch aur: lemminx + 'clangd', + 'basedpyright', + 'wgsl_analyzer', + } +else + -- any lsp which should be enabled in all situations + enable_this_lsp = { + } +end + +for l in pairs(enable_this_lsp) do + vim.lsp.enable(enable_this_lsp[l]) +end + + +-- add autoformat to Dioxus projects +vim.api.nvim_create_autocmd("BufWritePost", { + pattern = "*.rs", + callback = function() + local cwd = vim.lsp.buf.list_workspace_folders() + if not (cwd == nil) then + if vim.fn.filereadable(cwd[1] .. "/Dioxus.toml") == 1 then + local command = "dx fmt --file %" + vim.cmd("silent ! " .. command) + -- vim.notify(command) + end + end + end, +}) diff --git a/lua/options.lua b/lua/options.lua index b685494..8a78ed3 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -1,70 +1,96 @@ ---------------------------------------------------- --- --- Some general setup taken from some tutorial --- which I have forgotten --- --------------------------------------------------- - --- Hint: use `:h