summaryrefslogtreecommitdiff
path: root/nvim/lua/keymaps.lua
blob: 0b729329c131a1a1ade9ecc38550ceadb26a5a78 (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
local map = vim.keymap.set;
local builtin = require('telescope.builtin')
local opts = { noremap = true, silent = true}

map('', '<Up>', 'gk', opts)
map('', '<Down>', 'gj', opts)
map('n', 'J', 'mzJ`z', opts)

map('', 'o', 'o<Esc>', opts)
map('', 'O', 'O<Esc>', opts)

map('i', '<C-Space>', '<Esc>', opts)
map('v', '<C-Space>', '<Esc>', opts)
map('t', '<C-Space>', '<C-\\><C-n>', opts)
map('v', '<PageDown>', ":m '>+1<CR>gv=gv", opts)
map('v', '<PageUp>', ":m '<-2<CR>gv=gv", opts)

map('n', 'Q', '<nop>')

--
-- telescope
-- 
map('n', '<leader>pf', builtin.find_files, {})
map('n', '<leader>pg', function()
    -- If the directory is not a git repository, fallback to regular find_files.
    if pcall(builtin.git_files) then
    else
        pcall(builtin.find_files)
    end
end, {})
map('n', '<leader>fs', function()
    builtin.grep_string({ search = vim.fn.input("Grep > ") })
end, {})
--

map("n", "-", "<CMD>Oil<CR>", { desc = "Open parent directory" })
map('n', '<leader>u', vim.cmd.UndotreeToggle)
map('n', '<PageUp>', vim.cmd.BufferLineCycleNext)
map('n', '<PageDown>', vim.cmd.BufferLineCyclePrev)
map('n', '<leader>br', vim.cmd.BufDel)

--
-- window resizing
--
-- map('n', '<S-Left>', ':vertical resize -2<CR>', { silent = true })
-- map('n', '<S-Right>', ':vertical resize +2<CR>', { silent = true })
-- map('n', '<S-Up>', ':resize +2<CR>', { silent = true })
-- map('n', '<S-Down>', ':resize -2<CR>', { silent = true })

map('n', '<C-p>', ':MarkdownPreview<CR>', { silent = true })

map('x', 'p', '\"_dP')

map('n', '<leader>y', '\"+y')
map('v', '<leader>y', '\"+y')
map('n', '<leader>Y', '\"+Y')

map('n', '<leader>d', '\"+d')
map('v', '<leader>d', '\"+d')

map('n', '<leader>js', ':vertical botright Repl julia<CR>')
map('n', '<leader>jr', function()
    vim.cmd.ReplSend(string.format('include("%s")', vim.fn.expand('%:p')))
end)
map('n', '<leader>j;', function()
    vim.cmd.ReplSend(string.format('include("%s");', vim.fn.expand('%:p')))
end)

map('n', '<C-h>', vim.cmd.HopWord)

map('n', '<leader>vv', vim.cmd.VimtexCompile)
map('n', '<leader>vc', ':VimtexClean!<CR>')

map('i', '<C-f>', [[<Esc>: silent exec '.!inkscape-figures create "'.getline('.').'" "'.b:vimtex.root.'/figures/"'<CR><CR>:w<CR>]], opts)
map('n', '<C-f>', [[: silent exec '!inkscape-figures edit "'.b:vimtex.root.'/figures/" > /dev/null 2>&1 &'<CR><CR>:redraw!<CR>]], opts)

vim.cmd([[
" press <Tab> to expand or jump in a snippet. These can also be mapped separately
" via <Plug>luasnip-expand-snippet and <Plug>luasnip-jump-next.
imap <silent><expr> <Tab> luasnip#expand_or_jumpable() ? '<Plug>luasnip-expand-or-jump' : '<Tab>' 
]])

map('i', '<S-Tab>', [[<cmd>lua require'luasnip'.jump(-1)<Cr>]], opts)
map('s', '<Tab>', [[<cmd>lua require('luasnip').jump(1)<Cr>]], opts)
map('s', '<Tab>', [[<cmd>lua require('luasnip').jump(-1)<Cr>]], opts)