diff --git a/docs/manual/hacking/keybinds.md b/docs/manual/hacking/keybinds.md index 8c9e7233..3940466f 100644 --- a/docs/manual/hacking/keybinds.md +++ b/docs/manual/hacking/keybinds.md @@ -30,53 +30,12 @@ There are many settings available in the options. Please refer to the [documentation](https://notashelf.github.io/nvf/options.html#opt-vim.keymaps) to see a list of them. -**nvf** provides a list of helper commands, so that you don't have to write the +**nvf** provides a helper function, so that you don't have to write the mapping attribute sets every time: -- `mkBinding = key: action: desc:` - makes a basic binding, with `silent` set to - true. -- `mkExprBinding = key: action: desc:` - makes an expression binding, with - `lua`, `silent`, and `expr` set to true. -- `mkLuaBinding = key: action: desc:` - makes an expression binding, with `lua`, - and `silent` set to true. +- `mkKeymap`, which mimics neovim's `vim.keymap.set` function -Do note that the Lua in these bindings is actual Lua, and not pasted into a -`:lua` command. Therefore, you should either pass in a function like -`require('someplugin').some_function`, without actually calling it, or you -should define your own functions, for example - -```lua -function() - require('someplugin').some_function() -end -``` - -Additionally, to not have to repeat the descriptions, there's another utility -function with its own set of functions: Utility function that takes two -attribute sets: - -- `{ someKey = "some_value" }` -- `{ someKey = { description = "Some Description"; }; }` - -and merges them into -`{ someKey = { value = "some_value"; description = "Some Description"; }; }` - -```nix -addDescriptionsToMappings = actualMappings: mappingDefinitions: -``` - -This function can be used in combination with the same `mkBinding` functions as -above, except they only take two arguments - `binding` and `action`, and have -different names: - -- `mkSetBinding = binding: action:` - makes a basic binding, with `silent` set - to true. -- `mkSetExprBinding = binding: action:` - makes an expression binding, with - `lua`, `silent`, and `expr` set to true. -- `mkSetLuaBinding = binding: action:` - makes an expression binding, with - `lua`, and `silent` set to true. - -You can read the source code of some modules to see them in action, but their +You can read the source code of some modules to see them in action, but the usage should look something like this: ```nix @@ -90,20 +49,13 @@ in { # Mappings should always be inside an attrset called mappings mappings = { - # mkMappingOption is a helper function from lib, - # that takes a description (which will also appear in which-key), - # and a default mapping (which can be null) - toggleCurrentLine = mkMappingOption "Toggle current line comment" "gcc"; - toggleCurrentBlock = mkMappingOption "Toggle current block comment" "gbc"; - - toggleOpLeaderLine = mkMappingOption "Toggle line comment" "gc"; - toggleOpLeaderBlock = mkMappingOption "Toggle block comment" "gb"; - - toggleSelectedLine = mkMappingOption "Toggle selected comment" "gc"; - toggleSelectedBlock = mkMappingOption "Toggle selected block" "gb"; + workspaceDiagnostics = mkMappingOption "Workspace diagnostics [trouble]" "lwd"; + documentDiagnostics = mkMappingOption "Document diagnostics [trouble]" "ld"; + lspReferences = mkMappingOption "LSP References [trouble]" "lr"; + quickfix = mkMappingOption "QuickFix [trouble]" "xq"; + locList = mkMappingOption "LOCList [trouble]" "xl"; + symbols = mkMappingOption "Symbols [trouble]" "xs"; }; - - }; } ``` @@ -111,56 +63,27 @@ in { # config.nix { config, - pkgs, lib, + options, ... }: let - inherit (lib.modules) mkIf mkMerge; - inherit (lib.nvim.binds) mkSetBinding; + inherit (lib.modules) mkIf; + inherit (lib.nvim.binds) mkKeymap; - cfg = config.vim.plugin; - self = import ./plugindefinition.nix {inherit lib;}; - mappingDefinitions = self.options.vim.plugin; + cfg = config.vim.plugin; - # addDescriptionsToMappings is a helper function from lib, - # that merges mapping values and their descriptions - # into one nice attribute set - mappings = addDescriptionsToMappings cfg.mappings mappingDefinitions; + keys = cfg.mappings; + inherit (options.vim.lsp.trouble) mappings; in { - config = mkIf (cfg.enable) { - # ... - vim.maps.normal = mkMerge [ - # mkSetBinding is another helper function from lib, - # that actually adds the mapping with a description. - (mkSetBinding mappings.findFiles " Telescope find_files") - (mkSetBinding mappings.liveGrep " Telescope live_grep") - (mkSetBinding mappings.buffers " Telescope buffers") - (mkSetBinding mappings.helpTags " Telescope help_tags") - (mkSetBinding mappings.open " Telescope") - - (mkSetBinding mappings.gitCommits " Telescope git_commits") - (mkSetBinding mappings.gitBufferCommits " Telescope git_bcommits") - (mkSetBinding mappings.gitBranches " Telescope git_branches") - (mkSetBinding mappings.gitStatus " Telescope git_status") - (mkSetBinding mappings.gitStash " Telescope git_stash") - - (mkIf config.vim.lsp.enable (mkMerge [ - (mkSetBinding mappings.lspDocumentSymbols " Telescope lsp_document_symbols") - (mkSetBinding mappings.lspWorkspaceSymbols " Telescope lsp_workspace_symbols") - - (mkSetBinding mappings.lspReferences " Telescope lsp_references") - (mkSetBinding mappings.lspImplementations " Telescope lsp_implementations") - (mkSetBinding mappings.lspDefinitions " Telescope lsp_definitions") - (mkSetBinding mappings.lspTypeDefinitions " Telescope lsp_type_definitions") - (mkSetBinding mappings.diagnostics " Telescope diagnostics") - ])) - - ( - mkIf config.vim.treesitter.enable - (mkSetBinding mappings.treesitter " Telescope treesitter") - ) + config = mkIf cfg.enable { + vim.keymaps = [ + (mkKeymap "n" keys.workspaceDiagnostics "Trouble toggle diagnostics" {desc = mappings.workspaceDiagnostics.description;}) + (mkKeymap "n" keys.documentDiagnostics "Trouble toggle diagnostics filter.buf=0" {desc = mappings.documentDiagnostics.description;}) + (mkKeymap "n" keys.lspReferences "Trouble toggle lsp_references" {desc = mappings.lspReferences.description;}) + (mkKeymap "n" keys.quickfix "Trouble toggle quickfix" {desc = mappings.quickfix.description;}) + (mkKeymap "n" keys.locList "Trouble toggle loclist" {desc = mappings.locList.description;}) + (mkKeymap "n" keys.symbols "Trouble toggle symbols" {desc = mappings.symbols.description;}) ]; - # ... }; } ```