mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-07-24 04:34:42 +02:00
[Refactor] remove lv prefix (#1112)
* Rename lv-utils into utils * Move commands defined in utils into core/commands.lua
This commit is contained in:
parent
623994af2a
commit
12c0a7441e
10 changed files with 62 additions and 50 deletions
|
@ -116,7 +116,7 @@ In case you want to see all the settings inside LunarVim, run the following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /tmp
|
cd /tmp
|
||||||
lvim --headless +'lua require("lv-utils").generate_settings()' +qa && sort -o lv-settings.lua{,}
|
lvim --headless +'lua require("utils").generate_settings()' +qa && sort -o lv-settings.lua{,}
|
||||||
```
|
```
|
||||||
and then inspect `/tmp/lv-settings.lua` file
|
and then inspect `/tmp/lv-settings.lua` file
|
||||||
|
|
||||||
|
|
5
init.lua
5
init.lua
|
@ -28,8 +28,11 @@ plugin_loader:load { plugins, lvim.plugins }
|
||||||
vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
|
vim.g.colors_name = lvim.colorscheme -- Colorscheme must get called after plugins are loaded or it will break new installs.
|
||||||
vim.cmd("colorscheme " .. lvim.colorscheme)
|
vim.cmd("colorscheme " .. lvim.colorscheme)
|
||||||
|
|
||||||
local utils = require "lv-utils"
|
local utils = require "utils"
|
||||||
utils.toggle_autoformat()
|
utils.toggle_autoformat()
|
||||||
|
local commands = require "core.commands"
|
||||||
|
commands.load(commands.defaults)
|
||||||
|
|
||||||
require("lsp").setup_handlers()
|
require("lsp").setup_handlers()
|
||||||
|
|
||||||
local null_status_ok, null_ls = pcall(require, "null-ls")
|
local null_status_ok, null_ls = pcall(require, "null-ls")
|
||||||
|
|
|
@ -27,7 +27,7 @@ lvim.autocommands = {
|
||||||
"*",
|
"*",
|
||||||
"setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
|
"setlocal formatoptions-=c formatoptions-=r formatoptions-=o",
|
||||||
},
|
},
|
||||||
{ "BufWritePost", "lv-config.lua", "lua require('lv-utils').reload_lv_config()" },
|
{ "BufWritePost", "lv-config.lua", "lua require('utils').reload_lv_config()" },
|
||||||
{
|
{
|
||||||
"FileType",
|
"FileType",
|
||||||
"qf",
|
"qf",
|
||||||
|
|
21
lua/core/commands.lua
Normal file
21
lua/core/commands.lua
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
M.defaults = {
|
||||||
|
[[
|
||||||
|
function! QuickFixToggle()
|
||||||
|
if empty(filter(getwininfo(), 'v:val.quickfix'))
|
||||||
|
copen
|
||||||
|
else
|
||||||
|
cclose
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
]],
|
||||||
|
}
|
||||||
|
|
||||||
|
M.load = function(commands)
|
||||||
|
for _, command in ipairs(commands) do
|
||||||
|
vim.cmd(command)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
|
@ -95,7 +95,7 @@ M.config = function()
|
||||||
name = "Packer",
|
name = "Packer",
|
||||||
c = { "<cmd>PackerCompile<cr>", "Compile" },
|
c = { "<cmd>PackerCompile<cr>", "Compile" },
|
||||||
i = { "<cmd>PackerInstall<cr>", "Install" },
|
i = { "<cmd>PackerInstall<cr>", "Install" },
|
||||||
r = { "<cmd>lua require('lv-utils').reload_lv_config()<cr>", "Reload" },
|
r = { "<cmd>lua require('utils').reload_lv_config()<cr>", "Reload" },
|
||||||
s = { "<cmd>PackerSync<cr>", "Sync" },
|
s = { "<cmd>PackerSync<cr>", "Sync" },
|
||||||
u = { "<cmd>PackerUpdate<cr>", "Update" },
|
u = { "<cmd>PackerUpdate<cr>", "Update" },
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local lv_utils = require "lv-utils"
|
local utils = require "utils"
|
||||||
|
|
||||||
local opts = {
|
local opts = {
|
||||||
nnoremap = { noremap = true, silent = true },
|
nnoremap = { noremap = true, silent = true },
|
||||||
|
@ -103,11 +103,11 @@ local function get_user_keys(mode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
lv_utils.add_keymap_normal_mode(opts.nnoremap, get_user_keys "normal_mode")
|
utils.add_keymap_normal_mode(opts.nnoremap, get_user_keys "normal_mode")
|
||||||
lv_utils.add_keymap_insert_mode(opts.inoremap, get_user_keys "insert_mode")
|
utils.add_keymap_insert_mode(opts.inoremap, get_user_keys "insert_mode")
|
||||||
lv_utils.add_keymap_visual_mode(opts.vnoremap, get_user_keys "visual_mode")
|
utils.add_keymap_visual_mode(opts.vnoremap, get_user_keys "visual_mode")
|
||||||
lv_utils.add_keymap_visual_block_mode(opts.xnoremap, get_user_keys "visual_block_mode")
|
utils.add_keymap_visual_block_mode(opts.xnoremap, get_user_keys "visual_block_mode")
|
||||||
lv_utils.add_keymap_term_mode(opts.generic, get_user_keys "term_mode")
|
utils.add_keymap_term_mode(opts.generic, get_user_keys "term_mode")
|
||||||
|
|
||||||
-- navigate tab completion with <c-j> and <c-k>
|
-- navigate tab completion with <c-j> and <c-k>
|
||||||
-- runs conditionally
|
-- runs conditionally
|
||||||
|
|
|
@ -301,7 +301,7 @@ end
|
||||||
function lsp_config.setup(lang)
|
function lsp_config.setup(lang)
|
||||||
local lang_server = lvim.lang[lang].lsp
|
local lang_server = lvim.lang[lang].lsp
|
||||||
local provider = lang_server.provider
|
local provider = lang_server.provider
|
||||||
if require("lv-utils").check_lsp_client_active(provider) then
|
if require("utils").check_lsp_client_active(provider) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
local lv_utils = {}
|
local utils = {}
|
||||||
|
|
||||||
-- recursive Print (structure, limit, separator)
|
-- recursive Print (structure, limit, separator)
|
||||||
local function r_inspect_settings(structure, limit, separator)
|
local function r_inspect_settings(structure, limit, separator)
|
||||||
|
@ -42,7 +42,7 @@ local function r_inspect_settings(structure, limit, separator)
|
||||||
return limit - 1
|
return limit - 1
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.generate_settings()
|
function utils.generate_settings()
|
||||||
-- Opens a file in append mode
|
-- Opens a file in append mode
|
||||||
local file = io.open("lv-settings.lua", "w")
|
local file = io.open("lv-settings.lua", "w")
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ function lv_utils.generate_settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- autoformat
|
-- autoformat
|
||||||
local toggle_autoformat = function()
|
function utils.toggle_autoformat()
|
||||||
if lvim.format_on_save then
|
if lvim.format_on_save then
|
||||||
require("core.autocmds").define_augroups {
|
require("core.autocmds").define_augroups {
|
||||||
autoformat = {
|
autoformat = {
|
||||||
|
@ -71,30 +71,28 @@ local toggle_autoformat = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
if not lvim.format_on_save then
|
if not lvim.format_on_save then
|
||||||
vim.cmd [[if exists('#autoformat#BufWritePre')
|
vim.cmd [[
|
||||||
:autocmd! autoformat
|
if exists('#autoformat#BufWritePre')
|
||||||
endif]]
|
:autocmd! autoformat
|
||||||
|
endif
|
||||||
|
]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.toggle_autoformat()
|
function utils.reload_lv_config()
|
||||||
toggle_autoformat()
|
|
||||||
end
|
|
||||||
|
|
||||||
function lv_utils.reload_lv_config()
|
|
||||||
vim.cmd "source ~/.local/share/lunarvim/lvim/lua/settings.lua"
|
vim.cmd "source ~/.local/share/lunarvim/lvim/lua/settings.lua"
|
||||||
vim.cmd "source ~/.config/lvim/lv-config.lua"
|
vim.cmd "source ~/.config/lvim/lv-config.lua"
|
||||||
vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua"
|
vim.cmd "source ~/.local/share/lunarvim/lvim/lua/plugins.lua"
|
||||||
local plugins = require "plugins"
|
local plugins = require "plugins"
|
||||||
local plugin_loader = require("plugin-loader").init()
|
local plugin_loader = require("plugin-loader").init()
|
||||||
toggle_autoformat()
|
utils.toggle_autoformat()
|
||||||
plugin_loader:load { plugins, lvim.plugins }
|
plugin_loader:load { plugins, lvim.plugins }
|
||||||
vim.cmd ":PackerCompile"
|
vim.cmd ":PackerCompile"
|
||||||
vim.cmd ":PackerInstall"
|
vim.cmd ":PackerInstall"
|
||||||
-- vim.cmd ":PackerClean"
|
-- vim.cmd ":PackerClean"
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.check_lsp_client_active(name)
|
function utils.check_lsp_client_active(name)
|
||||||
local clients = vim.lsp.get_active_clients()
|
local clients = vim.lsp.get_active_clients()
|
||||||
for _, client in pairs(clients) do
|
for _, client in pairs(clients) do
|
||||||
if client.name == name then
|
if client.name == name then
|
||||||
|
@ -104,38 +102,38 @@ function lv_utils.check_lsp_client_active(name)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap(mode, opts, keymaps)
|
function utils.add_keymap(mode, opts, keymaps)
|
||||||
for _, keymap in ipairs(keymaps) do
|
for _, keymap in ipairs(keymaps) do
|
||||||
vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts)
|
vim.api.nvim_set_keymap(mode, keymap[1], keymap[2], opts)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap_normal_mode(opts, keymaps)
|
function utils.add_keymap_normal_mode(opts, keymaps)
|
||||||
lv_utils.add_keymap("n", opts, keymaps)
|
utils.add_keymap("n", opts, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap_visual_mode(opts, keymaps)
|
function utils.add_keymap_visual_mode(opts, keymaps)
|
||||||
lv_utils.add_keymap("v", opts, keymaps)
|
utils.add_keymap("v", opts, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap_visual_block_mode(opts, keymaps)
|
function utils.add_keymap_visual_block_mode(opts, keymaps)
|
||||||
lv_utils.add_keymap("x", opts, keymaps)
|
utils.add_keymap("x", opts, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap_insert_mode(opts, keymaps)
|
function utils.add_keymap_insert_mode(opts, keymaps)
|
||||||
lv_utils.add_keymap("i", opts, keymaps)
|
utils.add_keymap("i", opts, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.add_keymap_term_mode(opts, keymaps)
|
function utils.add_keymap_term_mode(opts, keymaps)
|
||||||
lv_utils.add_keymap("t", opts, keymaps)
|
utils.add_keymap("t", opts, keymaps)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.unrequire(m)
|
function utils.unrequire(m)
|
||||||
package.loaded[m] = nil
|
package.loaded[m] = nil
|
||||||
_G[m] = nil
|
_G[m] = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function lv_utils.gsub_args(args)
|
function utils.gsub_args(args)
|
||||||
if args == nil or type(args) ~= "table" then
|
if args == nil or type(args) ~= "table" then
|
||||||
return args
|
return args
|
||||||
end
|
end
|
||||||
|
@ -146,16 +144,6 @@ function lv_utils.gsub_args(args)
|
||||||
return args
|
return args
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.cmd [[
|
return utils
|
||||||
function! QuickFixToggle()
|
|
||||||
if empty(filter(getwininfo(), 'v:val.quickfix'))
|
|
||||||
copen
|
|
||||||
else
|
|
||||||
cclose
|
|
||||||
endif
|
|
||||||
endfunction
|
|
||||||
]]
|
|
||||||
|
|
||||||
return lv_utils
|
|
||||||
|
|
||||||
-- TODO: find a new home for these autocommands
|
-- TODO: find a new home for these autocommands
|
|
@ -18,7 +18,7 @@ lvim.leader = "space"
|
||||||
-- {'<S-Tab>', ':bprevious<CR>'},
|
-- {'<S-Tab>', ':bprevious<CR>'},
|
||||||
-- }
|
-- }
|
||||||
-- if you just want to augment the existing ones then use the utility function
|
-- if you just want to augment the existing ones then use the utility function
|
||||||
-- require("lv-utils").add_keymap_insert_mode({ silent = true }, {
|
-- require("utils").add_keymap_insert_mode({ silent = true }, {
|
||||||
-- { "<C-s>", ":w<cr>" },
|
-- { "<C-s>", ":w<cr>" },
|
||||||
-- { "<C-c>", "<ESC>" },
|
-- { "<C-c>", "<ESC>" },
|
||||||
-- })
|
-- })
|
||||||
|
|
|
@ -26,7 +26,7 @@ lvim.leader = "space"
|
||||||
-- {'<S-Tab>', ':bprevious<CR>'},
|
-- {'<S-Tab>', ':bprevious<CR>'},
|
||||||
-- }
|
-- }
|
||||||
-- if you just want to augment the existing ones then use the utility function
|
-- if you just want to augment the existing ones then use the utility function
|
||||||
-- require("lv-utils").add_keymap_insert_mode({ silent = true }, {
|
-- require("utils").add_keymap_insert_mode({ silent = true }, {
|
||||||
-- { "<C-s>", ":w<cr>" },
|
-- { "<C-s>", ":w<cr>" },
|
||||||
-- { "<C-c>", "<ESC>" },
|
-- { "<C-c>", "<ESC>" },
|
||||||
-- })
|
-- })
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue