From cecf9a7f3d0560bb5ef42102a9a4003350af193c Mon Sep 17 00:00:00 2001 From: Kevin Knosala Date: Fri, 12 Apr 2024 12:06:47 +0200 Subject: [PATCH] Custom snippets and snakemake support --- init.lua | 14 ++-- lua/custom/keymap.lua | 12 +-- my-snippets/package.json | 14 ++++ my-snippets/snippets/python.json | 9 +++ syntax/snakemake.vim | 126 ------------------------------- 5 files changed, 37 insertions(+), 138 deletions(-) create mode 100644 my-snippets/package.json create mode 100644 my-snippets/snippets/python.json delete mode 100644 syntax/snakemake.vim diff --git a/init.lua b/init.lua index b93ab38d..97a330d1 100644 --- a/init.lua +++ b/init.lua @@ -670,6 +670,7 @@ require('lazy').setup({ 'rafamadriz/friendly-snippets', config = function() require('luasnip.loaders.from_vscode').lazy_load() + require('luasnip.loaders.from_vscode').load { paths = { './my-snippets' } } end, }, }, @@ -714,6 +715,7 @@ require('lazy').setup({ -- This will auto-import if your LSP supports it. -- This will expand snippets if the LSP sent a snippet. [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.confirm { select = true }, -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display @@ -733,11 +735,11 @@ require('lazy').setup({ luasnip.expand_or_jump() end end, { 'i', 's' }), - [''] = cmp.mapping(function() - if luasnip.locally_jumpable(-1) then - luasnip.jump(-1) - end - end, { 'i', 's' }), + -- [''] = cmp.mapping(function() + -- if luasnip.locally_jumpable(-1) then + -- luasnip.jump(-1) + -- end + -- end, { 'i', 's' }), -- For more advanced Luasnip keymaps (e.g. selecting choice nodes, expansion) see: -- https://github.com/L3MON4D3/LuaSnip?tab=readme-ov-file#keymaps @@ -809,7 +811,7 @@ require('lazy').setup({ 'nvim-treesitter/nvim-treesitter', build = ':TSUpdate', opts = { - ensure_installed = { 'bash', 'c', 'html', 'json', 'lua', 'luadoc', 'markdown', 'python', 'rust', 'toml', 'typst', 'vim', 'vimdoc', 'yaml' }, + ensure_installed = { 'bash', 'c', 'html', 'json', 'lua', 'luadoc', 'markdown', 'python', 'rust', 'toml', 'typst', 'vim', 'vimdoc', 'yaml', 'snakemake' }, -- Autoinstall languages that are not installed auto_install = true, highlight = { diff --git a/lua/custom/keymap.lua b/lua/custom/keymap.lua index f1105561..b3ad4d99 100644 --- a/lua/custom/keymap.lua +++ b/lua/custom/keymap.lua @@ -29,12 +29,12 @@ vim.keymap.set('n', 'm', ':make ', { desc = '[M]ake' }) vim.keymap.set('n', 'su', require('telescope').extensions.undo.undo, { desc = '[S]earch [U]ndo' }) -- Compile markdown to html with pandoc -vim.keymap.set( - 'n', - '', - ":! pandoc '%:p' -o /tmp/'%:p:t'.html --template=easy_template.html --toc && /mnt/c/Program\\ Files/Mozilla\\ Firefox/ /tmp/'%:p:t'.html &", - { desc = 'Build [M]arkdown to HTML' } -) +-- vim.keymap.set( +-- 'n', +-- '', +-- ":! pandoc '%:p' -o /tmp/'%:p:t'.html --template=easy_template.html --toc && /mnt/c/Program\\ Files/Mozilla\\ Firefox/ /tmp/'%:p:t'.html &", +-- { desc = 'Build [M]arkdown to HTML' } +-- ) -- Spectre vim.keymap.set('n', 'S', 'lua require("spectre").toggle()', { diff --git a/my-snippets/package.json b/my-snippets/package.json new file mode 100644 index 00000000..294e8647 --- /dev/null +++ b/my-snippets/package.json @@ -0,0 +1,14 @@ +{ + "name": "my-snippets", + "engines": { + "vscode": "^1.11.0" + }, + "contributes": { + "snippets": [ + { + "language": "python", + "path": "./snippets/python.json" + } + ] + } +} diff --git a/my-snippets/snippets/python.json b/my-snippets/snippets/python.json new file mode 100644 index 00000000..04f480d3 --- /dev/null +++ b/my-snippets/snippets/python.json @@ -0,0 +1,9 @@ +{ + "# type: ignore": { + "prefix": "ti", + "body": [ + " # type: ignore" + ], + "description": "Insert # type: ignore" + } +} diff --git a/syntax/snakemake.vim b/syntax/snakemake.vim deleted file mode 100644 index 1660412f..00000000 --- a/syntax/snakemake.vim +++ /dev/null @@ -1,126 +0,0 @@ -" Vim syntax file -" Language: Snakemake (extended from python.vim) -" Maintainer: Jay Hesselberth (jay.hesselberth@gmail.com) -" Last Change: 2020 Oct 6 -" -" Usage -" -" copy to $HOME/.vim/syntax directory and -" copy to ftdetect/snakemake.vim to $HOME/.vim/ftdetect directory -" -" force coloring in a vim session with: -" -" :set syntax=snakemake -" -if exists("b:current_syntax") - finish -endif - -" load settings from system python.vim (7.4) -source $VIMRUNTIME/syntax/python.vim -source $VIMRUNTIME/indent/python.vim - -" -" Snakemake rules, as of version 5.8 -" -" -" rule = "rule" (identifier | "") ":" ruleparams -" include = "include:" stringliteral -" workdir = "workdir:" stringliteral -" ni = NEWLINE INDENT -" ruleparams = [ni input] [ni output] [ni params] [ni message] [ni threads] [ni (run | shell)] NEWLINE snakemake -" input = "input" ":" parameter_list -" output = "output" ":" parameter_list -" params = "params" ":" parameter_list -" message = "message" ":" stringliteral -" threads = "threads" ":" integer -" resources = "resources" ":" parameter_list -" version = "version" ":" statement -" run = "run" ":" ni statement -" shell = "shell" ":" stringliteral -" singularity = "singularity" ":" stringliteral -" conda = "conda" ":" stringliteral -" shadow = "shadow" ":" stringliteral -" group = "group" ":" stringliteral - - -" general directives (e.g. input) -syn keyword pythonStatement - \ benchmark - \ conda - \ configfile - \ container - \ default_target - \ envmodules - \ group - \ include - \ input - \ localrule - \ localrules - \ log - \ message - \ notebook - \ onerror - \ onstart - \ onsuccess - \ output - \ params - \ priority - \ resources - \ ruleorder - \ run - \ scattergather - \ script - \ shadow - \ shell - \ singularity - \ snakefile - \ template_engine - \ threads - \ version - \ wildcard_constraints - \ wildcards - \ workdir - \ wrapper - -" directives with a label (e.g. rule) -syn keyword pythonStatement - \ checkpoint - \ rule - \ subworkflow - \ nextgroup=pythonFunction skipwhite - -" common snakemake objects -syn keyword pythonBuiltinObj - \ Paramspace - \ checkpoints - \ config - \ gather - \ rules - \ scatter - \ workflow - -" snakemake functions -syn keyword pythonBuiltinFunc - \ ancient - \ directory - \ expand - \ multiext - \ pipe - \ protected - \ read_job_properties - \ service - \ temp - \ touch - \ unpack - -" similar to special def and class treatment from python.vim, except -" parenthetical part of def and class -syn match pythonFunction - \ "\%(\%(rule\s\|subworkflow\s\|checkpoint\s\)\s*\)\@<=\h\w*" contained - -syn sync match pythonSync grouphere NONE "^\s*\%(rule\|subworkflow\|checkpoint\)\s\+\h\w*\s*" - -let b:current_syntax = "snakemake" - -" vim:set sw=2 sts=2 ts=8 noet: