generated from 2KAbhishek/bare-minimum
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
functions.lua
55 lines (46 loc) · 1.78 KB
/
functions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
-- Reload neovim config
vim.api.nvim_create_user_command('ReloadConfig', function()
for name, _ in pairs(package.loaded) do
if name:match('^plugins') then
package.loaded[name] = nil
end
end
dofile(vim.env.MYVIMRC)
vim.notify('Nvim configuration reloaded!', vim.log.levels.INFO)
end, {})
local function copy_to_clipboard(content, message)
vim.fn.setreg('+', content)
vim.notify('Copied "' .. content .. '" to the clipboard!', vim.log.levels.INFO)
end
vim.api.nvim_create_user_command('CopyRelativePath', function()
local path = vim.fn.expand('%')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyAbsolutePath', function()
local path = vim.fn.expand('%:p')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyRelativePathWithLine', function()
local path = vim.fn.expand('%')
local line = vim.fn.line('.')
local result = path .. ':' .. line
copy_to_clipboard(result, 'Copied "' .. result .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyAbsolutePathWithLine', function()
local path = vim.fn.expand('%:p')
local line = vim.fn.line('.')
local result = path .. ':' .. line
copy_to_clipboard(result, 'Copied "' .. result .. '" to the clipboard!')
end, {})
vim.api.nvim_create_user_command('CopyFileName', function()
local path = vim.fn.expand('%:t')
copy_to_clipboard(path, 'Copied "' .. path .. '" to the clipboard!')
end, {})
-- Switch to git root or file parent dir
vim.api.nvim_create_user_command('RootDir', function()
local root = require('lib.util').get_root_dir()
if root == '' then
return
end
vim.cmd('lcd ' .. root)
end, {})