Compare commits

...

4 Commits

Author SHA1 Message Date
e78c8fc07f Add :PreProcIfWrap command and C/C++ mappings
Quickly wrap a line or range in `#if 0`/`#endif` to quickly disable
compilation of sections of code.
2024-05-25 10:24:07 +01:00
0602390a2d Add telescope extension to list luasnip snippets 2024-05-25 10:22:35 +01:00
b0cfb31645 Add func snippet for go 2024-05-24 23:09:47 +01:00
Kenneth Benzie (Benie)
aba1664d09 Cleanup unused arg in statusline implementation 2024-05-24 16:04:23 +01:00
6 changed files with 83 additions and 5 deletions

3
after/ftplugin/c.lua Normal file
View File

@@ -0,0 +1,3 @@
local opts = { buffer = true, remap = false, silent = true }
vim.keymap.set('n', '0', ':PreProcIfWrap<CR>', opts)
vim.keymap.set('v', '0', ':PreProcIfWrap<CR>', opts)

View File

@@ -1,2 +1,6 @@
vim.opt.commentstring = '//%s'
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)

View File

@@ -5,6 +5,7 @@ return {
'nvim-telescope/telescope-fzy-native.nvim',
'nvim-tree/nvim-web-devicons',
'axkirillov/easypick.nvim',
'benfowler/telescope-luasnip.nvim',
},
config = function()
local telescope = require('telescope')
@@ -28,6 +29,7 @@ return {
},
})
telescope.load_extension('fzy_native')
telescope.load_extension('luasnip')
local builtin = require('telescope.builtin')
local opts = { noremap = true }

View File

@@ -126,3 +126,13 @@ vim.api.nvim_create_user_command('Rg', function(opts)
end
require('telescope.builtin').grep_string(grep_opts)
end, { bang = true, nargs = '*' })
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 })

View File

@@ -75,7 +75,7 @@ local function special(group, name, title)
end
-- Construct a statusline for generic buffer types.
local function generic(group, name, show_lsp)
local function generic(group, name)
-- Display current mode with dynamic highlights.
local line = '%#' .. group .. '# ' .. name .. ' '
-- 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')
elseif vim.o.previewwindow then
if mode == 'Normal' then mode = 'Preview' end
return generic('StatusLineLight', mode, false)
return generic('StatusLineLight', mode)
elseif vim.o.filetype == 'man' then
return special('StatusLineDusk', 'Manual', '%f')
end
return generic('StatusLineLight', mode, true)
return generic('StatusLineLight', mode)
end
function _G.statusline_inactive()
@@ -152,11 +152,11 @@ function _G.statusline_inactive()
elseif vim.o.buftype == 'terminal' then
line = special('StatusLineDusk', 'Terminal', '%f')
elseif vim.o.previewwindow then
line = generic('StatusLineDusk', 'Preview', false)
line = generic('StatusLineDusk', 'Preview')
elseif vim.o.filetype == 'man' then
line = special('StatusLineDusk', 'Manual', '%f')
else
line = generic('StatusLineDusk', 'Idle', false)
line = generic('StatusLineDusk', 'Idle')
end
return line
end

59
snippets/go.lua Normal file
View File

@@ -0,0 +1,59 @@
# 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