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
136
137
138
139
140
141
142
143
144
145
146
147
148
|
local function map(mode, bind, cmd, opts)
opts = opts or {noremap = true, 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
-- greatest remap ever
map('x', '<leader>p', [["_dP]])
-- clear search
map('n', '<ESC>', ':nohlsearch<Bar>:echo<CR>')
-- move selected text up/down
map('v', '<S-k>', ":m '<-2<CR>gv=gv")
map('v', '<S-j>', ":m '>+1<CR>gv=gv")
-- the cursor STAYS IN THE MIDDLE
map('n', '<S-j>', 'mzJ`z<cmd>delm z<CR>') -- when combining lines
map('n', 'n', 'nzzzv') -- searching
map('n', 'N', 'Nzzzv')
map('n', '<C-d>', '<C-d>zz') -- half page jumping
map('n', '<C-u>', '<C-u>zz')
-- execute order 111
map('n', '<leader>x', '<cmd>!chmod +x %<CR>')
-- tabs
--[[ map('n', '<C-i>', '<cmd>tabnew<CR>')
map('n', '<C-o>', '<cmd>tabclose<CR>')
map('n', '<C-u>', '<cmd>tabprevious<CR>')
map('n', '<C-p>', '<cmd>tabnext<CR>')
map('n', '<leader>tL', '<cmd>tabmove +1<CR>')
map('n', '<leader>tH', '<cmd>tabmove -1<CR>') ]]
-- add some keybinds to the file view
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
})
-- custom menu for simpler neovim managment -----------------------------------
local function configmenu()
local list = {}
local function add(name, plug)
if not plug then
table.insert(list, name)
return
end
if package.loaded[plug] then
table.insert(list, name)
end
end
add('edit config')
add('update plugins', 'dep')
vim.ui.select(list, { prompt = 'Config Menu' },
function(choice)
if choice == 'edit config' then
vim.cmd'e $XDG_CONFIG_HOME/nvim/init.lua'
end
if choice == 'update plugins' then
require('dep').sync()
if package.loaded['nvim-treesitter'] then
vim.cmd'TSUpdate'
end
if package.loaded['mason'] then
require('mason.api.command').MasonUpdate()
end
end
end)
end
map('n', '<C-m>', configmenu)
-- plugin binds ---------------------------------------------------------------
-- treesj
local treesj = require('treesj')
map('n', '<leader>j', treesj.toggle)
-- telescope
local telebuilt = require('telescope.builtin')
map('n', '<leader>sf', telebuilt.find_files)
map('n', '<leader>sg', telebuilt.git_files)
map('n', '<leader>sp', function()
telebuilt.grep_string({ search = vim.fn.input('Find string in project > ') });
end)
map('n', '<leader>so', telebuilt.oldfiles)
-- intellitab
local intellitab = require('intellitab')
map('n', '<Tab>', intellitab.indent)
-- undo tree
map('n', '<leader>u', '<cmd>UndotreeToggle<CR>')
-- sfm
map('n', '<leader>f', '<cmd>SFMToggle<CR>')
-- dap ui
local dapui = require('dapui')
map('n', '<leader>d', dapui.toggle)
-- switch between previous buffers
map('n', '<leader>b', '<cmd>JABSOpen<CR>')
-- resizing buffers (toggleable)
local smartsplits = require('smart-splits')
map('n', '<leader>r', smartsplits.start_resize_mode)
-- trouble (lsp error view)
map('n', '<leader>t', '<cmd>TroubleToggle<CR>')
-- icon picker
map('n', '<C-e>', '<cmd>IconPickerYank<CR>')
-- toggle term
map('t', '<ESC>', '<C-\\><C-n>') -- make <ESC> work in terminals
map({'n', 't'}, '<C-\\>', '<cmd>ToggleTerm size=20<CR>')
map({'n', 't'}, '<leader>gl', '<cmd>lua _glow()<CR>')
|