aboutsummaryrefslogtreecommitdiff
path: root/neovim/.config/nvim/lua/keybinds.lua
blob: d84e5e4c1f76671673a0bfe3ec66e2336f659d05 (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
map = function(m, k, v)
  vim.keymap.set(m, k, v, { silent = true })
end

-- Fix * (Keep the cursor position, don't move to next match)
map("n", "*", "*N")

-- Move line up and down in NORMAL and VISUAL modes
map("n", "<A-j>", "<cmd>move .+1<cr>")
map("n", "<A-k>", "<cmd>move .-2<cr>")
map("x", "<A-j>", ":move '>+1<cr>gv=gv")
map("x", "<A-k>", ":move '<-2<cr>gv=gv")

-- Keep cursor position
map("n", "J", "mzJ`z")

-- Keep cursur in center
map("n", "<C-d>", "<C-d>zz")
map("n", "<C-u>", "<C-u>zz")
map("n", "n", "nzzzv")
map("n", "N", "Nzzzv")

-- Remove to void (and paste)
map("n", "<leader>d", "\"_d")
map("v", "<leader>d", "\"_d")
map("x", "<leader>p", "\"_dP")

-- Format
map("n", "<leader>i", function() vim.lsp.buf.format() end)
-- Edit word
map("n", "<leader>s", [[:%s/\<<C-r><C-w>\>/<C-r><C-w>/gI<Left><Left><Left>]])
-- Make executable
map("n", "<leader>x", "<cmd>!chmod +x %<CR>")
-- Copy file path
map("n", "<leader>y", "<cmd>!echo $(pwd)/% | xclip -selection clipboard<CR>")

-- map("n", "<C-space>", ":Files<CR>")
map("n", "<C-c>", ":!compile %<cr><cr>")

-- Move to the next/previous buffer
-- map("n", "<leader>[", "<CMD>bp<CR>")
-- map("n", "<leader>]", "<CMD>bn<CR>")

-- Move to last buffer
-- map("n", """", "<CMD>b#<CR>")

-- Telescope binds
local Telescope = setmetatable({}, {
  __index = function(_, k)
    if vim.bo.filetype == "NvimTree" then
      vim.cmd.wincmd("l")
    end
    return require("telescope.builtin")[k]
  end,
})

-- Help
map("n", "<leader>fh", Telescope.help_tags)
-- Files with match
map("n", "<leader>ff", Telescope.live_grep)
-- Project files
map("n", "<leader>fp", Telescope.find_files)
-- Changed git files
map("n", "<leader>fc", Telescope.git_status)
-- Git files
map("n", "<leader>fg", function()
  local ok = pcall(Telescope.git_files, { show_untracked = true })
  if not ok then
    Telescope.find_files()
  end
end)

-- Highlighted comments
map("n", "<leader>ft", "<cmd>TodoTelescope<cr>")

-- Hacky update thing
--[[ map("n", "<leader>u", function()
  local ok = pcall(vim.cmd.PackerSync)
  if ok then ok = pcall(vim.cmd.PackerCompile) end
  if ok then ok = pcall(vim.cmd.TSUpdate) end
  if ok then pcall(vim.cmd.Mason) end
end) ]]

exp = {}
exp.map = map