summaryrefslogtreecommitdiffstats
path: root/lua/conf/binds.lua
blob: 2f5673a1262492960dd55f208c7581fa8a533f6c (plain) (blame)
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
local misc = require('core.misc')
local map = misc.map

-- vim binds
vim.g.mapleader = ' ' -- set leader key

map('x', '<leader>p', [["_dP]], { desc = 'Greatest remap of all time.' })
map('n', '<esc>', ':nohlsearch<Bar>:echo<CR>', { desc = 'Clear search.' })
-- move selected text up/down
map('v', '<S-k>', ":m '<-2<CR>gv=gv", { desc = 'Move selected text up.' })
map('v', '<S-j>', ":m '>+1<CR>gv=gv", { desc = 'Move selected text down.' })

-- the cursor STAYS IN THE MIDDLE
map('n', '<S-j>', 'mzJ`z<cmd>delm z<CR>') -- when combining lines
map('n', 'n', 'nzzzv') -- when searching
map('n', 'N', 'Nzzzv')
map('n', '<C-d>', '<C-d>zz') -- half page jumping
map('n', '<C-u>', '<C-u>zz')

map('n', '<leader>x', function() -- execute order 111
  local fn = vim.fn.expand("%:p")
  if vim.fn.getftype(fn) == "file" then
    local perm = vim.fn.getfperm(fn)
    if string.match(perm, "x", 3) then
      vim.notify("Removed executable flags", vim.log.levels.INFO, { title = misc.appid })
      vim.fn.setfperm(fn, string.sub(fn, 1, 2).."-"..string.sub(fn, 4, 5).."-"..string.sub(fn, 7, 8).."-")
    else
      vim.notify("Add executable flags", vim.log.levels.INFO, { title = misc.appid })
      vim.fn.setfperm(fn, string.sub(fn, 1, 2).."x"..string.sub(fn, 4, 5).."x"..string.sub(fn, 7, 8).."x")
    end
  else
    vim.notify("File doesn't exist", vim.log.levels.INFO, { title = misc.appid })
  end
end, { desc = 'toggle executable flag of the file' })

-- tabs
map('n', '[]', '<cmd>tabnew<CR>')
map('n', '][', '<cmd>tabc<CR>')
map('n', '[[', '<cmd>tabp<CR>')
map('n', ']]', '<cmd>tabn<CR>')

-- good spell suggestion ui
-- (stolen from https://github.com/neovim/neovim/pull/25833)
vim.keymap.set('n', 'z=', function()
  local spell_on_choice = vim.schedule_wrap(function(_, idx)
    if type(idx) == 'number' then
      vim.cmd('normal! '..idx..'z=')
    end
  end)

  if vim.v.count > 0 then
    spell_on_choice(nil, vim.v.count)
    return
  end
  local cword = vim.fn.expand('<cword>')
  local prompt = 'Change '..vim.inspect(cword)..' to:'
  vim.ui.select(vim.fn.spellsuggest(cword, vim.o.lines), { prompt = prompt }, spell_on_choice)
end, { desc = 'Shows spelling suggestions' })