pre zsh-switch backup
This commit is contained in:
@@ -18,7 +18,6 @@ vim.opt.rtp:prepend(lazypath)
|
||||
require('BluePlum.set')
|
||||
require('BluePlum.keymap')
|
||||
require('BluePlum.neovide')
|
||||
require('BluePlum.utility')
|
||||
|
||||
require('lazy').setup({
|
||||
-- Plugins
|
||||
@@ -30,3 +29,4 @@ require('lazy').setup({
|
||||
})
|
||||
|
||||
require('lsp')
|
||||
require('BluePlum.input')
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"markview.nvim": { "branch": "main", "commit": "67b69cdaf9055bebac3682a070d7e5c8eecba29c" },
|
||||
"mason-lspconfig.nvim": { "branch": "main", "commit": "25c11854aa25558ee6c03432edfa0df0217324be" },
|
||||
"mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" },
|
||||
"neoscroll.nvim": { "branch": "master", "commit": "81c47f9d111c00d13111b65bfd13cc81b7b347a1" },
|
||||
"nvim-cmp": { "branch": "main", "commit": "ae644feb7b67bf1ce4260c231d1d4300b19c6f30" },
|
||||
"nvim-colorizer.lua": { "branch": "master", "commit": "a065833f35a3a7cc3ef137ac88b5381da2ba302e" },
|
||||
"nvim-lspconfig": { "branch": "master", "commit": "ff69ecca55d83ffc70657f260a799f79a5637831" },
|
||||
@@ -26,6 +27,7 @@
|
||||
"plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" },
|
||||
"promise-async": { "branch": "main", "commit": "119e8961014c9bfaf1487bf3c2a393d254f337e2" },
|
||||
"rustaceanvim": { "branch": "master", "commit": "d1f56672638508a7bc971cde31a29df4018579a9" },
|
||||
"smear-cursor.nvim": { "branch": "main", "commit": "78c42170f9326fb70d09aff2184c81189eddf144" },
|
||||
"telescope.nvim": { "branch": "master", "commit": "df534c3042572fb958586facd02841e10186707c" },
|
||||
"todo-comments.nvim": { "branch": "main", "commit": "ae0a2afb47cf7395dc400e5dc4e05274bf4fb9e0" }
|
||||
}
|
||||
|
||||
248
.config/nvim/lua/BluePlum/input.lua
Normal file
248
.config/nvim/lua/BluePlum/input.lua
Normal file
@@ -0,0 +1,248 @@
|
||||
local M = {
|
||||
interupt = false,
|
||||
}
|
||||
|
||||
M.Keys = {
|
||||
enter = '<CR>',
|
||||
tab = '<Tab>',
|
||||
backspace = '<BS>',
|
||||
escape = '<Esc>',
|
||||
|
||||
-- if await_key().is_arrow
|
||||
-- if key == Keys.left
|
||||
left = { is_arrow = true, this = '<Left>' },
|
||||
right = { is_arrow = true, this = '<Right>' },
|
||||
up = { is_arrow = true, this = '<Up>' },
|
||||
down = { is_arrow = true, this = '<Down>' },
|
||||
}
|
||||
|
||||
function M.await_key()
|
||||
-- local char = vim.fn.getchar()
|
||||
local char = vim.fn.getchar()
|
||||
local num = vim.fn.nr2char(char)
|
||||
local key = vim.fn.keytrans(num)
|
||||
-- vim.print(char, num, key, key == '<BS>')
|
||||
|
||||
-- Some special keys work weird..
|
||||
local is_key = function(key)
|
||||
return pcall(function(char)
|
||||
if vim.fn.keytrans(char) ~= key then
|
||||
error()
|
||||
end
|
||||
end, char)
|
||||
end
|
||||
|
||||
if is_key('<BS>') then
|
||||
return M.Keys.backspace
|
||||
elseif is_key('<Left>') then
|
||||
return M.Keys.left
|
||||
elseif is_key('<Right>') then
|
||||
return M.Keys.right
|
||||
elseif is_key('<Up>') then
|
||||
return M.Keys.up
|
||||
elseif is_key('<Down>') then
|
||||
return M.Keys.down
|
||||
elseif key == '<Space>' then
|
||||
return ' '
|
||||
elseif key == '<Lt>' then
|
||||
return '<'
|
||||
elseif key == '<Gt>' then
|
||||
return '>'
|
||||
end
|
||||
|
||||
return key
|
||||
end
|
||||
|
||||
-- vim.print(vim.fn.getcompletion('ech', 'command'))
|
||||
-- vim.fn.getchar()
|
||||
|
||||
local function refresh_completions(pattern, kind)
|
||||
local completions = vim.fn.getcompletion(pattern, kind)
|
||||
|
||||
if #completions > 25 then
|
||||
local new = {}
|
||||
for i = 1, 25 do
|
||||
new[i] = completions[i]
|
||||
end
|
||||
new[#new + 1] = '...' -- Append truncation indicator
|
||||
return new
|
||||
end
|
||||
|
||||
return completions
|
||||
end
|
||||
|
||||
local function format_completions(completions)
|
||||
local formatted = { { '{', 'Normal' } }
|
||||
for i = 1, #completions do
|
||||
table.insert(formatted, { completions[i], i == 1 and 'CursorLineNr' or 'Normal' })
|
||||
if i ~= #completions then
|
||||
table.insert(formatted, { ', ', 'Normal' })
|
||||
end
|
||||
end
|
||||
table.insert(formatted, { '}', 'Normal' })
|
||||
return formatted
|
||||
end
|
||||
|
||||
local function input(prompt, default, completion)
|
||||
vim.validate({
|
||||
prompt = { prompt, 'table' },
|
||||
default = { default, { 'string', 'nil' } },
|
||||
completion = { completion, { 'string', 'nil' } },
|
||||
})
|
||||
local using_default = default ~= nil
|
||||
local typed = default or ''
|
||||
|
||||
local completions = {}
|
||||
|
||||
local cursor = 0
|
||||
|
||||
while true do
|
||||
if completion ~= nil then
|
||||
completions = refresh_completions(typed, completion)
|
||||
end
|
||||
|
||||
vim.cmd('echo | redraw')
|
||||
vim.api.nvim_echo({
|
||||
unpack(prompt),
|
||||
{ string.sub(typed, 0, cursor), using_default and 'Visual' or 'Normal' },
|
||||
cursor == #typed and { '█', 'CursorLineNr' } or { string.sub(typed, cursor + 1, cursor + 1), 'Search' },
|
||||
{ string.sub(typed, cursor + 2), 'Normal' },
|
||||
unpack(#completions > 0 and format_completions(completions) or {}),
|
||||
}, false, {})
|
||||
local input = M.await_key()
|
||||
|
||||
if input == M.Keys.enter or input == M.Keys.escape then
|
||||
vim.cmd('echo | redraw')
|
||||
return input == M.Keys.enter, typed
|
||||
elseif input == M.Keys.backspace then
|
||||
if cursor <= 0 then
|
||||
goto continue
|
||||
end
|
||||
typed = string.sub(typed, 0, cursor - 1) .. string.sub(typed, cursor + 1)
|
||||
cursor = cursor - 1
|
||||
goto continue
|
||||
elseif input.is_arrow then
|
||||
if input == M.Keys.left then
|
||||
if cursor > 0 then
|
||||
cursor = cursor - 1
|
||||
end
|
||||
elseif input == M.Keys.right then
|
||||
if cursor < #typed then
|
||||
cursor = cursor + 1
|
||||
end
|
||||
end
|
||||
-- vim.api.nvim_win_set_cursor(0, { 1, 10 })
|
||||
goto continue
|
||||
elseif input == M.Keys.tab then
|
||||
if #completions == 0 then
|
||||
goto continue
|
||||
end
|
||||
cursor = #typed
|
||||
|
||||
local insert = completions[1]
|
||||
local offset = #typed
|
||||
|
||||
-- Find the largest overlapping slice
|
||||
while offset > 0 and not vim.startswith(insert, string.sub(typed, -offset)) do
|
||||
offset = offset - 1
|
||||
end
|
||||
|
||||
-- Replace `typed` with the completion
|
||||
typed = string.sub(typed, 1, #typed - offset) .. insert .. ' '
|
||||
cursor = #typed
|
||||
goto continue
|
||||
end
|
||||
|
||||
typed = string.sub(typed, 0, cursor) .. input .. string.sub(typed, cursor + 1)
|
||||
cursor = cursor + 1
|
||||
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
-- Safe wrapper for hiding the cursor (also captures <C-c>)
|
||||
function M.input(prompt, default, completion)
|
||||
local hl = vim.api.nvim_get_hl(0, { name = 'Cursor' })
|
||||
|
||||
hl.blend = 100
|
||||
vim.api.nvim_set_hl(0, 'Cursor', hl)
|
||||
|
||||
-- local result, success, typed = pcall(input, prompt, defaut, completion)
|
||||
local success, typed = input(prompt, default, completion)
|
||||
vim.cmd('echo | redraw')
|
||||
|
||||
hl.blend = 0
|
||||
vim.api.nvim_set_hl(0, 'Cursor', hl)
|
||||
|
||||
return success, typed, not result
|
||||
end
|
||||
|
||||
---@param opts? table
|
||||
---@param on_confirm function
|
||||
vim.ui.input = function(opts, on_confirm)
|
||||
vim.validate({
|
||||
opts = { opts, 'table' },
|
||||
on_confirm = { on_confirm, 'function' },
|
||||
})
|
||||
|
||||
opts = opts or {}
|
||||
on_confirm = on_confirm or function() end
|
||||
|
||||
vim.validate({
|
||||
-- Also supports list of HlGroup tuples
|
||||
prompt = { opts.prompt, { 'table', 'string', 'nil' } },
|
||||
|
||||
default = { opts.default, { 'string', 'nil' } },
|
||||
completion = { opts.completion, { 'string', 'nil' } },
|
||||
|
||||
highlight = {
|
||||
opts.highlight,
|
||||
function(it)
|
||||
return it == nil
|
||||
end,
|
||||
'nil (not supported)',
|
||||
},
|
||||
})
|
||||
|
||||
local prompt = opts.prompt or { { 'Enter input > ', 'Question' } }
|
||||
if type(prompt) == 'string' then
|
||||
-- Strip invalid characters
|
||||
prompt = vim.trim(prompt)
|
||||
|
||||
local is_alpha = function(char)
|
||||
local num = vim.fn.char2nr(char)
|
||||
return (num >= 65 and num <= 90) or (num >= 97 and num <= 122)
|
||||
end
|
||||
|
||||
local last = string.sub(prompt, #prompt)
|
||||
while not is_alpha(last) do
|
||||
prompt = string.sub(prompt, 0, #prompt - 1)
|
||||
prompt = vim.trim(prompt)
|
||||
last = string.sub(prompt, #prompt)
|
||||
end
|
||||
|
||||
prompt = { { prompt .. ' > ', 'Question' } }
|
||||
end
|
||||
|
||||
local finished, typed, interrupted = M.input(prompt, opts.default, opts.completion)
|
||||
if interrupted then
|
||||
return
|
||||
end
|
||||
on_confirm(finished and typed or nil)
|
||||
end
|
||||
|
||||
-- vim.ui.input({ completion = 'cmdline' }, function(a)
|
||||
-- vim.print(a)
|
||||
-- end)
|
||||
|
||||
-- vim.keymap.set('n', ';', function()
|
||||
-- vim.ui.input({ prompt = { { ':', 'Normal' } }, completion = 'cmdline' }, function(command)
|
||||
-- vim.print(command)
|
||||
-- if command then
|
||||
-- vim.cmd(command)
|
||||
-- end
|
||||
-- end)
|
||||
-- end)
|
||||
-- add cmdheight to the input function
|
||||
|
||||
return M
|
||||
@@ -35,9 +35,10 @@ vim.keymap.set(
|
||||
|
||||
-- Help
|
||||
vim.cmd.cnoreabbrev('h vert h')
|
||||
vim.keymap.set('n', '<leader>h', ':h <C-r><C-w><CR>')
|
||||
|
||||
-- Windows
|
||||
vim.keymap.set('n', '<leader>k', function()
|
||||
vim.keymap.set('n', '<leader>q', function()
|
||||
if vim.bo.modified then
|
||||
if Confirm('Buffer has unsaved changes; write?') then
|
||||
vim.cmd.write()
|
||||
@@ -51,13 +52,7 @@ vim.keymap.set('n', '<leader>k', function()
|
||||
end)
|
||||
|
||||
-- Comp mode
|
||||
vim.keymap.set('n', '<leader>s', function() -- s: start
|
||||
local command = Input('Enter compilation command > ', vim.g.last_compile_command)
|
||||
if command then
|
||||
vim.g.last_compile_command = command
|
||||
vim.cmd.Compile(command)
|
||||
end
|
||||
end)
|
||||
vim.keymap.set('n', '<leader>c<CR>', ':Compile<CR>')
|
||||
vim.keymap.set('n', '<leader>cs', ':CompileInterrupt<CR>')
|
||||
|
||||
vim.keymap.set('n', '<leader>E', ':NextError<CR>')
|
||||
vim.keymap.set('n', '<leader>S', ':Recompile<CR>')
|
||||
|
||||
@@ -38,3 +38,7 @@ vim.api.nvim_create_autocmd('FileType', {
|
||||
pattern = 'help',
|
||||
command = 'setlocal linebreak',
|
||||
})
|
||||
|
||||
-- Search
|
||||
vim.opt.hlsearch = false
|
||||
vim.opt.incsearch = true
|
||||
|
||||
@@ -1,53 +1,69 @@
|
||||
function Ask(msg)
|
||||
vim.cmd.echohl('Question')
|
||||
vim.cmd.echo('"' .. msg .. '"')
|
||||
vim.cmd.echohl()
|
||||
end
|
||||
local M = {}
|
||||
|
||||
function Confirm(msg)
|
||||
Ask(msg .. ' [Y/n] ')
|
||||
return M
|
||||
|
||||
local answer = vim.fn.getchar()
|
||||
return answer ~= 110 and answer ~= 27 and answer ~= 37 -- 'n', <ESC>, <SPACE>
|
||||
end
|
||||
|
||||
function Input(prompt, last)
|
||||
local buffer = ''
|
||||
while true do
|
||||
vim.cmd('redraw | echo')
|
||||
vim.api.nvim_echo({
|
||||
{ prompt, 'Question' },
|
||||
last and { last, 'Visual' } or { buffer, 'Normal' },
|
||||
}, false, {})
|
||||
|
||||
local character = vim.fn.getchar()
|
||||
if pcall(function(char)
|
||||
if vim.fn.keytrans(char) ~= '<BS>' then
|
||||
error()
|
||||
end
|
||||
end, character) then
|
||||
last = nil
|
||||
buffer = vim.fn.slice(buffer, 0, -1)
|
||||
elseif character == 27 then
|
||||
vim.cmd('redraw | echo')
|
||||
return nil
|
||||
elseif character == 13 then
|
||||
return last or buffer
|
||||
elseif
|
||||
(character == 32 or pcall(function(char)
|
||||
if vim.fn.keytrans(char) ~= '<Right>' then
|
||||
error()
|
||||
end
|
||||
end, character)) and last
|
||||
then
|
||||
buffer = last
|
||||
if character == 32 then
|
||||
buffer = buffer .. ' '
|
||||
end
|
||||
last = nil
|
||||
else
|
||||
last = nil
|
||||
buffer = buffer .. vim.fn.nr2char(character)
|
||||
end
|
||||
end
|
||||
end
|
||||
-- function Ask(msg)
|
||||
-- vim.cmd.echohl('Question')
|
||||
-- vim.cmd.echo('"' .. msg .. '"')
|
||||
-- vim.cmd.echohl()
|
||||
-- end
|
||||
--
|
||||
-- function Confirm(msg)
|
||||
-- Ask(msg .. ' [Y/n] ')
|
||||
--
|
||||
-- local answer = vim.fn.getchar()
|
||||
-- return answer ~= 110 and answer ~= 27 and answer ~= 37 -- 'n', <ESC>, <SPACE>
|
||||
-- end
|
||||
--
|
||||
-- function Input(prompt, last)
|
||||
-- local buffer = ''
|
||||
-- while true do
|
||||
-- vim.cmd('redraw | echo')
|
||||
-- vim.api.nvim_echo({
|
||||
-- { prompt, 'Question' },
|
||||
-- last and { last, 'Visual' } or { buffer, 'Normal' },
|
||||
-- }, false, {})
|
||||
--
|
||||
-- local character = vim.fn.getchar()
|
||||
-- if pcall(function(char)
|
||||
-- if vim.fn.keytrans(char) ~= '<BS>' then
|
||||
-- error()
|
||||
-- end
|
||||
-- end, character) then
|
||||
-- last = nil
|
||||
-- buffer = vim.fn.slice(buffer, 0, -1)
|
||||
-- elseif character == 27 then
|
||||
-- vim.cmd('redraw | echo')
|
||||
-- return nil
|
||||
-- elseif character == 13 then
|
||||
-- return last or buffer
|
||||
-- elseif
|
||||
-- (character == 32 or pcall(function(char)
|
||||
-- if vim.fn.keytrans(char) ~= '<Right>' then
|
||||
-- error()
|
||||
-- end
|
||||
-- end, character)) and last
|
||||
-- then
|
||||
-- buffer = last
|
||||
-- if character == 32 then
|
||||
-- buffer = buffer .. ' '
|
||||
-- end
|
||||
-- last = nil
|
||||
-- else
|
||||
-- last = nil
|
||||
-- buffer = buffer .. vim.fn.nr2char(character)
|
||||
-- end
|
||||
-- end
|
||||
-- end
|
||||
--
|
||||
-- vim.ui.input = function(opts, after)
|
||||
-- local prompt = (opts.prompt or 'Enter input') .. ' > '
|
||||
-- if prompt == 'Compile command: ' then
|
||||
-- prompt = 'Enter command'
|
||||
-- end
|
||||
-- local last = opts.default or ''
|
||||
--
|
||||
-- return (after or function(x)
|
||||
-- print('Unhandled data: ' .. x)
|
||||
-- end)(Input(prompt, last))
|
||||
-- end
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
vim = vim
|
||||
|
||||
local required = { 'mason', 'mason-lspconfig', 'lspconfig', 'lsp-zero', 'cmp' }
|
||||
local ready = true
|
||||
|
||||
@@ -24,8 +22,21 @@ vim.cmd.echohl('None')
|
||||
local zero = require('lsp-zero')
|
||||
|
||||
zero.preset('recommended')
|
||||
|
||||
require('mason').setup({})
|
||||
|
||||
local settings = {
|
||||
['lua_ls'] = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = 'LuaJIT',
|
||||
},
|
||||
workspace = {
|
||||
library = { vim.env.VIMRUNTIME },
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
require('mason-lspconfig').setup({
|
||||
ensure_installed = {
|
||||
'lua_ls',
|
||||
@@ -34,6 +45,7 @@ require('mason-lspconfig').setup({
|
||||
-- zero.default_setup,
|
||||
function(name)
|
||||
require('lspconfig')[name].setup({
|
||||
settings = settings[name] or {},
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(),
|
||||
})
|
||||
end,
|
||||
|
||||
@@ -6,9 +6,7 @@ return {
|
||||
':IncRename ',
|
||||
} },
|
||||
config = function()
|
||||
require('inc_rename').setup({
|
||||
input_buffer_type = 'dressing',
|
||||
})
|
||||
require('inc_rename').setup({})
|
||||
end,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -18,4 +18,10 @@ return {
|
||||
vim.api.nvim_set_hl(0, 'MarkviewLayer', { fg = '#2a2a2a', bg = '#373737' })
|
||||
end,
|
||||
},
|
||||
{
|
||||
'sphamba/smear-cursor.nvim',
|
||||
opts = {
|
||||
time_interval = 10,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -16,8 +16,31 @@ return {
|
||||
vim.api.nvim_set_hl(0, 'CompileModeMessageCol', { link = 'CursorLineNr' })
|
||||
|
||||
vim.g.compile_mode = {
|
||||
baleria_setup = true,
|
||||
baleia_setup = true,
|
||||
}
|
||||
end,
|
||||
},
|
||||
-- {
|
||||
-- dir = '~/dev/s-ido',
|
||||
-- name = 's-ido',
|
||||
-- lazy = false,
|
||||
-- dev = true,
|
||||
-- opts = {},
|
||||
-- keys = {
|
||||
-- {
|
||||
-- '<Tab>',
|
||||
-- function()
|
||||
-- require('s-ido.commandline').complete()
|
||||
-- end,
|
||||
-- mode = 'c',
|
||||
-- },
|
||||
-- },
|
||||
-- },
|
||||
-- {
|
||||
-- dir = '~/dev/s-nav',
|
||||
-- name = 's-nav',
|
||||
-- lazy = false,
|
||||
-- dev = true,
|
||||
-- opts = {},
|
||||
-- },
|
||||
}
|
||||
Reference in New Issue
Block a user