Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
d21cd45701 |
@ -1,2 +0,0 @@
|
|||||||
local opts = { buffer = true, remap = false, silent = true }
|
|
||||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
|
@ -1,6 +1,2 @@
|
|||||||
vim.opt.commentstring = '//%s'
|
vim.opt.commentstring = '//%s'
|
||||||
vim.opt.matchpairs:append('<:>')
|
vim.opt.matchpairs:append('<:>')
|
||||||
|
|
||||||
local opts = { buffer = true, remap = false, silent = true }
|
|
||||||
-- vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
|
|
||||||
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)
|
|
||||||
|
@ -1,2 +0,0 @@
|
|||||||
-- Use treesitter for Python indenting since regex indenting is broken
|
|
||||||
vim.opt.indentexpr = 'nvim_treesitter#indent()'
|
|
@ -31,16 +31,8 @@ local kanagawa = {
|
|||||||
|
|
||||||
vim.cmd.highlight('WinSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
|
vim.cmd.highlight('WinSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
|
||||||
vim.cmd.highlight('MsgSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
|
vim.cmd.highlight('MsgSeparator', 'guifg=' .. dragon.ui.bg_m3, 'guibg=' .. dragon.ui.bg_m3)
|
||||||
vim.cmd.highlight('TreesitterContext', 'guibg=' .. dragon.ui.bg_gutter)
|
vim.cmd.highligh('TreesitterContext', 'guibg=' .. dragon.ui.bg_gutter)
|
||||||
|
vim.cmd.highlight('link zshTodo Comment')
|
||||||
-- Don't lighlight TODO specially in comments
|
|
||||||
for _, todo_group in pairs({
|
|
||||||
'confTodo',
|
|
||||||
'ps1CommentTodo',
|
|
||||||
'zshTodo',
|
|
||||||
}) do
|
|
||||||
vim.cmd.highlight('link ' .. todo_group .. ' Comment')
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
10
lua/plugins/comment.lua
Normal file
10
lua/plugins/comment.lua
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
return {
|
||||||
|
-- TODO: v0.10.0 Added built-in |commenting| support.
|
||||||
|
'terrortylor/nvim-comment',
|
||||||
|
config = function()
|
||||||
|
require('nvim_comment').setup({
|
||||||
|
-- should comment out empty or whitespace only lines
|
||||||
|
comment_empty = false,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
}
|
@ -26,22 +26,13 @@ if vim.fn.executable('pip') == 1 then
|
|||||||
local ensure_install_from_pip = {
|
local ensure_install_from_pip = {
|
||||||
'cmake', -- CMake
|
'cmake', -- CMake
|
||||||
'esbonio', -- Sphinx
|
'esbonio', -- Sphinx
|
||||||
'ruff', -- Python
|
'ruff_lsp', -- Python
|
||||||
}
|
}
|
||||||
for _, package in ipairs(ensure_install_from_pip) do
|
for _, package in ipairs(ensure_install_from_pip) do
|
||||||
table.insert(ensure_installed, package)
|
table.insert(ensure_installed, package)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if vim.fn.executable('go') then
|
|
||||||
local ensure_installed_from_go = {
|
|
||||||
'gopls', -- Go
|
|
||||||
}
|
|
||||||
for _, package in ipairs(ensure_installed_from_go) do
|
|
||||||
table.insert(ensure_installed, package)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if vim.fn.has('win32') == 1 then
|
if vim.fn.has('win32') == 1 then
|
||||||
table.insert(ensure_installed, 'powershell_es')
|
table.insert(ensure_installed, 'powershell_es')
|
||||||
end
|
end
|
||||||
@ -59,11 +50,11 @@ return {
|
|||||||
'saadparwaiz1/cmp_luasnip', -- Source for LuaSnip snippets
|
'saadparwaiz1/cmp_luasnip', -- Source for LuaSnip snippets
|
||||||
'hrsh7th/cmp-buffer', -- Source for buffer words
|
'hrsh7th/cmp-buffer', -- Source for buffer words
|
||||||
'hrsh7th/cmp-path', -- Source for filesystem paths
|
'hrsh7th/cmp-path', -- Source for filesystem paths
|
||||||
'petertriho/cmp-git', -- Source for Git/GitHub/GitLab
|
'kbenzie/cmp-git', -- Source for Git/GitHub/GitLab
|
||||||
'hrsh7th/nvim-cmp', -- Completion engine combines and uses the above
|
'hrsh7th/nvim-cmp', -- Completion engine combines and uses the above
|
||||||
|
|
||||||
-- Lua vim module support in lua language server
|
-- Lua vim module support in lua language server
|
||||||
{ 'folke/lazydev.nvim', ft = 'lua', opts = {} },
|
'folke/neodev.nvim',
|
||||||
-- Expose clangd extensions
|
-- Expose clangd extensions
|
||||||
'p00f/clangd_extensions.nvim',
|
'p00f/clangd_extensions.nvim',
|
||||||
|
|
||||||
@ -81,48 +72,57 @@ return {
|
|||||||
},
|
},
|
||||||
|
|
||||||
config = function()
|
config = function()
|
||||||
local lspconfig_default_opts = {
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
-- Broadcast full client capabilities to language servers
|
capabilities = vim.tbl_deep_extend(
|
||||||
capabilities = vim.tbl_deep_extend(
|
'force', capabilities, require('cmp_nvim_lsp').default_capabilities())
|
||||||
'force', vim.lsp.protocol.make_client_capabilities(),
|
|
||||||
require('cmp_nvim_lsp').default_capabilities()),
|
|
||||||
}
|
|
||||||
|
|
||||||
local lspconfig_custom_opts = {
|
|
||||||
clangd = {
|
|
||||||
cmd = { 'clangd', '--completion-style=detailed' },
|
|
||||||
},
|
|
||||||
|
|
||||||
lua_ls = {
|
|
||||||
settings = {
|
|
||||||
Lua = {
|
|
||||||
diagnostics = {
|
|
||||||
disable = { 'missing-fields', },
|
|
||||||
globals = { 'vim', },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
pyright = {
|
|
||||||
settings = {
|
|
||||||
pyright = {
|
|
||||||
disableOrganizeImports = true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
require('mason').setup()
|
require('mason').setup()
|
||||||
require('mason-lspconfig').setup({
|
require('mason-lspconfig').setup({
|
||||||
automatic_installation = false,
|
automatic_installation = false,
|
||||||
ensure_installed = ensure_installed,
|
ensure_installed = ensure_installed,
|
||||||
|
|
||||||
handlers = {
|
handlers = {
|
||||||
|
-- Default handler, sets up everything unless a custom language server
|
||||||
|
-- setup handler is defined below
|
||||||
function(server_name)
|
function(server_name)
|
||||||
local opts = vim.tbl_deep_extend("force",
|
require('lspconfig')[server_name].setup({
|
||||||
lspconfig_default_opts, lspconfig_custom_opts[server_name] or {})
|
capabilities = capabilities,
|
||||||
require('lspconfig')[server_name].setup(opts)
|
})
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
['clangd'] = function()
|
||||||
|
require('lspconfig').clangd.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
cmd = { 'clangd', '--completion-style=detailed' }
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
|
||||||
|
['lua_ls'] = function()
|
||||||
|
require('neodev').setup()
|
||||||
|
require('lspconfig').lua_ls.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
settings = {
|
||||||
|
Lua = {
|
||||||
|
diagnostics = {
|
||||||
|
disable = { 'missing-fields', },
|
||||||
|
globals = { 'vim', },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
|
||||||
|
['pyright'] = function()
|
||||||
|
require('lspconfig').pyright.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
settings = {
|
||||||
|
pyright = {
|
||||||
|
disableOrganizeImports = true, -- Use ruff import sorter instead
|
||||||
|
},
|
||||||
|
}
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -147,8 +147,8 @@ return {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
sources = {
|
sources = {
|
||||||
{ name = 'luasnip' },
|
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
{ name = 'buffer' },
|
{ name = 'buffer' },
|
||||||
{ name = 'path' },
|
{ name = 'path' },
|
||||||
{ name = 'git' },
|
{ name = 'git' },
|
||||||
@ -172,8 +172,6 @@ return {
|
|||||||
completion = cmp.config.window.bordered(),
|
completion = cmp.config.window.bordered(),
|
||||||
documentation = cmp.config.window.bordered(),
|
documentation = cmp.config.window.bordered(),
|
||||||
},
|
},
|
||||||
|
|
||||||
preselect = 'none', -- Don't preselect completions suggested by source
|
|
||||||
})
|
})
|
||||||
require("cmp_git").setup({})
|
require("cmp_git").setup({})
|
||||||
|
|
||||||
@ -182,12 +180,11 @@ return {
|
|||||||
vim.api.nvim_create_autocmd('LspAttach', {
|
vim.api.nvim_create_autocmd('LspAttach', {
|
||||||
pattern = '*',
|
pattern = '*',
|
||||||
group = augroup,
|
group = augroup,
|
||||||
callback = function(event)
|
callback = function(ev)
|
||||||
local opts = { noremap = true, buffer = event.buf }
|
local opts = { noremap = true, buffer = ev.buf }
|
||||||
|
|
||||||
-- Fixit mapping, or close enough, actually any code action
|
-- Fixit mapping, or close enough, actually any code action
|
||||||
vim.keymap.set('n', '<leader>fi',
|
vim.keymap.set('n', '<leader>fi', require('actions-preview').code_actions, opts)
|
||||||
require('actions-preview').code_actions, opts)
|
|
||||||
|
|
||||||
-- Goto mappings
|
-- Goto mappings
|
||||||
local tb = require('telescope.builtin')
|
local tb = require('telescope.builtin')
|
||||||
@ -198,7 +195,7 @@ return {
|
|||||||
vim.keymap.set('n', 'gr', tb.lsp_references, opts)
|
vim.keymap.set('n', 'gr', tb.lsp_references, opts)
|
||||||
vim.keymap.set('n', '<leader>ic', tb.lsp_incoming_calls, opts)
|
vim.keymap.set('n', '<leader>ic', tb.lsp_incoming_calls, opts)
|
||||||
vim.keymap.set('n', '<leader>oc', tb.lsp_outgoing_calls, opts)
|
vim.keymap.set('n', '<leader>oc', tb.lsp_outgoing_calls, opts)
|
||||||
vim.keymap.set('n', '<leader>sd', tb.lsp_document_symbols, opts)
|
vim.keymap.set('n', '<leader>ss', tb.lsp_document_symbols, opts)
|
||||||
vim.keymap.set('n', '<leader>sw', tb.lsp_workspace_symbols, opts)
|
vim.keymap.set('n', '<leader>sw', tb.lsp_workspace_symbols, opts)
|
||||||
|
|
||||||
-- Refactoring mappings
|
-- Refactoring mappings
|
||||||
@ -215,8 +212,7 @@ return {
|
|||||||
|
|
||||||
-- Swtich file using clangd extension
|
-- Swtich file using clangd extension
|
||||||
-- TODO: limit this to only filetypes supported by clangd
|
-- TODO: limit this to only filetypes supported by clangd
|
||||||
vim.keymap.set('n', '<leader>sf',
|
vim.keymap.set('n', '<leader>sf', ':ClangdSwitchSourceHeader<CR>', { silent = true })
|
||||||
':ClangdSwitchSourceHeader<CR>', { silent = true })
|
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,64 +0,0 @@
|
|||||||
return {
|
|
||||||
'numToStr/Navigator.nvim',
|
|
||||||
config = function()
|
|
||||||
local navigator = require('Navigator')
|
|
||||||
navigator.setup({
|
|
||||||
disable_on_zoom = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
local augroup = vim.api.nvim_create_augroup('mux', { clear = true })
|
|
||||||
if vim.env.TMUX ~= nil then
|
|
||||||
-- Integrate tmux navigation flag
|
|
||||||
local navigation_flag =
|
|
||||||
'@vim' .. vim.fn.substitute(vim.env.TMUX_PANE, '%', '\\%', 'g')
|
|
||||||
local function set_navigation_flag()
|
|
||||||
vim.fn.system('tmux set-window-option ' .. navigation_flag .. ' 1')
|
|
||||||
end
|
|
||||||
local function unset_navigation_flag()
|
|
||||||
-- FIXME: Due to a regression this causes SIGABRT when RelWithDebInfo
|
|
||||||
-- vim.fn.system('tmux set-window-option -u ' .. navigation_flag)
|
|
||||||
-- https://github.com/neovim/neovim/issues/21856 contains a workaround
|
|
||||||
vim.fn.jobstart(
|
|
||||||
'tmux set-window-option -u ' .. navigation_flag, { detach = true })
|
|
||||||
end
|
|
||||||
|
|
||||||
-- [Un]set tmux window option to detect when to change pane.
|
|
||||||
set_navigation_flag()
|
|
||||||
vim.api.nvim_create_autocmd('FocusGained', {
|
|
||||||
pattern = '*', group = augroup, callback = set_navigation_flag,
|
|
||||||
})
|
|
||||||
vim.api.nvim_create_autocmd('VimLeave', {
|
|
||||||
pattern = '*', group = augroup, callback = unset_navigation_flag,
|
|
||||||
})
|
|
||||||
elseif vim.env.TERM_PROGRAM ~= nil and vim.env.TERM_PROGRAM == 'WezTerm' then
|
|
||||||
local function set_wezterm_user_var(in_vim)
|
|
||||||
local value = in_vim and '1' or '0'
|
|
||||||
local template = "\x1b]1337;SetUserVar=%s=%s\a"
|
|
||||||
local command = template:format('vim', vim.base64.encode(tostring(value)))
|
|
||||||
vim.api.nvim_chan_send(vim.v.stderr, command)
|
|
||||||
end
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'VimEnter', 'VimResume' }, {
|
|
||||||
pattern = '*',
|
|
||||||
group = augroup,
|
|
||||||
callback = function()
|
|
||||||
set_wezterm_user_var(true)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd({ 'VimLeave', 'VimSuspend' }, {
|
|
||||||
pattern = '*',
|
|
||||||
group = augroup,
|
|
||||||
callback = function()
|
|
||||||
set_wezterm_user_var(false)
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Map nativation bindings
|
|
||||||
vim.keymap.set('n', "<C-h>", navigator.left)
|
|
||||||
vim.keymap.set('n', "<C-j>", navigator.down)
|
|
||||||
vim.keymap.set('n', "<C-k>", navigator.up)
|
|
||||||
vim.keymap.set('n', "<C-l>", navigator.right)
|
|
||||||
end
|
|
||||||
}
|
|
@ -22,15 +22,5 @@ return {
|
|||||||
luasnip.jump(-1)
|
luasnip.jump(-1)
|
||||||
end
|
end
|
||||||
end, { silent = true })
|
end, { silent = true })
|
||||||
-- vim.keymap.set('s', '<M-l>', function()
|
|
||||||
-- if luasnip.choice_active() then
|
|
||||||
-- luasnip.change_choice(1)
|
|
||||||
-- end
|
|
||||||
-- end, { silent = true })
|
|
||||||
-- vim.keymap.set('s', '<M-h>', function()
|
|
||||||
-- if luasnip.choice_active() then
|
|
||||||
-- luasnip.change_choice(-1)
|
|
||||||
-- end
|
|
||||||
-- end, { silent = true })
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
return {
|
|
||||||
'Kicamon/markdown-table-mode.nvim',
|
|
||||||
config = function()
|
|
||||||
require('markdown-table-mode').setup()
|
|
||||||
end
|
|
||||||
}
|
|
@ -5,10 +5,11 @@ return {
|
|||||||
'nvim-telescope/telescope-fzy-native.nvim',
|
'nvim-telescope/telescope-fzy-native.nvim',
|
||||||
'nvim-tree/nvim-web-devicons',
|
'nvim-tree/nvim-web-devicons',
|
||||||
'axkirillov/easypick.nvim',
|
'axkirillov/easypick.nvim',
|
||||||
'benfowler/telescope-luasnip.nvim',
|
'catgoose/telescope-helpgrep.nvim',
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
local telescope = require('telescope')
|
local telescope = require('telescope')
|
||||||
|
local actions = require('telescope.actions')
|
||||||
telescope.setup({
|
telescope.setup({
|
||||||
defaults = {
|
defaults = {
|
||||||
mappings = {
|
mappings = {
|
||||||
@ -21,23 +22,38 @@ return {
|
|||||||
['<C-s>'] = 'select_horizontal',
|
['<C-s>'] = 'select_horizontal',
|
||||||
['<C-h>'] = 'preview_scrolling_left',
|
['<C-h>'] = 'preview_scrolling_left',
|
||||||
['<C-l>'] = 'preview_scrolling_right',
|
['<C-l>'] = 'preview_scrolling_right',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
layout_config = {
|
layout_config = {
|
||||||
height = 0.7,
|
height = 0.7,
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
extensions = {
|
||||||
|
helpgrep = {
|
||||||
|
mappings = {
|
||||||
|
i = {
|
||||||
|
["<CR>"] = actions.select_default,
|
||||||
|
["<C-v>"] = actions.select_vertical,
|
||||||
|
},
|
||||||
|
n = {
|
||||||
|
["<CR>"] = actions.select_default,
|
||||||
|
["<C-s>"] = actions.select_horizontal,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
telescope.load_extension('fzy_native')
|
telescope.load_extension('fzy_native')
|
||||||
telescope.load_extension('luasnip')
|
|
||||||
|
|
||||||
local builtin = require('telescope.builtin')
|
local builtin = require('telescope.builtin')
|
||||||
local opts = { noremap = true }
|
local opts = { noremap = true }
|
||||||
vim.keymap.set('n', '<leader>gF', builtin.find_files, opts)
|
vim.keymap.set('n', '<leader>gF', builtin.find_files, opts)
|
||||||
vim.keymap.set('n', '<leader>gf', builtin.git_files, opts)
|
vim.keymap.set('n', '<leader>gf', builtin.git_files, opts)
|
||||||
vim.keymap.set('n', '<leader>gg', builtin.live_grep, opts)
|
vim.keymap.set('n', '<leader>gg', builtin.live_grep, opts)
|
||||||
|
vim.keymap.set('n', '<leader>rg', builtin.grep_string, opts)
|
||||||
vim.keymap.set('n', '<leader>gb', builtin.buffers, opts)
|
vim.keymap.set('n', '<leader>gb', builtin.buffers, opts)
|
||||||
vim.keymap.set('n', '<leader>gh', builtin.help_tags, opts)
|
vim.keymap.set('n', '<leader>ht', builtin.help_tags, opts)
|
||||||
|
vim.keymap.set('n', '<leader>gh', require('telescope-helpgrep').live_grep, opts)
|
||||||
vim.keymap.set('n', '<leader>bl', builtin.current_buffer_fuzzy_find, opts)
|
vim.keymap.set('n', '<leader>bl', builtin.current_buffer_fuzzy_find, opts)
|
||||||
|
|
||||||
require('easypick').setup({
|
require('easypick').setup({
|
||||||
|
39
lua/plugins/tmux.lua
Normal file
39
lua/plugins/tmux.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
return {
|
||||||
|
'alexghergh/nvim-tmux-navigation',
|
||||||
|
config = function()
|
||||||
|
local plugin = require('nvim-tmux-navigation')
|
||||||
|
plugin.setup({
|
||||||
|
disable_when_zoomed = true,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Integrate tmux navigation flag
|
||||||
|
local navigation_flag =
|
||||||
|
'@vim' .. vim.fn.substitute(vim.env.TMUX_PANE, '%', '\\%', 'g')
|
||||||
|
local function set_navigation_flag()
|
||||||
|
vim.fn.system('tmux set-window-option ' .. navigation_flag .. ' 1')
|
||||||
|
end
|
||||||
|
local function unset_navigation_flag()
|
||||||
|
-- FIXME: Due to a regression this causes SIGABRT when RelWithDebInfo
|
||||||
|
-- vim.fn.system('tmux set-window-option -u ' .. navigation_flag)
|
||||||
|
-- https://github.com/neovim/neovim/issues/21856 contains a workaround
|
||||||
|
vim.fn.jobstart(
|
||||||
|
'tmux set-window-option -u ' .. navigation_flag, { detach = true})
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [Un]set tmux window option to detect when to change pane.
|
||||||
|
set_navigation_flag()
|
||||||
|
local augroup = vim.api.nvim_create_augroup('tmux', { clear = true })
|
||||||
|
vim.api.nvim_create_autocmd('FocusGained', {
|
||||||
|
pattern = '*', group = augroup, callback = set_navigation_flag,
|
||||||
|
})
|
||||||
|
vim.api.nvim_create_autocmd('VimLeave', {
|
||||||
|
pattern = '*', group = augroup, callback = unset_navigation_flag,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Map nativation bindings
|
||||||
|
vim.keymap.set('n', "<C-h>", plugin.NvimTmuxNavigateLeft)
|
||||||
|
vim.keymap.set('n', "<C-j>", plugin.NvimTmuxNavigateDown)
|
||||||
|
vim.keymap.set('n', "<C-k>", plugin.NvimTmuxNavigateUp)
|
||||||
|
vim.keymap.set('n', "<C-l>", plugin.NvimTmuxNavigateRight)
|
||||||
|
end
|
||||||
|
}
|
@ -62,7 +62,6 @@ return {
|
|||||||
'rst',
|
'rst',
|
||||||
'ssh_config',
|
'ssh_config',
|
||||||
'strace',
|
'strace',
|
||||||
'tablegen',
|
|
||||||
'tmux',
|
'tmux',
|
||||||
'toml',
|
'toml',
|
||||||
'vim',
|
'vim',
|
||||||
|
@ -33,13 +33,12 @@ local noice = {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
-- noice,
|
-- noice,
|
||||||
{ 'echasnovski/mini.comment', opts = { options = { ignore_blank_line = true } } },
|
|
||||||
{
|
{
|
||||||
'idanarye/nvim-impairative',
|
'tummetott/unimpaired.nvim',
|
||||||
config = function()
|
config = function()
|
||||||
require('impairative').setup({})
|
require('unimpaired').setup({})
|
||||||
require('impairative.replicate-unimpaired')()
|
end
|
||||||
end},
|
},
|
||||||
{ 'stevearc/dressing.nvim' },
|
{ 'stevearc/dressing.nvim' },
|
||||||
{ 'kevinhwang91/nvim-bqf' },
|
{ 'kevinhwang91/nvim-bqf' },
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,26 @@ vim.api.nvim_create_autocmd('TermOpen', {
|
|||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Don't show the line number column in terminal-insert mode
|
||||||
|
vim.api.nvim_create_autocmd('TermEnter', {
|
||||||
|
group = group, pattern = 'term://*',
|
||||||
|
callback = function()
|
||||||
|
vim.opt.number = false
|
||||||
|
vim.opt.relativenumber = false
|
||||||
|
vim.opt.signcolumn = 'no'
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
-- But do show the line number column in terminal-normal mode
|
||||||
|
vim.api.nvim_create_autocmd('TermLeave', {
|
||||||
|
group = group, pattern = 'term://*',
|
||||||
|
callback = function()
|
||||||
|
vim.opt.number = true
|
||||||
|
vim.opt.relativenumber = true
|
||||||
|
vim.opt.signcolumn = 'yes'
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-- Automatically press enter when the terminal process exit successfully
|
-- Automatically press enter when the terminal process exit successfully
|
||||||
vim.api.nvim_create_autocmd('TermClose', {
|
vim.api.nvim_create_autocmd('TermClose', {
|
||||||
group = group,
|
group = group,
|
||||||
|
@ -21,58 +21,42 @@ function build.set_dir(dirname)
|
|||||||
end
|
end
|
||||||
|
|
||||||
build.dir = build_dir
|
build.dir = build_dir
|
||||||
|
|
||||||
|
echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo')
|
||||||
local compile_commands = current_dir .. '/compile_commands.json'
|
local compile_commands = current_dir .. '/compile_commands.json'
|
||||||
|
-- Post-process compile_commands.json with compdb as an async job to avoid
|
||||||
|
-- blocking the user interface
|
||||||
|
vim.fn.jobstart(
|
||||||
|
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands, {
|
||||||
|
|
||||||
if vim.fn.executable('compdb') == 1 then
|
-- Restart clangd language server
|
||||||
echo('Processing compile_commands.json with compdb ...', 'DiagnosticInfo')
|
-- TODO: Configure cmake language server?
|
||||||
-- Post-process compile_commands.json with compdb as an async job to avoid
|
on_exit = function()
|
||||||
-- blocking the user interface
|
vim.cmd.LspRestart('clangd')
|
||||||
vim.fn.jobstart(
|
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
|
||||||
'compdb -p ' .. build.dir .. ' list > ' .. compile_commands, {
|
end,
|
||||||
|
|
||||||
-- Restart clangd language server
|
-- Display any error messages to the user
|
||||||
on_exit = function()
|
on_stderr = function(_, output, _)
|
||||||
-- This is a callback so doesn't run on the main thread which causes
|
-- Remove any lines containing a compdb warning
|
||||||
-- issues for running commands, so schedule that on the main thread.
|
local error = {}
|
||||||
vim.schedule(function()
|
local warning = 'WARNING:compdb'
|
||||||
vim.cmd('LspRestart')
|
for _, line in ipairs(output) do
|
||||||
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
|
if string.sub(line, 1, #warning) ~= warning then
|
||||||
end)
|
table.insert(error, line)
|
||||||
end,
|
|
||||||
|
|
||||||
-- Display any error messages to the user
|
|
||||||
on_stderr = function(_, output, _)
|
|
||||||
-- Remove any lines containing a compdb warning
|
|
||||||
local error = {}
|
|
||||||
local warning = 'WARNING:compdb'
|
|
||||||
for _, line in ipairs(output) do
|
|
||||||
if string.sub(line, 1, #warning) ~= warning then
|
|
||||||
table.insert(error, line)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Display the error message if there was one
|
-- Display the error message if there was one
|
||||||
if table.maxn(error) > 0 then
|
if table.maxn(error) > 0 then
|
||||||
echo(vim.fn.join(error, '\n'), 'Error')
|
echo(vim.fn.join(error, '\n'), 'Error')
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
stderr_buffered = true,
|
stderr_buffered = true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
else
|
|
||||||
vim.uv.fs_copyfile(build_dir .. '/compile_commands.json', compile_commands, nil,
|
|
||||||
function()
|
|
||||||
-- This is a callback so doesn't run on the main thread which causes
|
|
||||||
-- issues for running commands, so schedule that on the main thread.
|
|
||||||
vim.schedule(function()
|
|
||||||
vim.cmd('LspRestart')
|
|
||||||
echo('Build directory selected: ' .. dirname, 'DiagnosticInfo')
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function build.select_dir(callback)
|
function build.select_dir(callback)
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
-- :RStrip strip white space from right of all lines, ranges supported
|
-- :RString strip white psace from right of all lines, ranges supported
|
||||||
vim.api.nvim_create_user_command('RStrip', function(opts)
|
vim.api.nvim_create_user_command('RStrip', function(opts)
|
||||||
local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win())
|
local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win())
|
||||||
local range = opts.line1 .. ',' .. opts.line2
|
local range = opts.line1 .. ',' .. opts.line2
|
||||||
@ -7,15 +7,6 @@ vim.api.nvim_create_user_command('RStrip', function(opts)
|
|||||||
vim.fn.setpos('.', pos)
|
vim.fn.setpos('.', pos)
|
||||||
end, { range = '%' })
|
end, { range = '%' })
|
||||||
|
|
||||||
-- :LStrip strip white space from left of all lines, ranges supported
|
|
||||||
vim.api.nvim_create_user_command('LStrip', function(opts)
|
|
||||||
local pos = vim.fn.getcurpos(vim.api.nvim_get_current_win())
|
|
||||||
local range = opts.line1 .. ',' .. opts.line2
|
|
||||||
vim.cmd.execute("'" .. range .. 's/^\\s\\+//e' .. "'")
|
|
||||||
vim.cmd.nohlsearch()
|
|
||||||
vim.fn.setpos('.', pos)
|
|
||||||
end, { range = '%' })
|
|
||||||
|
|
||||||
-- :TabWidth set the tab width for the current buffer
|
-- :TabWidth set the tab width for the current buffer
|
||||||
vim.api.nvim_create_user_command('TabWidth', function(opts)
|
vim.api.nvim_create_user_command('TabWidth', function(opts)
|
||||||
-- Set the tab width for the current filetype
|
-- Set the tab width for the current filetype
|
||||||
@ -51,7 +42,7 @@ vim.api.nvim_create_user_command('Remove', function(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Actually remove the file using the selected callback.
|
-- Actually remove the file using the selecte callback.
|
||||||
vim.loop.fs_unlink(path, callback)
|
vim.loop.fs_unlink(path, callback)
|
||||||
end, { bang = true })
|
end, { bang = true })
|
||||||
|
|
||||||
@ -125,83 +116,13 @@ end, {
|
|||||||
complete = 'file',
|
complete = 'file',
|
||||||
})
|
})
|
||||||
|
|
||||||
-- :Rg grep for the given string, word under the cursor, or visual selection
|
-- :Rg grep for the given string and fuzzy find the results, bang to enable
|
||||||
-- then fuzzy find the results. Bang to enable regex in given string.
|
-- regex in given string
|
||||||
|
-- FIXME: Support visual select modes
|
||||||
vim.api.nvim_create_user_command('Rg', function(opts)
|
vim.api.nvim_create_user_command('Rg', function(opts)
|
||||||
local search = opts.args
|
local grep_opts = { search = opts.args }
|
||||||
if opts.range == 2 then
|
|
||||||
local lines = vim.fn.getline(vim.fn.line("'<"), vim.fn.line("'>"))
|
|
||||||
local start_col = vim.fn.col("'<")
|
|
||||||
local end_col = vim.fn.col("'>")
|
|
||||||
if #lines == 1 then
|
|
||||||
lines[1] = string.sub(lines[1], start_col, end_col)
|
|
||||||
else
|
|
||||||
lines[1] = string.sub(lines[1], start_col)
|
|
||||||
lines[#lines] = string.sub(lines[#lines], 1, end_col)
|
|
||||||
end
|
|
||||||
search = table.concat(lines, "\n")
|
|
||||||
elseif #search == 0 then
|
|
||||||
search = vim.fn.expand('<cword>')
|
|
||||||
end
|
|
||||||
local grep_opts = { search = search}
|
|
||||||
if opts.bang then
|
if opts.bang then
|
||||||
grep_opts['use_regex'] = true
|
grep_opts['use_regex'] = true
|
||||||
end
|
end
|
||||||
require('telescope.builtin').grep_string(grep_opts)
|
require('telescope.builtin').grep_string(grep_opts)
|
||||||
end, { bang = true, range = true, nargs = '*' })
|
end, { bang = true, nargs = '*' })
|
||||||
|
|
||||||
-- :PreProcIfWrap wraps the given range of lines in #if 0 / #endif.
|
|
||||||
vim.api.nvim_create_user_command('PreProcIfWrap', function(opts)
|
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
|
||||||
vim.api.nvim_buf_set_lines(
|
|
||||||
buffer, opts.line2, opts.line2, true, { '#endif' })
|
|
||||||
vim.api.nvim_buf_set_lines(
|
|
||||||
buffer, opts.line1 - 1, opts.line1 - 1, true, { '#if 0' })
|
|
||||||
local window = vim.api.nvim_get_current_win()
|
|
||||||
vim.api.nvim_win_set_cursor(window, { opts.line1, 5 })
|
|
||||||
end, { range = true })
|
|
||||||
|
|
||||||
-- :CheckboxToggle toggles GitHub Flavoured Markdown style checkboxes.
|
|
||||||
vim.api.nvim_create_user_command('CheckboxToggle', function(opts)
|
|
||||||
local linenr = vim.fn.line('.')
|
|
||||||
local line = vim.fn.getline(linenr)
|
|
||||||
local pos = string.find(line, '[ ]', 0, true)
|
|
||||||
if pos == nil then
|
|
||||||
pos = string.find(line, '[x]', 0, true)
|
|
||||||
if pos == nil then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local x = string.sub(line, pos + 1, pos + 1)
|
|
||||||
if x == 'x' then x = ' ' else x = 'x' end
|
|
||||||
vim.fn.setline(linenr, string.sub(line, 1, pos) .. x .. string.sub(line, pos + 2))
|
|
||||||
end, {})
|
|
||||||
|
|
||||||
-- :Tac reverse the order of lines in the selected range or the whole file if
|
|
||||||
-- no range is specificed, works as if executing :!tac but purely in Lua making
|
|
||||||
-- it cross-platform.
|
|
||||||
vim.api.nvim_create_user_command('Tac', function(opts)
|
|
||||||
local buffer = vim.api.nvim_get_current_buf()
|
|
||||||
local line1 = opts.line1 - 1
|
|
||||||
local line2 = opts.line2
|
|
||||||
if opts.range == 0 then
|
|
||||||
line1 = 0
|
|
||||||
line2 = -1
|
|
||||||
end
|
|
||||||
print(opts.range, line1, line2)
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(buffer, line1, line2, false)
|
|
||||||
if lines and #lines > 1 then
|
|
||||||
local temp = nil
|
|
||||||
for n = 1, math.floor(#lines / 2) do
|
|
||||||
temp = lines[n]
|
|
||||||
lines[n] = lines[#lines - (n - 1)]
|
|
||||||
lines[#lines - (n - 1)] = temp
|
|
||||||
end
|
|
||||||
vim.api.nvim_buf_set_lines(buffer, line1, line2, true, lines)
|
|
||||||
end
|
|
||||||
end, { range = true })
|
|
||||||
|
|
||||||
-- :DiagnosticToggle to disable diagnostics when enabled and vise versa.
|
|
||||||
vim.api.nvim_create_user_command('DiagnosticToggle', function(_)
|
|
||||||
vim.diagnostic.enable(not vim.diagnostic.is_enabled())
|
|
||||||
end, {})
|
|
||||||
|
@ -43,10 +43,3 @@ vim.keymap.set('t', '<C-w><C-g>', '<C-\\><C-n>:Gdb<CR>:startinsert<CR>', opts)
|
|||||||
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
|
vim.keymap.set('t', '<C-w><C-e>', '<C-\\><C-n>:Program<CR>', opts)
|
||||||
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
|
vim.keymap.set('t', '<C-w><C-s>', '<C-\\><C-n>:Source<CR>', opts)
|
||||||
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
|
vim.keymap.set('t', '<C-w><C-a>', '<C-\\><C-n>:Asm<CR>', opts)
|
||||||
|
|
||||||
-- Mappings to grep for then fuzzy find the word under the cursor or visual selection
|
|
||||||
vim.keymap.set('n', '<leader>rg', ':Rg<CR>', opts)
|
|
||||||
vim.keymap.set('v', '<leader>rg', ":'<,'>Rg<CR>", opts)
|
|
||||||
|
|
||||||
-- Mapping to toggle checkboxes
|
|
||||||
vim.keymap.set('n', '<leader><CR>', ':CheckboxToggle<CR>', opts)
|
|
||||||
|
@ -60,7 +60,7 @@ local function get_mode()
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Display cusor line/total and column
|
-- Display cusor line/total and column
|
||||||
local position = '# %l/%L:%2c '
|
local position = '# ☰ %l/%L %2c '
|
||||||
|
|
||||||
-- Construct a statusline for special buffer types.
|
-- Construct a statusline for special buffer types.
|
||||||
local function special(group, name, title)
|
local function special(group, name, title)
|
||||||
@ -75,7 +75,7 @@ local function special(group, name, title)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Construct a statusline for generic buffer types.
|
-- Construct a statusline for generic buffer types.
|
||||||
local function generic(group, name)
|
local function generic(group, name, show_lsp)
|
||||||
-- Display current mode with dynamic highlights.
|
-- Display current mode with dynamic highlights.
|
||||||
local line = '%#' .. group .. '# ' .. name .. ' '
|
local line = '%#' .. group .. '# ' .. name .. ' '
|
||||||
-- Display spell or paste if set with dusk highlights in a group to swallow
|
-- Display spell or paste if set with dusk highlights in a group to swallow
|
||||||
@ -131,11 +131,11 @@ function _G.statusline_active()
|
|||||||
return special('StatusLineLight', 'Terminal', '%f')
|
return special('StatusLineLight', 'Terminal', '%f')
|
||||||
elseif vim.o.previewwindow then
|
elseif vim.o.previewwindow then
|
||||||
if mode == 'Normal' then mode = 'Preview' end
|
if mode == 'Normal' then mode = 'Preview' end
|
||||||
return generic('StatusLineLight', mode)
|
return generic('StatusLineLight', mode, false)
|
||||||
elseif vim.o.filetype == 'man' then
|
elseif vim.o.filetype == 'man' then
|
||||||
return special('StatusLineDusk', 'Manual', '%f')
|
return special('StatusLineDusk', 'Manual', '%f')
|
||||||
end
|
end
|
||||||
return generic('StatusLineLight', mode)
|
return generic('StatusLineLight', mode, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function _G.statusline_inactive()
|
function _G.statusline_inactive()
|
||||||
@ -152,11 +152,11 @@ function _G.statusline_inactive()
|
|||||||
elseif vim.o.buftype == 'terminal' then
|
elseif vim.o.buftype == 'terminal' then
|
||||||
line = special('StatusLineDusk', 'Terminal', '%f')
|
line = special('StatusLineDusk', 'Terminal', '%f')
|
||||||
elseif vim.o.previewwindow then
|
elseif vim.o.previewwindow then
|
||||||
line = generic('StatusLineDusk', 'Preview')
|
line = generic('StatusLineDusk', 'Preview', false)
|
||||||
elseif vim.o.filetype == 'man' then
|
elseif vim.o.filetype == 'man' then
|
||||||
line = special('StatusLineDusk', 'Manual', '%f')
|
line = special('StatusLineDusk', 'Manual', '%f')
|
||||||
else
|
else
|
||||||
line = generic('StatusLineDusk', 'Idle')
|
line = generic('StatusLineDusk', 'Idle', false)
|
||||||
end
|
end
|
||||||
return line
|
return line
|
||||||
end
|
end
|
||||||
|
@ -6,7 +6,7 @@ local snip = luasnip.snippet
|
|||||||
local text = luasnip.text_node
|
local text = luasnip.text_node
|
||||||
-- local isn = luasnip.indent_snippet_node
|
-- local isn = luasnip.indent_snippet_node
|
||||||
-- local t = luasnip.text_node
|
-- local t = luasnip.text_node
|
||||||
local ins = luasnip.insert_node
|
local insert = luasnip.insert_node
|
||||||
local func = luasnip.function_node
|
local func = luasnip.function_node
|
||||||
-- local c = luasnip.choice_node
|
-- local c = luasnip.choice_node
|
||||||
-- local d = luasnip.dynamic_node
|
-- local d = luasnip.dynamic_node
|
||||||
@ -67,7 +67,7 @@ for _, name in ipairs({ 'fixme', 'todo', 'hack', 'warn', 'note' }) do
|
|||||||
snip(name, {
|
snip(name, {
|
||||||
func(comment_prefix),
|
func(comment_prefix),
|
||||||
text(string.upper(name) .. ': '),
|
text(string.upper(name) .. ': '),
|
||||||
ins(0),
|
insert(0),
|
||||||
func(comment_suffix),
|
func(comment_suffix),
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
@ -7,11 +7,6 @@ local insert = luasnip.insert_node
|
|||||||
local func = luasnip.function_node
|
local func = luasnip.function_node
|
||||||
local key = require("luasnip.nodes.key_indexer").new_key
|
local key = require("luasnip.nodes.key_indexer").new_key
|
||||||
|
|
||||||
local function getIncludeGuardName()
|
|
||||||
local filename = vim.fn.expand('%'):gsub('[^%w_]', '_'):upper()
|
|
||||||
return filename .. '_INCLUDED'
|
|
||||||
end
|
|
||||||
|
|
||||||
local snippets = {
|
local snippets = {
|
||||||
snip('#include', {
|
snip('#include', {
|
||||||
text('#include '),
|
text('#include '),
|
||||||
@ -25,21 +20,6 @@ local snippets = {
|
|||||||
end
|
end
|
||||||
end, key('open')),
|
end, key('open')),
|
||||||
}),
|
}),
|
||||||
|
|
||||||
snip('once', {
|
|
||||||
text('#ifndef '),
|
|
||||||
func(function(args)
|
|
||||||
return args[1][1]
|
|
||||||
end, key('name')),
|
|
||||||
text({ '', '#define ' }),
|
|
||||||
insert(1, getIncludeGuardName(), { key = 'name' }),
|
|
||||||
text({ '', '', '', }),
|
|
||||||
insert(0, ''),
|
|
||||||
text({ '', '', '#endif // ' }),
|
|
||||||
func(function(args)
|
|
||||||
return args[1][1]
|
|
||||||
end, key('name')),
|
|
||||||
}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return snippets
|
return snippets
|
||||||
|
@ -1,48 +1,5 @@
|
|||||||
-- C++ LuaSnip Snippets
|
# C++ LuaSnip Snippets
|
||||||
|
|
||||||
local luasnip = require('luasnip')
|
local luasnip = require('luasnip')
|
||||||
|
|
||||||
luasnip.filetype_extend('cpp', { 'c' })
|
luasnip.filetype_extend('cpp', { 'c' })
|
||||||
local snip = luasnip.snippet
|
|
||||||
local text = luasnip.text_node
|
|
||||||
local ins = luasnip.insert_node
|
|
||||||
local dyn = luasnip.dynamic_node
|
|
||||||
local node = luasnip.snippet_node
|
|
||||||
local key = require("luasnip.nodes.key_indexer").new_key
|
|
||||||
|
|
||||||
local snippets = {
|
|
||||||
|
|
||||||
snip('for', {
|
|
||||||
text('for ('),
|
|
||||||
ins(1, 'auto'),
|
|
||||||
text(' '),
|
|
||||||
ins(2, 'index'),
|
|
||||||
text(' '),
|
|
||||||
ins(3, '='),
|
|
||||||
dyn(4, function(args)
|
|
||||||
local choice = args[2][1]
|
|
||||||
if choice == '=' then -- index based for loop
|
|
||||||
local var = args[1][1]
|
|
||||||
return node(nil, {
|
|
||||||
text(' '),
|
|
||||||
ins(1, '0'),
|
|
||||||
text('; ' .. var .. ' < '),
|
|
||||||
ins(2, 'count'),
|
|
||||||
text('; '),
|
|
||||||
ins(3, var .. '++'),
|
|
||||||
})
|
|
||||||
elseif choice == ':' then -- range based for loop
|
|
||||||
return node(nil, {
|
|
||||||
text(' '),
|
|
||||||
ins(1, 'container')
|
|
||||||
})
|
|
||||||
end
|
|
||||||
return node(nil, {})
|
|
||||||
end, { 2, 3 }, key('var')),
|
|
||||||
text({ ') {', '\t' }),
|
|
||||||
ins(0, ''),
|
|
||||||
text({ '', '}' })
|
|
||||||
}),
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return snippets
|
|
||||||
|
@ -2,6 +2,16 @@
|
|||||||
|
|
||||||
extends c
|
extends c
|
||||||
|
|
||||||
|
snippet for Range based
|
||||||
|
for (${1:auto} ${2:value} : ${3:container}) {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
|
||||||
|
snippet for Index based
|
||||||
|
for (${1:int} i = ${2:0}; i < ${3:count}; i++) {
|
||||||
|
$0
|
||||||
|
}
|
||||||
|
|
||||||
snippet namespace
|
snippet namespace
|
||||||
namespace ${1} {
|
namespace ${1} {
|
||||||
$0
|
$0
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
# Go LuaSnip Snippets
|
|
||||||
|
|
||||||
local luasnip = require('luasnip')
|
|
||||||
local snip = luasnip.snippet
|
|
||||||
local text = luasnip.text_node
|
|
||||||
local ins = luasnip.insert_node
|
|
||||||
local func = luasnip.function_node
|
|
||||||
local node = luasnip.snippet_node
|
|
||||||
local key = require("luasnip.nodes.key_indexer").new_key
|
|
||||||
|
|
||||||
local function short_name(name)
|
|
||||||
local short = string.lower(string.sub(name, 1, 1))
|
|
||||||
for i = 2, #name do
|
|
||||||
local char = string.sub(name, i, i)
|
|
||||||
if char == string.upper(char) then
|
|
||||||
short = short .. char
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return string.lower(short)
|
|
||||||
end
|
|
||||||
|
|
||||||
local snippets = {
|
|
||||||
|
|
||||||
snip('func', {
|
|
||||||
text('func '),
|
|
||||||
node(1, {
|
|
||||||
func(function(args)
|
|
||||||
if string.len(args[1][1]) > 0 then
|
|
||||||
return '(' .. short_name(args[1][1]) .. ' *'
|
|
||||||
end
|
|
||||||
return ''
|
|
||||||
end, key('type')),
|
|
||||||
ins(1, '', { key = 'type' }),
|
|
||||||
func(function(args)
|
|
||||||
if string.len(args[1][1]) > 0 then
|
|
||||||
return ') '
|
|
||||||
end
|
|
||||||
return ''
|
|
||||||
end, key('type')),
|
|
||||||
}),
|
|
||||||
ins(2, 'name'),
|
|
||||||
text('('),
|
|
||||||
ins(3, ''),
|
|
||||||
text(') '),
|
|
||||||
ins(4, '', { key = 'return' }),
|
|
||||||
func(function(args)
|
|
||||||
if string.len(args[1][1]) > 0 then
|
|
||||||
return ' '
|
|
||||||
end
|
|
||||||
return ''
|
|
||||||
end, key('return')),
|
|
||||||
text({ '{', '\t' }),
|
|
||||||
ins(0, ''),
|
|
||||||
text({ '', '}' }),
|
|
||||||
}),
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return snippets
|
|
@ -1,8 +0,0 @@
|
|||||||
# Go SnipMate snippets
|
|
||||||
|
|
||||||
snippet main
|
|
||||||
package main
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
$0
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user