diff options
Diffstat (limited to '.vim')
| -rw-r--r-- | .vim/after/snippets/_.snippets | 22 | ||||
| -rw-r--r-- | .vim/autoload/snips.vim | 8 | ||||
| -rw-r--r-- | .vim/lua/plugins.lua | 157 | ||||
| -rw-r--r-- | .vim/lua/snips.lua | 78 |
4 files changed, 185 insertions, 80 deletions
diff --git a/.vim/after/snippets/_.snippets b/.vim/after/snippets/_.snippets deleted file mode 100644 index 7c99bd0..0000000 --- a/.vim/after/snippets/_.snippets +++ /dev/null @@ -1,22 +0,0 @@ -snippet sign "Robert Günzler <r@gnzler.io>" - Robert Günzler <r@gnzler.io> -snippet me "git user id" - `snips#exec('git config --get user.name')` <`snips#exec('git config --get user.email')`> -snippet today "YYYY-MM-DD" - `luaeval("os.date('%Y-%m-%d')")` -snippet nowutc "YYYY-MM-DDThh:mm:ssZ" - `luaeval("os.date('!%Y-%m-%dT%H:%M:%SZ')")` -snippet nowloc "YYYY-MM-DDThh:mm:ssZ" - `luaeval("os.date('%Y-%m-%dT%H:%M:%SZ')")` -snippet ok "✔" - ✔ -snippet bad "✘" - ✘ -snippet arrow "→" - → -snippet arrowb "⇒" - ⇒ -snippet todo "TODO(<user>): ..." - `snips#comment('TODO(' .. snips#exec('id -un') .. '):')` $0 -snippet note "NOTE(<user>): ..." - `snips#comment('NOTE(' .. snips#exec('id -un') .. '):')` $0 diff --git a/.vim/autoload/snips.vim b/.vim/autoload/snips.vim deleted file mode 100644 index 3136c2a..0000000 --- a/.vim/autoload/snips.vim +++ /dev/null @@ -1,8 +0,0 @@ - -function snips#exec(arg) - return luaeval("require('snips').exec")(a:arg) -endfunction - -function snips#comment(arg) - return luaeval("require('snips').comment")(a:arg) -endfunction diff --git a/.vim/lua/plugins.lua b/.vim/lua/plugins.lua index bef00cc..49748e8 100644 --- a/.vim/lua/plugins.lua +++ b/.vim/lua/plugins.lua @@ -364,15 +364,19 @@ return require('packer').startup({function() use {'hrsh7th/nvim-cmp', -- {{{ requires = { 'hrsh7th/cmp-buffer', + 'hrsh7th/cmp-cmdline', 'hrsh7th/cmp-path', 'hrsh7th/cmp-nvim-lua', 'hrsh7th/cmp-nvim-lsp', - -- 3rd party - 'dcampos/cmp-snippy', + 'hrsh7th/cmp-nvim-lsp-document-symbol', + 'hrsh7th/cmp-nvim-lsp-signature-help', + 'saadparwaiz1/cmp_luasnip', 'f3fora/cmp-spell', + 'onsails/lspkind-nvim', }, config = function() local cmp = require('cmp') + local luasnip = require('luasnip') cmp.setup { completion = { -- autocomplete = { cmp.TriggerEvent.TextChanged } @@ -383,46 +387,163 @@ return require('packer').startup({function() border = { '', '', '', ' ', '', '', '', ' ' }, }, mapping = { - ['<cr>'] = cmp.mapping.confirm(), + ['<cr>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + elseif luasnip.expandable() then + luasnip.expand() + else + fallback() + end + end), ['<c-space>'] = cmp.mapping.complete(), - ['<c-e>'] = cmp.mapping.close(), + ['<c-e>'] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + ['<c-n>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's'}), + ['<c-p>'] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { 'i', 's'}), + ['<tab>'] = cmp.mapping({ + i = function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + elseif luasnip.expandable() then + luasnip.expand() + else + fallback() + end + end, + s = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + c = function(fallback) + if cmp.visible() then + cmp.select_next_item() + else + fallback() + end + end, + }), + ['<s-tab>'] = cmp.mapping({ + s = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + c = function(fallback) + if cmp.visible() then + cmp.select_prev_item() + else + fallback() + end + end, + }), }, snippet = { expand = function(args) - require('snippy').expand_snippet(args.body) + require('luasnip').lsp_expand(args.body) end, }, - sources = { + sources = cmp.config.sources({ { name = 'nvim_lsp' }, - { name = 'snippy' }, + { name = 'nvim_lsp_signature_help' }, + { name = 'luasnip' }, { name = 'nvim_lua' }, + }, { { name = 'neorg' }, { name = 'orgmode' }, { name = 'spell', keyword_length = 3, max_item_count = 10 }, { name = 'path' }, { name = 'buffer', keyword_length = 3 }, - }, + }), formatting = { format = require('lspkind').cmp_format { with_text = false, menu = { - nvim_lsp = '[lsp]', - snippy = '[snip]', - nvim_lua = '[nvim]', - orgmode = '[org]', - spell = '[spell]', - path = '[path]', - buffer = '[buf]', + nvim_lsp = '[LSP]', + luasnip = '[SNIP]', + nvim_lua = '[NVIM]', + orgmode = '[ORG]', + spell = '[SPELL]', + path = '[PATH]', + buffer = '[BUF]', } } }, - experimental = { - native_menu = false, - -- ghost_text = { hl_group = 'Comment' } + } + cmp.setup.cmdline('/', { + sources = cmp.config.sources({ + { name = 'nvim_lsp_document_symbol' } + }, { + { name = 'buffer' } + }) + }) + cmp.setup.cmdline(':', { + sources = cmp.config.sources({ + { name = 'path' } + }, { + { name = 'cmdline' } + }) + }) + + require('lspkind').init { + symbol_map = { + Text = '', + Method = '', + Function = '', + Constructor = '', + Field = '', + Variable = '', + Class = '', + Interface = '', + Module = '', + Property = '', + Unit = '', + Value = '', + Enum = '', + Keyword = '', + Snippet = '', + Color = '', + File = '', + Reference = '', + Folder = '', + EnumMember = '', + Constant = '', + Struct = 'פּ', + Event = '', + Operator = '', + TypeParameter = '', } } end} -- }}} + use {'L3MON4D3/LuaSnip', -- {{{ + config = function() + require('snips') + end} -- }}} + use {'nvim-telescope/telescope.nvim', --- {{{ requires = { 'nvim-lua/popup.nvim', diff --git a/.vim/lua/snips.lua b/.vim/lua/snips.lua index b8c8b77..c4a58af 100644 --- a/.vim/lua/snips.lua +++ b/.vim/lua/snips.lua @@ -1,36 +1,50 @@ -local M = {} -M.exec = function(cmd) - return io.popen(cmd):read'*l' -end +local ls = require("luasnip") +local fmt = require('luasnip.extras.fmt').fmt -local function find_sub(s, replacement, pattern, start, special) - local x1, x2 = s:find(pattern, start, special) - if x1 then - return s:sub(1, x1-1) .. replacement .. s:sub(x2+1), x1, x2 - end - return s -end --- Only works with prefix comments. -local function get_line_comment() - local cms = vim.bo.commentstring - -- This whole pesc dance is a bummer. - local pattern = '^(%s*)' .. - (find_sub(vim.pesc((find_sub(cms, '\0', '%s', 1, true))), '(%s*).*', '\0', 1, true)) - local pre_ws, inner_ws = vim.api.nvim_get_current_line():match(pattern) - if pre_ws then - return pre_ws .. cms:format('') .. inner_ws - end - return '' -end -M.comment = function(str) - -- add space - local prefix = vim.bo.commentstring:format(''):gsub('%S$', '%0 ') - local comment = get_line_comment() - if comment ~= '' then - prefix = '' - end - return prefix .. str +local s = ls.s +local t = ls.text_node +local f = ls.function_node +-- local i = ls.insert_node + +local exec = function(command) + return f(function(_, _, arg) + local p = io.popen(arg, 'r') + local res = {} + for line in p:lines() do + table.insert(res, line) + end + return res + end, {}, { user_args = { command }}) end -return M +-- snipmate snippets +require('luasnip.loaders.from_snipmate').load({ paths = {'~/.config/nvim/after/snippets'} }) + +-- luasnip snippets +ls.add_snippets('all', { + s( + 'sign', + t('Robert Günzler <r@gnzler.io>') + ), + + s( + 'me', + fmt( + [[{} <{}>]], { + exec('git config --get user.name'), + exec('git config --get user.email'), + } + ) + ), + + s( + 'today', + f(function() return os.date('%Y-%m-%d') end, {}) + ), + + s( + 'now', + f(function() return os.date('%Y-%m-%dT%H:%M:%SZ') end, {}) + ) +}) |