WIP, cant get which key to register at startup setup function, calling in open nvwim works. Also + purple text is weird
This commit is contained in:
parent
5fcc77255c
commit
713d128018
5 changed files with 33 additions and 27 deletions
53
lua/autocommands.lua
Normal file
53
lua/autocommands.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
function is_available(plugin)
|
||||
local lazy_config_avail, lazy_config = pcall(require, "lazy.core.config")
|
||||
return lazy_config_avail and lazy_config.plugins[plugin] ~= nil
|
||||
end
|
||||
|
||||
local augroup = vim.api.nvim_create_augroup
|
||||
local autocmd = vim.api.nvim_create_autocmd
|
||||
local cmd = vim.api.nvim_create_user_command
|
||||
local namespace = vim.api.nvim_create_namespace
|
||||
|
||||
if is_available "alpha-nvim" then
|
||||
local group_name = augroup("alpha_settings", { clear = true })
|
||||
autocmd({ "User", "BufEnter" }, {
|
||||
desc = "Disable status and tablines for alpha",
|
||||
group = group_name,
|
||||
callback = function(event)
|
||||
if
|
||||
(
|
||||
(event.event == "User" and event.file == "AlphaReady")
|
||||
or (event.event == "BufEnter" and vim.api.nvim_get_option_value("filetype", { buf = event.buf }) == "alpha")
|
||||
) and not vim.g.before_alpha
|
||||
then
|
||||
vim.g.before_alpha = { showtabline = vim.opt.showtabline:get(), laststatus = vim.opt.laststatus:get() }
|
||||
vim.opt.showtabline, vim.opt.laststatus = 0, 0
|
||||
elseif
|
||||
vim.g.before_alpha
|
||||
and event.event == "BufEnter"
|
||||
and vim.api.nvim_get_option_value("buftype", { buf = event.buf }) ~= "nofile"
|
||||
then
|
||||
vim.opt.laststatus, vim.opt.showtabline = vim.g.before_alpha.laststatus, vim.g.before_alpha.showtabline
|
||||
vim.g.before_alpha = nil
|
||||
end
|
||||
end,
|
||||
})
|
||||
autocmd("VimEnter", {
|
||||
desc = "Start Alpha when vim is opened with no arguments",
|
||||
group = group_name,
|
||||
callback = function()
|
||||
local should_skip = false
|
||||
if vim.fn.argc() > 0 or vim.fn.line2byte(vim.fn.line "$") ~= -1 or not vim.o.modifiable then
|
||||
should_skip = true
|
||||
else
|
||||
for _, arg in pairs(vim.v.argv) do
|
||||
if arg == "-b" or arg == "-c" or vim.startswith(arg, "+") or arg == "-S" then
|
||||
should_skip = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not should_skip then require("alpha").start(true, require("alpha").default_config) end
|
||||
end,
|
||||
})
|
||||
end
|
175
lua/keymaps.lua
Normal file
175
lua/keymaps.lua
Normal file
|
@ -0,0 +1,175 @@
|
|||
-- Shorten function name
|
||||
local keymap = vim.keymap.set
|
||||
-- Silent keymap option
|
||||
local opts = { silent = true }
|
||||
|
||||
--Remap space as leader key
|
||||
keymap("", "<Space>", "<Nop>", opts)
|
||||
vim.g.mapleader = " "
|
||||
|
||||
-- Modes
|
||||
-- normal_mode = "n",
|
||||
-- insert_mode = "i",
|
||||
-- visual_mode = "v",
|
||||
-- visual_block_mode = "x",
|
||||
-- term_mode = "t",
|
||||
-- command_mode = "c",
|
||||
|
||||
local scratch = function(extension)
|
||||
os.execute "mkdir -p ~/dev/scratches/"
|
||||
local date = os.date "%Y-%m-%dT%H:%M:%S"
|
||||
local filepath = "~/dev/scratches/scratch_" .. date .. extension
|
||||
vim.cmd("execute 'edit " .. filepath .. "'")
|
||||
end
|
||||
|
||||
local mappings = {
|
||||
n = {
|
||||
["<leader>w"] = { "<cmd>w<cr>", desc = "Save" },
|
||||
["<leader>q"] = { "<cmd>confirm q<cr>", desc = "Quit" },
|
||||
["|"] = { "<cmd>vsplit<cr>", desc = "Vertical Split" },
|
||||
["\\"] = { "<cmd>split<cr>", desc = "Horizontal Split" },
|
||||
["<C-d>"] = { "<C-d>zz", desc = "Vertical half page down and center cursor" },
|
||||
["<C-u>"] = { "<C-u>zz", desc = "Vertical half page up and center cursor" },
|
||||
["y"] = { '"*y', desc = "Copy to system clipboard" },
|
||||
["p"] = { '"*p', desc = "Paste from system clipboard" },
|
||||
-- TODO L-c to close buffer
|
||||
|
||||
["<leader>fs"] = {
|
||||
function()
|
||||
require("telescope.builtin").live_grep {
|
||||
search_dirs = { "~/dev/scratches/" },
|
||||
}
|
||||
end,
|
||||
desc = "Find words in scratches",
|
||||
},
|
||||
["<leader>s"] = { name = " Scratch File" },
|
||||
["<leader>ss"] = { function() scratch ".txt" end, desc = "New text scratch file" },
|
||||
["<leader>sn"] = { function() scratch ".json" end, desc = "New json scratch file" },
|
||||
["<leader>sq"] = { function() scratch ".sql" end, desc = "New sql scratch file" },
|
||||
["<leader>st"] = { function() scratch ".ts" end, desc = "New ts scratch file" },
|
||||
["<leader>sb"] = { function() scratch ".sh" end, desc = "New shell scratch file" },
|
||||
["<leader>sj"] = { function() scratch ".js" end, desc = "New js scratch file" },
|
||||
|
||||
|
||||
["<leader>Q"] = { ":qa<CR>", desc = "Quit all" },
|
||||
["<leader>,"] = { name = " Misc Tools" },
|
||||
["<leader>,c"] = { name = " Casing" },
|
||||
["<leader>,cs"] = { ":Snek<CR>", desc = "To Snek Case" },
|
||||
["<leader>,cc"] = { ":Camel<CR>", desc = "To Camel Case" },
|
||||
["<leader>,cp"] = { ":CamelB<CR>", desc = "To Pascal Case" },
|
||||
["<leader>,ck"] = { ":Kebab<CR>", desc = "To Kebab Case" },
|
||||
["<leader>,ce"] = { ":Screm<CR>", desc = "To Screm Case" },
|
||||
["<leader>,j"] = { name = " Jest Tests" },
|
||||
["<leader>,jr"] = { function() require("jester").run() end, desc = "Run test under cursor" },
|
||||
["<leader>,jf"] = { function() require("jester").run_file() end, desc = "Run tests for file" },
|
||||
["<leader>,jl"] = { function() require("jester").run_last() end, desc = "Run last ran test" },
|
||||
["<leader>lz"] = { ":LspRestart<CR>", desc = "Restart LSP Server" },
|
||||
},
|
||||
v = {
|
||||
["<leader>gf"] = { ":OpenInGHFile <CR>", desc = "Open in github" },
|
||||
["y"] = { '"*y', desc = "Copy to system clipboard" },
|
||||
["p"] = { '"*p', desc = "Paste from system clipboard" },
|
||||
["∆"] = {
|
||||
cmd = ":m '>+1<CR>gv=gv",
|
||||
desc = "Move the selected text up",
|
||||
},
|
||||
["˚"] = {
|
||||
cmd = ":m '<-2<CR>gv=gv",
|
||||
desc = "Move the selected text down",
|
||||
},
|
||||
["<leader>,"] = { name = " Misc Tools" },
|
||||
["<leader>,c"] = { name = " Casing" },
|
||||
["<leader>,cs"] = { ":Snek<CR>", desc = "To Snek Case" },
|
||||
["<leader>,cc"] = { ":Camel<CR>", desc = "To Camel Case" },
|
||||
["<leader>,cp"] = { ":CamelB<CR>", desc = "To Pascal Case" },
|
||||
["<leader>,ck"] = { ":Kebab<CR>", desc = "To Kebab Case" },
|
||||
["<leader>,ce"] = { ":Screm<CR>", desc = "To Screm Case" },
|
||||
},
|
||||
x = {
|
||||
["∆"] = {
|
||||
cmd = ":m '>+1<CR>gv=gv",
|
||||
desc = "Move the selected text up",
|
||||
},
|
||||
["˚"] = {
|
||||
desc = "Move the selected text down",
|
||||
cmd = ":m '<-2<CR>gv=gv",
|
||||
},
|
||||
},
|
||||
i = {
|
||||
["<C-k>"] = { "<Up>", desc = "Up" },
|
||||
["<C-j>"] = { "<Down>", desc = "Down" },
|
||||
["<C-h>"] = { "<Left>", desc = "Left" },
|
||||
["<C-l>"] = { "<Right>", desc = "Right" },
|
||||
},
|
||||
c = {
|
||||
["<C-h>"] = { "<Left>", desc = "Left" },
|
||||
["<C-j>"] = { "<Down>", desc = "Down" },
|
||||
["<C-k>"] = { "<Up>", desc = "Up" },
|
||||
["<C-l>"] = { "<Right>", desc = "Right" },
|
||||
},
|
||||
}
|
||||
|
||||
for _, file in ipairs(vim.fn.readdir(vim.fn.stdpath('config')..'/lua/user', [[v:val =~ '\.lua$']])) do
|
||||
local uplugin = require('user.'..file:gsub('%.lua$', ''))
|
||||
-- if (uplugin[1] ~= nil) then
|
||||
if (uplugin.mappings ~= nil) then
|
||||
for mode, keymaps in pairs(uplugin.mappings) do
|
||||
-- Add new mode if not already existing
|
||||
if (mappings[mode] == nil) then
|
||||
mappings[mode] = {}
|
||||
end
|
||||
|
||||
for key, value in pairs(keymaps) do
|
||||
mappings[mode][key] = value;
|
||||
end
|
||||
end
|
||||
end
|
||||
-- end
|
||||
end
|
||||
|
||||
local M = {}
|
||||
local which_key_queue = nil
|
||||
function M.which_key_register()
|
||||
if which_key_queue then
|
||||
local wk_avail, wk = pcall(require, "which-key")
|
||||
if wk_avail then
|
||||
for mode, registration in pairs(which_key_queue) do
|
||||
wk.register(registration, { mode = mode })
|
||||
end
|
||||
which_key_queue = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function set_mappings(map_table, base)
|
||||
-- iterate over the first keys for each mode
|
||||
base = base or {}
|
||||
for mode, maps in pairs(map_table) do
|
||||
-- iterate over each keybinding set in the current mode
|
||||
for keymap, options in pairs(maps) do
|
||||
-- build the options for the command accordingly
|
||||
if options then
|
||||
local cmd = options
|
||||
local keymap_opts = base
|
||||
if type(options) == "table" then
|
||||
cmd = options[1]
|
||||
keymap_opts = vim.tbl_deep_extend("force", keymap_opts, options)
|
||||
keymap_opts[1] = nil
|
||||
end
|
||||
if not cmd or keymap_opts.name then -- if which-key mapping, queue it
|
||||
if not which_key_queue then which_key_queue = {} end
|
||||
if not which_key_queue[mode] then which_key_queue[mode] = {} end
|
||||
which_key_queue[mode][keymap] = keymap_opts
|
||||
else -- if not which-key mapping, set it
|
||||
vim.keymap.set(mode, keymap, cmd, keymap_opts)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if package.loaded["which-key"] then M.which_key_register() end -- if which-key is loaded already, register
|
||||
end
|
||||
|
||||
set_mappings(mappings);
|
||||
|
||||
return M
|
||||
|
20
lua/options.lua
Normal file
20
lua/options.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
-- allow use of system keyboard
|
||||
vim.opt.clipboard = "unnamedplus"
|
||||
-- allow use of mouse
|
||||
vim.opt.mouse = 'a'
|
||||
-- line numbering, relative
|
||||
vim.opt.number = true
|
||||
vim.wo.number = true
|
||||
vim.wo.relativenumber = true
|
||||
-- Highlights the results of previous search, which is annoying when we are done searching
|
||||
vim.opt.hlsearch = false
|
||||
-- Wrap lines in files
|
||||
vim.opt.wrap = true
|
||||
-- preseve indentation of virtual wrapped lines
|
||||
vim.opt.breakindent = true
|
||||
-- set tab length
|
||||
vim.opt.tabstop = 2;
|
||||
vim.opt.shiftwidth = 2;
|
||||
-- split to the right or below always
|
||||
vim.opt.splitbelow = true
|
||||
vim.opt.splitright = true
|
|
@ -123,5 +123,9 @@ return {
|
|||
ensure_installed = { "codelldb" },
|
||||
},
|
||||
},
|
||||
|
||||
mappings = {
|
||||
n = {
|
||||
["<leader>l"] = { desc = " LSP" },
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,9 @@ return {
|
|||
-- your configuration comes here
|
||||
-- or leave it empty to use the default settings
|
||||
-- refer to the configuration section below
|
||||
}
|
||||
},
|
||||
setup = function(_, opts)
|
||||
require("which-key").setup(opts)
|
||||
require("keymaps").which_key_register()
|
||||
end
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue