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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
local function map(mode, bind, cmd, opts)
opts = opts or {}
opts['noremap'] = true
opts['silent'] = true
if type(bind) == 'table' then
for i in pairs(bind) do
vim.keymap.set(mode, bind[i], cmd, opts)
end
elseif type(bind) == 'string' then
vim.keymap.set(mode, bind, cmd, opts)
else
vim.notify('-- Invalid bind for keymap:\nvim.keymap.set(\''
.. mode .. '\', ' .. bind .. ', \'' .. cmd .. '\')',
vim.log.levels.WARN, {
title = 'Neovim Config',
on_open = function(win)
local buf = vim.api.nvim_win_get_buf(win)
vim.api.nvim_buf_set_option(buf, "filetype", "lua")
end
}
)
end
end
-- vim binds ------------------------------------------------------------------
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.' })
map('t', '<esc>', '<C-\\><C-n>', { desc = 'make <esc> work in terminals.' })
-- 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', '<cmd>!chmod +x %<CR>') -- execute order 111
-- add some keybinds to the file view (netrw)
a.nvim_create_autocmd('FileType', {
pattern = 'netrw',
callback = function()
local bind = function(lhs, rhs)
vim.keymap.set('n', lhs, rhs, { remap = true, buffer = true })
end
bind('h', '-^') -- Go up a directory
bind('l', '<CR>') -- Go down a directory / open a file
bind('.', 'gh') -- Toggle dotfiles
bind('P', '<C-w>z') -- Close preview window
bind('<esc>', '<cmd>q<CR>') -- Close netrw
end
})
-- tabs
map('n', '<C-q>n', '<cmd>tabnew<CR>')
map('n', '<C-q>w', '<cmd>tabclose<CR>')
map('n', '<C-q>h', '<cmd>tabprev<CR>')
map('n', '<C-q>l', '<cmd>tabnext<CR>')
-- plugin binds ---------------------------------------------------------------
-- pretty lsp view
map('n', 'gd', '<CMD>Glance definitions<CR>')
map('n', 'gr', '<CMD>Glance references<CR>')
map('n', 'gy', '<CMD>Glance type_definitions<CR>')
map('n', 'gi', '<CMD>Glance implementations<CR>')
if pcall(require, "treesj") then
local treesj = require('treesj') -- treesj
map('n', '<leader>j', treesj.toggle)
end
if pcall(require, "telescope") then
local telebuilt = require('telescope.builtin') -- telescope
map('n', '<leader>sf', telebuilt.find_files, { desc = 'Find files.' })
map('n', '<leader>sg', telebuilt.git_files, { desc = 'Find git files.' })
map('n', '<leader>sp', function()
telebuilt.grep_string({ search = vim.fn.input(
'Find string in project > '
) })
end, { desc = 'Find string in project.' })
map('n', '<leader>so', telebuilt.oldfiles, { desc = 'Find old files.' })
end
map('n', '<leader>u', '<cmd>UndotreeToggle<CR>', { desc = 'Open undo tree.' })
map('n', '<leader>f', '<cmd>SFMToggle<CR>', { desc = 'Open file tree view.' })
map('n', '<leader>b', '<cmd>JABSOpen<CR>', { desc = 'Switch between buffers.' })
map('n', '<leader>tt', '<cmd>TroubleToggle<CR>', { desc = 'Diagnostic list.' })
map('n', '<leader>tc', '<cmd>TodoTrouble<CR>', { desc = 'Comment list.' })
map('n', '<C-e>', '<cmd>IconPickerYank<CR>', { desc = 'Icon picker list.' })
if pcall(require, "dapui") then
local dapui = require('dapui') -- dap ui
map('n', '<leader>d', dapui.toggle, { desc = 'Debuging ui.' })
end
if pcall(require, "smart-splits") then
local smartsplits = require('smart-splits') -- resizing buffers (toggleable)
map('n', '<leader>r', smartsplits.start_resize_mode)
end
-- toggle term (don't use leader key in these binds)
map({'n', 't'}, '<C-\\>', '<cmd>ToggleTerm direction=float<CR>')
map({'n', 't'}, '<C-g>', '<cmd>lua _glow()<CR>')
-- true zen
if pcall(require, "true-zen") then
map('n', '<leader>zf', require("true-zen.focus").toggle, {
desc = 'fullscreen',
})
map('n', '<leader>zm', require("true-zen.minimalist").toggle, {
desc = 'minimal',
})
map('n', '<leader>za', require("true-zen.ataraxis").toggle, {
desc = 'zen',
})
end
-- Git
map('n', '<leader>gph', '<cmd>Gitsigns preview_hunk_inline<CR>')
map('n', '<leader>gsh', '<cmd>Gitsigns stage_hunk<CR>')
map('n', '<leader>gb', '<cmd>Gitsigns blame_line<CR>')
-- neogen
if pcall(require, "neogen") then
map('n', '<leader>df', require("neogen").generate, {
desc = 'Generate anootations',
})
end
|