new config old version is now on v1 branch
This commit is contained in:
148
lua/core/binds.lua
Normal file
148
lua/core/binds.lua
Normal file
@ -0,0 +1,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>')
|
Reference in New Issue
Block a user