repositories / dotfiles

dotfiles

bugabingas dorkfiles

owned by bugabinga

neovim: change keybinds wo whichkey

6c8fe5a751365a3f845a24546d1451ecab98da4d

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

unsigned

Browse filesCompare with HEAD

Changed files (6)

+237 / −116 text lines

Diff layout

git/gitconfig

Modified

+4 / −0 text lines

5252[commit]
5353 verbose = true
55[help]
56 # try to automatically correct mispelled git commands
57 autocorrect = 7
5559# In order to have host-specific configuration, I include additional settings here.
5660# On each host a different file might be symlinked into '.gitconfig.include'.
5761[include]

neovim/lua/general_editor_settings.lua

Modified

+2 / −10 text lines

2020 -- How many milliseconds must pass before neovim decides I was "idle"
2121 vim.opt.updatetime = 250
2222 -- How long to wait between key sequences in order to chain them. e.g. <LEADER>b
23 vim.opt.timeoutlen = 350
23 -- This setting affects the which-key plugin.
24 vim.opt.timeoutlen = 700
2425 -- I do not care for folding
2526 vim.opt.foldenable = false
2627 vim.opt.cursorline = true
27 -- Highlight the cursor line in the current buffer
28 autocommand({
29 show_cursor_line_in_active_window = {
30 [[WinLeave * lua vim.opt.cursorline = false]],
31 [[WinEnter * lua vim.opt.cursorline = true]],
32 [[InsertEnter * lua vim.opt.cursorline = false]],
33 [[InsertLeave * lua vim.opt.cursorline = true]],
34 },
35 })
3628 -- integrate Nushell with nvim
3729 -- all nushell builtins (ls, sys, etc.) print their output with escape codes, which nvim cannot parse.
3830 -- only time will tell if this will annoy me so much as to change it...

neovim/lua/keybinds.lua

Modified

+70 / −43 text lines

