feat(nvim): added some user commands and global functions for utility
This commit is contained in:
@@ -3,10 +3,11 @@ vim.loader.enable()
|
||||
vim.g.mapleader = ' '
|
||||
vim.g.maplocalleader = ' '
|
||||
|
||||
require('custom.globals')
|
||||
require('custom.config.options')
|
||||
vim.schedule(function()
|
||||
require('custom.config.keymaps')
|
||||
require('custom.config.autocmds')
|
||||
require('custom.config.commands')
|
||||
end)
|
||||
|
||||
local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
vim.api.nvim_create_autocmd('TextYankPost', {
|
||||
desc = 'Highlight when yanking text',
|
||||
group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('BufEnter', {
|
||||
desc = 'Disable newlines on commented lines from continuing the comment',
|
||||
group = vim.api.nvim_create_augroup('disable-comments-continuation', { clear = true }),
|
||||
callback = function()
|
||||
-- vim.opt_local.formatoptions:remove('r') -- no comments on enter
|
||||
vim.opt_local.formatoptions:remove('o') -- no comments on `o` or `O`
|
||||
end,
|
||||
})
|
||||
50
.config/nvim/lua/custom/config/commands.lua
Normal file
50
.config/nvim/lua/custom/config/commands.lua
Normal file
@@ -0,0 +1,50 @@
|
||||
vim.api.nvim_create_autocmd('TextYankPost', {
|
||||
desc = 'Highlight when yanking text',
|
||||
group = vim.api.nvim_create_augroup('highlight-yank', { clear = true }),
|
||||
callback = function()
|
||||
vim.highlight.on_yank()
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('BufEnter', {
|
||||
desc = 'Disable newlines on commented lines from continuing the comment',
|
||||
group = vim.api.nvim_create_augroup('disable-comments-continuation', { clear = true }),
|
||||
callback = function()
|
||||
-- vim.opt_local.formatoptions:remove('r') -- no comments on enter
|
||||
vim.opt_local.formatoptions:remove('o') -- no comments on `o` or `O`
|
||||
end,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_user_command('Format', function(args)
|
||||
local range = nil
|
||||
if args.count ~= -1 then
|
||||
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
|
||||
range = {
|
||||
start = { args.line1, 0 },
|
||||
['end'] = { args.line2, end_line:len() },
|
||||
}
|
||||
end
|
||||
require('conform').format({ async = true, lsp_format = 'fallback', range = range })
|
||||
end, { range = true })
|
||||
|
||||
vim.api.nvim_create_user_command('FormatToggle', function(args)
|
||||
local is_global = not args.bang
|
||||
if is_global then
|
||||
vim.g.disable_autoformat = not vim.g.disable_autoformat
|
||||
if vim.g.disable_autoformat then
|
||||
Notify('Autoformat-on-save disabled globally', 'info')
|
||||
else
|
||||
Notify('Autoformat-on-save enabled globally', 'info')
|
||||
end
|
||||
else
|
||||
vim.b.disable_autoformat = not vim.b.disable_autoformat
|
||||
if vim.b.disable_autoformat then
|
||||
Notify('Autoformat-on-save disabled for this buffer', 'info')
|
||||
else
|
||||
Notify('Autoformat-on-save enabled for this buffer', 'info')
|
||||
end
|
||||
end
|
||||
end, {
|
||||
desc = 'Toggle autoformat-on-save',
|
||||
bang = true,
|
||||
})
|
||||
25
.config/nvim/lua/custom/globals.lua
Normal file
25
.config/nvim/lua/custom/globals.lua
Normal file
@@ -0,0 +1,25 @@
|
||||
function Notify(title, message, level)
|
||||
local notify = require('notify')
|
||||
notify(message, level, { title = title })
|
||||
end
|
||||
|
||||
function ToggleWrap()
|
||||
if vim.wo.wrap then
|
||||
vim.wo.wrap = false
|
||||
Notify('Wrap disabled', 'info')
|
||||
else
|
||||
vim.wo.wrap = true
|
||||
vim.wo.number = false
|
||||
Notify('Wrap enabled', 'info')
|
||||
end
|
||||
end
|
||||
|
||||
function ToggleInlayHints()
|
||||
local is_enabled = vim.lsp.inlay_hint.is_enabled({})
|
||||
vim.lsp.inlay_hint.enable(not is_enabled)
|
||||
if is_enabled then
|
||||
Notify('Inlay Hints disabled', 'info')
|
||||
else
|
||||
Notify('Inlay Hints enabled', 'info')
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user