2024-08-06 03:03:57 +02:00
|
|
|
-- [[ Autocommands ]]
|
|
|
|
-- See `:help autocmd`
|
|
|
|
-- See `:help lua-guide-autocommands`
|
2024-08-04 03:28:42 +02:00
|
|
|
|
2024-08-06 03:04:33 +02:00
|
|
|
-- These should be self-explanatory
|
|
|
|
vim.api.nvim_create_user_command('Cd', 'cd %:h', { desc = 'Change directory to the current file' })
|
2024-08-06 03:39:50 +02:00
|
|
|
vim.api.nvim_create_user_command('Py', '!python %', { desc = 'Execute python file' })
|
2024-11-07 15:05:15 +01:00
|
|
|
vim.api.nvim_create_user_command('Trim', 'lua MiniTrailspace.trim()', { desc = 'Trim trailing whitespace' })
|
2024-08-06 03:04:33 +02:00
|
|
|
|
2024-08-04 03:28:42 +02:00
|
|
|
-- Instantly move help window to the right
|
|
|
|
-- This is almost certainly a hacky way to do this)
|
|
|
|
vim.api.nvim_create_autocmd('FileType', {
|
|
|
|
pattern = { 'help' },
|
2024-08-04 09:33:12 +02:00
|
|
|
command = 'wincmd L',
|
2024-08-04 03:28:42 +02:00
|
|
|
})
|
2024-08-06 03:03:57 +02:00
|
|
|
|
|
|
|
-- Highlight when yanking (copying) text
|
|
|
|
-- Try it with `yap` in normal mode
|
|
|
|
-- See `:help vim.highlight.on_yank()`
|
|
|
|
vim.api.nvim_create_autocmd('TextYankPost', {
|
|
|
|
desc = 'Highlight when yanking (copying) text',
|
|
|
|
group = vim.api.nvim_create_augroup('kickstart-highlight-yank', { clear = true }),
|
|
|
|
callback = function()
|
|
|
|
vim.highlight.on_yank()
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
2024-11-10 23:53:36 +01:00
|
|
|
vim.api.nvim_create_user_command('CDToGitRoot', function()
|
|
|
|
local handle = io.popen 'git rev-parse --show-toplevel 2>/dev/null'
|
|
|
|
local git_root = handle:read('*a'):gsub('\n', '')
|
|
|
|
handle:close()
|
|
|
|
|
|
|
|
if git_root == '' then
|
|
|
|
print 'Not in a Git repository'
|
|
|
|
else
|
|
|
|
vim.cmd('cd ' .. git_root)
|
|
|
|
print('Changed directory to Git root: ' .. git_root)
|
|
|
|
end
|
|
|
|
end, { desc = 'Change directory to the current Git repository root' })
|
|
|
|
|
2024-08-06 03:03:57 +02:00
|
|
|
-- vim: ts=2 sts=2 sw=2 et
|