33-- The benefit of assembling all keybinds here is, that they are easy to find.
44-- But unfortunataly, by collecting them here, they are placed "far" from their logical place, i.e. the plugins configuration.
55return function(cheatsheet)
6 -- Delegator over nvim_set_keymap, that sets some default options
7 -- TODO expose this function as module
8 local map = function(mode, left_hand_side, right_hand_side, options)
9 local default_options = { noremap = true, unique = true }
10 if options then
11 default_options = vim.tbl_extend("force", default_options, options)
12 end
13 vim.api.nvim_set_keymap(mode, left_hand_side, right_hand_side, default_options)
14 end
156 -- Let the <LEADER> key be <SPACE>
167 vim.g.mapleader = " "
8 cheatsheet("")
9 cheatsheet("The LEADER key is SPACE! Press it to show all bindings.")
10 cheatsheet("")
18 map("n", "<LEADER><F9>", [[<CMD>tabnew $MYVIMRC<CR>]])
19 cheatsheet("LEADER + F9 => Open nvim configuration in a new tab!")
21 map("n", "<LEADER><F10>", [[<CMD>PluginsSync<CR>]])
22 cheatsheet("LEADER + F10 => Sync nvim plugins configuration!")
24 map("n", "<LEADER>b", [[<CMD>Telescope buffers<CR>]])
25 cheatsheet("LEADER + b => Select a buffer")
27 map("n", "<LEADER>f", [[<CMD>Telescope file_browser<CR>]])
28 cheatsheet("LEADER + f => Select a file")
30 map("n", "<LEADER>e", [[<CMD>NvimTreeToggle<CR>]])
31 cheatsheet("LEADER + e => Toggle file explorer")
32
33 map("n", "<LEADER>t", [[<CMD>TroubleToggle<CR>]])
34 cheatsheet("LEADER + t => Toggle the Trouble window.")
36 cheatsheet("")
12 local keys = require("which-key")
3814 --Open up a URL under the cursor
3915 local opener_program = ""
4723 -- What should we do on unknown platforms? We guess...
4824 opener_program = "firefox"
4925 end
50 map("n", "gx", [[<CMD>lua require'spawn'(']] .. opener_program .. [[',{ vim.fn.expand('<cfile>') } )<CR>]])
51 cheatsheet("gx => Open URL under cursor")
53 cheatsheet("")
54 cheatsheet("ALT + j => Move line(s) down")
55 cheatsheet("ALT + k => Move line(s) up")
56 map("n", "<A-j>", [[<CMD>move .+1<CR>==]])
57 map("n", "<A-k>", [[<CMD>move .-2<CR>==]])
58 map("i", "<A-j>", [[<ESC><CMD>move .+1<CR>==gi]])
59 map("i", "<A-k>", [[<ESC><CMD>move .-2<CR>==gi]])
60 map("x", "<A-j>", [[<ESC><CMD>'<,'>move'>+1<CR>gv=gv]])
61 map("x", "<A-k>", [[<ESC><CMD>'<,'>move'<-2<CR>gv=gv]])
62
27 -- bundle all mappings under LEADER here
28 keys.register({
29 ["<F9>"] = { [[<CMD>tabnew $MYVIMRC<CR>]], "Open Nvim Configuration" },
30 ["<F10>"] = { [[<CMD>PluginsSync<CR>]], "Sync Plugins" },
31 ["<F11>"] = { [[<CMD>PluginsCompile<CR>]], "Compile Plugins" },
32 f = {
33 name = "file operations",
34 f = { [[<CMD>Telescope find_files<CR>]], "Find File" },
35 b = { [[<CMD>Telescope buffers<CR>]], "Open a Buffer" },
36 r = { [[<CMD>Telescope oldfiles<CR>]], "Open Recent File" },
37 e = { [[<CMD>NvimTreeToggle<CR>]], "Toggle File Explorer" },
38 },
39 g = {
40 name = "goto navigation",
41 t = { [[<CMD>TroubleToggle<CR>]], "Toggle Trouble Window" },
42 x = {
43 "<CMD>lua require'spawn'('" .. opener_program .. "',{vim.fn.expand('<cfile>')})<CR>",
44 "Open Url Under Cursor",
45 },
46 },
47 a = {
48 name = "code operations",
49 o = { [[<CMD>SymbolsOutline<CR>]], "Toggle Outline" },
50 },
51 }, {
52 prefix = "<LEADER>",
53 })
55 cheatsheet("")
56 cheatsheet("ALT + j => Move line(s) down")
57 cheatsheet("ALT + k => Move line(s) up")
58 keys.register({
59 ["<A-j>"] = { [[<CMD>move .+1<CR>==]], "Move Current Line(s) Up" },
60 ["<A-k>"] = { [[<CMD>move .-2<CR>==]], "Move Current Line(s) Down" },
61 })
62 keys.register({
63 ["<A-j>"] = { [[<ESC><CMD>move .+1<CR>==gi]], "Move Current Line(s) Up" },
64 ["<A-k>"] = { [[<ESC><CMD>move .-2<CR>==gi]], "Move Current Line(s) Down" },
65 }, {
66 mode = "i",
67 })
68 keys.register({
69 ["<A-j>"] = { [[<ESC><CMD>'<,'>move'>+1<CR>gv=gv]], "Move Current Line(s) Up" },
70 ["<A-k>"] = { [[<ESC><CMD>'<,'>move'<-2<CR>gv=gv]], "Move Current Line(s) Down" },
71 }, {
72 mode = "x",
73 })
6375 -- 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>")
76 -- Not sure why some bindings have to be escaped with which-key but not when using nvim api directly...
77 local escape = function(string)
78 return vim.api.nvim_replace_termcodes(string, true, true, true)
79 end
80 keys.register({
81 ["<ESC>"] = { escape([[<C-\><C-n>]]), "Escape terminal mode" },
82 ["<C-w>"] = { [[<ESC><C-w>]], "Delete Word" },
83 ["<A-1>"] = { [[<CMD>lua require'FTerm'.toggle()<CR>]], "Toggle the Terminal" },
84 }, {
85 mode = "t",
86 })
87 cheatsheet("")
88 cheatsheet("ALT + 1 => Toggle the Terminal")
89 cheatsheet("")
90 keys.register({
91 ["<A-1>"] = { [[<CMD>lua require'FTerm'.toggle()<CR>]], "Toggle the Terminal" },
92 })
6794 -- Clear highlighted search results whenever ESC is hit
68 map("n", "<ESC>", ":nohlsearch<CR>", { unique = false, silent = true })
95 keys.register({ ["<ESC>"] = { [[<CMD>nohlsearch<CR>]], "Clear Highlighted Text" } })
6996end

neovim/lua/lsp.lua

Modified

+106 / −38 text lines

66 print("LSP " .. client.name .. " [" .. client.id .. "] " .. "started.")
88 -- enable lsp-powered auto-completion
9 -- FIXME: I cannot seem to configure this plugin to my liking.
10 require("completion").on_attach()
9 local cmp = require("cmp")
10 local types = require("cmp.types")
1111 -- adds icons into the completion ui
12 require"lspkind".init()
12 local lspkind = require("lspkind")
13 -- TODO define snippets in some other file...
14 local snippets = require("snippets")
15 cmp.setup({
16 snippet = {
17 expand = function(arguments)
18 --FIXME no clue if this actually does something..
19 snippets.lookup_snippet(vim.o.filetype, arguments.body)
20 end,
21 },
22 completion = {
23 autocomplete = false,
24 },
25 confirmation = { default_behaviour = types.cmp.ConfirmBehavior.Insert },
26 mapping = {
27 ["<C-d>"] = cmp.mapping.scroll_docs(-4),
28 ["<C-f>"] = cmp.mapping.scroll_docs(4),
29 ["<C-n>"] = cmp.mapping.complete(),
30 ["<C-j>"] = cmp.mapping.select_next_item(),
31 ["<C-k>"] = cmp.mapping.select_prev_item(),
32 ["<C-e>"] = cmp.mapping.abort(),
33 ["<C-y>"] = cmp.mapping.confirm({ select = true }),
34 },
35 formatting = {
36 format = function(_, vim_item)
37 vim_item.kind = lspkind.presets.default[vim_item.kind]
38 return vim_item
39 end,
40 },
41 sources = {
42 { name = "nvim_lsp" },
43 { name = "nvim_lua" }, -- this source only makes sense in neovim lua files...
44 { name = "buffer" },
45 { name = "path" },
46 { name = "emoji" },
47 { name = "calc" },
48 },
49 })
50 -- Configure diagnostics to only show up on file save
51 vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
52 signs = true,
53 underline = false,
54 virtual_text = false,
55 -- FIXME these options are not merged yet
56 --[[ show_diagnostic_autocmds = { "BufWritePost" },
57 diagnostic_delay = 500, ]]
58 -- TODO
59 -- * clear diagnostics on enter i
60 })
61 local keys = require("which-key")
62 keys.register({
63 g = {
64 name = "Goto Navigation",
65 ["D"] = { [[<CMD>lua vim.lsp.buf.declaration()<CR>]], "Goto Declaration" },
66 ["d"] = { [[<CMD>lua vim.lsp.buf.definition()<CR>]], "Goto Definition" },
67 ["i"] = { [[<CMD>lua vim.lsp.buf.implementation()<CR>]], "Goto Implementation" },
68 ["t"] = { [[<CMD>lua vim.lsp.buf.type_definition()<CR>]], "Goto Type Definition" },
69 ["w"] = { [[<CMD>lua vim.lsp.buf.document_symbol()<CR>]], "Goto Document Symbol" },
70 ["W"] = { [[<CMD>lua vim.lsp.buf.workspace_symbol()<CR>]], "Goto Workspace Symbol" },
71 ["n"] = { [[<CMD>lua vim.lsp.diagnostic.goto_next()<CR>]], "Goto Next Diagnostic" },
72 ["N"] = { [[<CMD>lua vim.lsp.diagnostic.goto_prev()<CR>]], "Goto Previous Diagnostic" },
73 },
74 a = {
75 name = "Code Operations",
76 ["h"] = { [[<CMD>lua vim.lsp.buf.hover()<CR>]], "Show Hover" },
77 ["d"] = {
78 [[<CMD>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>]],
79 "Show Diagnostics on Current Line",
80 },
81 ["s"] = { [[<CMD>lua vim.lsp.buf.signature_help()<CR>]], "Show Signature Help" },
82 ["f"] = { [[<CMD>lua vim.lsp.buf.code_action()<CR>]], "Code Actions..." },
83 ["r"] = { [[<CMD>lua vim.lsp.buf.rename()<CR>]], "Rename" },
84 ["="] = { [[<CMD>lua vim.lsp.buf.formatting()<CR>]], "Format" },
14 -- hook lsp into vim autocomplete in insert mode
15 vim.api.nvim_buf_set_option(buffer_number, "omnifunc", "v:lua.vim.lsp.omnifunc")
17 local map = function(type, key, value)
18 vim.api.nvim_buf_set_keymap(buffer_number, type, key, value, { noremap = true, silent = true })
19 end
21 map("n", "<LEADER>gD", "<CMD>lua vim.lsp.buf.declaration()<CR>")
22 map("n", "<LEADER>gd", "<CMD>lua vim.lsp.buf.definition()<CR>")
23 map("n", "<LEADER>gr", "<CMD>lua vim.lsp.buf.references()<CR>")
24 map("n", "<LEADER>gi", "<CMD>lua vim.lsp.buf.implementation()<CR>")
25 map("n", "<LEADER>gt", "<CMD>lua vim.lsp.buf.type_definition()<CR>")
26 map("n", "<LEADER>gw", "<CMD>lua vim.lsp.buf.document_symbol()<CR>")
27 map("n", "<LEADER>gW", "<CMD>lua vim.lsp.buf.workspace_symbol()<CR>")
29 map("n", "<LEADER>ah", "<CMD>lua vim.lsp.buf.hover()<CR>")
30 map("n", "<LEADER>as", "<CMD>lua vim.lsp.buf.signature_help()<CR>")
31 map("n", "<LEADER>af", "<CMD>lua vim.lsp.buf.code_action()<CR>")
32 map("n", "<LEADER>ar", "<CMD>lua vim.lsp.buf.rename()<CR>")
33 map("n", "<LEADER>a=", "<CMD>lua vim.lsp.buf.formatting()<CR>")
34 map("n", "<LEADER>ai", "<CMD>lua vim.lsp.buf.incoming_calls()<CR>")
35 map("n", "<LEADER>ao", "<CMD>lua vim.lsp.buf.outgoing_calls()<CR>")
37 map("n", "<LEADER>n", "<CMD>lua vim.lsp.diagnostic.goto_next()<CR>")
38 map("n", "<LEADER>N", "<CMD>lua vim.lsp.diagnostic.goto_prev()<CR>")
39 map("n", "<LEADER><LEADER>", "<CMD>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>")
86 ["R"] = { [[<CMD>lua vim.lsp.buf.references()<CR>]], "Show References" },
87 ["i"] = { [[<CMD>lua vim.lsp.buf.incoming_calls()<CR>]], "Show Incoming Calls" },
88 ["o"] = { [[<CMD>lua vim.lsp.buf.outgoing_calls()<CR>]], "Show Outgoind Calls" },
89 },
90 }, {
91 prefix = "<LEADER>",
92 buffer = buffer_number,
93 })
4094 end
4296 local lsp = require("lspconfig")
98 local capabilities = vim.lsp.protocol.make_client_capabilities()
99 capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
44101 -- Nvim lua configuration LSP
45102 local neovim_runtime_path = vim.split(package.path, ";")
46103 table.insert(neovim_runtime_path, "lua/?.lua")
63120 neovim_lua_library[lua_path] = true
64121 end
65122 end
66 local sumneko_home = "~/Workspace/sua-language-server"
123 local sumneko_home = "~/Workspace/lua-language-server"
67124 if system_name == "Windows" then
68125 sumneko_home = "W:/misc/lua-language-server"
69126 end
72129 --TODO: How to switch this configuration based upon if we are editing neovim configuration or just any Lua file/project?
73130 lsp.sumneko_lua.setup({
74131 on_attach = integrate_into_neovim,
132 capabilites = capabilities,
75133 cmd = {
76134 sumneko_home .. "/bin/" .. system_name .. "/lua-language-server",
77135 "-E",
87145 diagnostics = {
88146 enable = true,
89147 disable = "trailing-space",
90 globals = { "vim" },
148 globals = { "vim", "_G", "Dump" },
91149 },
92150 hint = {
93151 enable = true,
100158 telemetry = {
101159 enable = true,
102160 },
103 globals = {
104 "cheatsheet",
105 },
106161 },
107162 },
108163 })
110165 -- Markdown Notes (Zettelkasten) LSP
111166 lsp.zeta_note.setup({
112167 on_attach = integrate_into_neovim,
168 capabilites = capabilities,
113169 cmd = { "zeta-note" },
114170 })
116172 -- YAML LSP
117173 lsp.yamlls.setup({
118174 on_attach = integrate_into_neovim,
175 capabilites = capabilities,
119176 --FIXME: Only works on Windows
120177 cmd = { "yaml-language-server.cmd", "--stdio" },
121178 root_dir = function()
126183 -- Zig LSP
127184 -- FIXME: ZLS is very tied to the specific version of the zig compiler one uses.
128185 -- we need to build our own version for 0.8.0 because it is not done upstream yet
129 -- lsp.zls.setup({ on_attach = integrate_into_neovim })
186 -- lsp.zls.setup({
187 -- on_attach = integrate_into_neovim,
188 -- capabilites = capabilities,
189 -- })
131191 -- LLVM Clang LSP
132 lsp.clangd.setup({ on_attach = integrate_into_neovim })
192 lsp.clangd.setup({
193 on_attach = integrate_into_neovim,
194 capabilites = capabilities,
195 })
134197 -- JSON LSP
135198 lsp.jsonls.setup({
136199 on_attach = integrate_into_neovim,
200 capabilites = capabilities,
137201 --FIXME: Only works on Windows
138202 cmd = { "vscode-json-language-server.cmd", "--stdio" },
139203 commands = {
147211 })
149213 -- GraphViz Dot LSP
150 lsp.dotls.setup({ on_attach = integrate_into_neovim })
214 lsp.dotls.setup({
215 on_attach = integrate_into_neovim,
216 capabilites = capabilities,
217 })
152219 -- Null-ls
153220 local nls = require("null-ls")
155222 nls.setup({
156223 debug = false,
224 capabilites = capabilities,
157225 -- Format: [CODE] MESSAGE (SOURCE)
158226 diagnostics_format = "[#{c}] #{m} (#{s})",
159227 sources = {

neovim/lua/plugins.lua

Modified

+54 / −24 text lines

2828 plugin_package = plugin_package,
2929 display = {
3030 non_interactive = non_interactive,
31 open_fn = require("packer.util").float,
3231 },
3332 profile = {
3433 enable = false,
6766 use({
6867 "folke/which-key.nvim",
6968 config = function()
70 require("which-key").setup({})
69 local key_labels = { ["<space>"] = "SPACE", ["<cr>"] = "ENTER", ["<tab>"] = "TAB", ["."] = "DOT" }
70 for f_key_number = 1, 12 do
71 key_labels["<F" .. f_key_number .. ">"] = "F" .. f_key_number
72 end
74 require("which-key").setup({
75 marks = true,
76 registers = true,
77 spelling = { enabled = true, suggestions = 5 },
78 key_labels = key_labels,
79 window = { border = "single" },
80 })
7181 end,
7282 })
108118 require("nvim-treesitter.install").compilers = { "clang" }
109119 require("nvim-treesitter.configs").setup({
110120 ensure_installed = {
111 "zig",
121 -- "zig",
112122 "java",
113123 "rust",
114124 "lua",
117127 "json",
118128 "jsonc",
119129 "c",
120 "comment",
130 -- "comment",
121131 "html",
122132 "css",
123133 "javascript",
126136 },
127137 highlight = { enable = true },
128138 incremental_selection = {
129 enable = true,
139 enable = false,
130140 keymaps = {
131141 init_selection = "<C-Up>",
132142 node_incremental = "<C-Up>",
134144 scope_incremental = "<A-Up>",
135145 },
136146 },
137 indent = { enable = true },
138 query_linter = { enable = true, use_virtual_text = true, lint_events = { "BufWrite" } },
147 indent = { enable = false },
148 query_linter = { enable = false, use_virtual_text = true, lint_events = { "BufWrite" } },
139149 refactor = {
140 highlight_definitions = { enable = true },
141 smart_rename = { enable = true, keymaps = { smart_rename = "<LEADER>r" } },
150 highlight_definitions = { enable = false },
151 smart_rename = { enable = false, keymaps = { smart_rename = "<LEADER>r" } },
142152 navigation = {
143 enable = true,
153 enable = false,
144154 keymaps = { goto_next_usage = "<a-.>", goto_previous_usage = "<a-,>" },
145155 },
146156 },
155165 use({
156166 "nvim-treesitter/playground",
157167 config = function()
158 local cheatsheet = require("cheatsheet").print
159 cheatsheet("")
160 cheatsheet(
161 ":TSHighlightCapturesUnderCursor => This command shows the highlight group under the cursor, when TreeSitter is used"
162 )
168 local keys = require("which-key")
169 keys.register({
170 ["<space>."] = {
171 "<CMD>TSHighlightCapturesUnderCursor<CR>",
172 "Shows the highlight group under the cursor, when TreeSitter is used.",
173 },
174 })
163175 end,
164176 })
221233 -- Preprepared collection of glue code for neovim lsp-client and thrid party lsp servers.
222234 "neovim/nvim-lspconfig",
223235 -- Completions support, that integrates advanced nvim features (LSP+treesitter)
224 "nvim-lua/completion-nvim",
236 "norcalli/snippets.nvim",
237 "hrsh7th/cmp-buffer",
238 "hrsh7th/cmp-calc",
239 "hrsh7th/cmp-emoji",
240 "hrsh7th/cmp-path",
241 "hrsh7th/cmp-nvim-lsp",
242 "hrsh7th/cmp-nvim-lua",
243 "hrsh7th/nvim-cmp",
225244 -- Icons for completion UI
226245 "onsails/lspkind-nvim",
227246 -- dependency of nvim-lsputils
237256 -- TODO: integrate with nvim-dap debugger
238257 -- use { 'mfussenegger/nvim-jdtls', opt = true }
239258 --
240 -- Nicer view than :registers, also shows popup on CTRL-R in I-mode
241 use({ "tversteeg/registers.nvim", opt = true, command = "Registers", keys = { "i", "<C-R>" } })
243260 -- comment and uncomment lines
244261 use({ "b3nj5m1n/kommentary" })
246263 -- smooth scrolling
247 -- TODO: configure mappings to overide duration
248 -- currently the scroll steps a pretty slow
264 -- Its possible Neovide will support smooth scrool soon: https://github.com/neovim/neovim/issues/15075
265 -- When it does, this plugin is redundant, if nvim runs in Neovide.
249266 use({
250267 "karb94/neoscroll.nvim",
251268 config = function()
268285 command = "VBox",
269286 })
271 -- convenient lua abstraction over the nvim keymap function
272 -- TODO: use it throughout the code
273 use("Iron-E/nvim-cartographer")
288 -- Show outline view based on LSP
289 use({ "simrat39/symbols-outline.nvim" })
291 -- Make using terminals in Neovim more comfortable
292 use({
293 "numtostr/FTerm.nvim",
294 config = function()
295 require("FTerm").setup({ cmd = "nu", border = "single" })
296 end,
297 })
275299 -- automatically size splits reasonably
276 use("beauwilliams/focus.nvim")
300 use({
301 "beauwilliams/focus.nvim",
302 config = function()
303 local focus = require("focus")
304 focus.signcolumn = false
305 end,
306 })
277307 end
279309 -- the plugin module always delegates to packer, ensuring that at all times init configures packer correctly

nushell/nurc

Modified

+1 / −1 text lines

116116 ...rest: string # Arguments to man
117117] {
118118 if (sys).host.name == "Windows" {
119 start (build-string https://man.cx/ ($rest | to-string))
119 start (build-string https://man.archlinux.org/man/ ($rest | to-string))
120120 } {
121121 exec man $rest
122122 }