aboutsummaryrefslogtreecommitdiff
path: root/nvim/lua/config/keymaps.lua
blob: c54247c5b6239c73cc7d50f883b04248891f744c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
local M = {}

local map = vim.keymap.set

function M.lsp(buffer, client)
  local opts = {
    buffer = buffer,
    noremap = true,
    silent = true,
  }

  map("n", "gd", vim.lsp.buf.definition, opts)
  map("n", "gD", vim.lsp.buf.declaration, opts)
  map("n", "gr", vim.lsp.buf.references, opts)
  map("n", "gi", vim.lsp.buf.implementation, opts)
  map("n", "K", vim.lsp.buf.hover, opts)
  map("n", "<leader>rn", vim.lsp.buf.rename, opts)
  map("n", "<leader>ca", vim.lsp.buf.code_action, opts)
  map("n", "<leader>cf", function() vim.lsp.buf.format({ async = true; }) end, opts)

  if client and client.name == "clangd" then
    map("n", "<leader>hs", "<cmd>ClangdSwitchSourceHeader<cr>", opts)
  end
end

function M.telescope()
  local opts = {
    noremap = true,
    silent = true,
  }

  map("n", "<leader>ff", function()
    require("telescope.builtin").find_files()
  end, opts)

  map("n", "<leader>fg", function()
    require("telescope.builtin").live_grep()
  end, opts)

  map("n", "<leader>fb", function()
    require("telescope.builtin").buffers()
  end, opts)

  map("n", "<leader>fh", function()
    require("telescope.builtin").help_tags()
  end, opts)

  map("n", "<leader>dd", function()
    require("telescope.builtin").diagnostics()
  end, opts)
end

function M.global()
  local opts = {
    noremap = true,
    silent = true,
  }

  map("n", "ö", "}", opts)
  map("n", "ä", "{", opts)

  map("n", "<leader>K", function()
    vim.diagnostic.open_float({ scope = "cursor", border = "rounded" })
  end, opts)
  map("n", "<leader>q", vim.diagnostic.setloclist, opts)

  map("n", "[d", function()
    vim.diagnostic.jump_prev({ wrap = false })
  end, opts)

  map("n", "]d", function()
    vim.diagnostic.jump_next({ wrap = false })
  end, opts)

  map("n", "[e", function()
    vim.diagnostic.jump_prev({
      severity = vim.diagnostic.severity.ERROR,
      wrap = false
    })
  end, opts)

  map("n", "]e", function()
    vim.diagnostic.jump_next({
      severity = vim.diagnostic.severity.ERROR,
      wrap = false
    })
  end, opts)

  vim.keymap.set("n", "<leader>ts", function()
    vim.opt_local.spell = not vim.opt_local.spell:get()
  end, { desc = "Toggle spell checking" })
end

return M