From 4fab2f74255b4dee7705a1766e96cda8434cf070 Mon Sep 17 00:00:00 2001 From: Frizzus Date: Mon, 20 Jan 2025 20:33:34 +0100 Subject: [PATCH] many snippets --- init.lua | 2 + lua/custom/plugins/custom_init.lua | 14 ++++ lua/custom/plugins/snippets.lua | 105 ++++++++++++++++++++++++++++- 3 files changed, 120 insertions(+), 1 deletion(-) diff --git a/init.lua b/init.lua index 471a502f..a1ffcb9f 100644 --- a/init.lua +++ b/init.lua @@ -959,3 +959,5 @@ ls.add_snippets('tcl', snippets.tcl) ls.add_snippets('typst', snippets.typst) ls.add_snippets('c', snippets.c) ls.add_snippets('cpp', snippets.c_header) +ls.add_snippets('bib', snippets.bib) +ls.add_snippets('javascript', snippets.js) diff --git a/lua/custom/plugins/custom_init.lua b/lua/custom/plugins/custom_init.lua index a1873f8b..466da2ad 100644 --- a/lua/custom/plugins/custom_init.lua +++ b/lua/custom/plugins/custom_init.lua @@ -11,5 +11,19 @@ return { vim.o.tabstop = 4 vim.o.shiftwidth = 4 vim.o.expandtab = true + + vim.keymap.set('', '', '', { noremap = true }) + vim.keymap.set('', '', '', { noremap = true }) + vim.keymap.set('i', '', '', { noremap = true }) + vim.keymap.set('i', '', '', { noremap = true }) + vim.keymap.set('i', '', '', { noremap = true }) + vim.keymap.set('i', '', '', { noremap = true }) + + vim.opt.mouse = '' + vim.opt.mousescroll = 'ver:0,hor:0' + + vim.api.nvim_create_user_command('ConfEdit', function() + vim.cmd 'edit ~/.config/nvim/lua/custom/plugins/' + end, { desc = 'Ouvrir le dossier des plugins personnalisés' }) end, } diff --git a/lua/custom/plugins/snippets.lua b/lua/custom/plugins/snippets.lua index 3d3ad19e..7ea6eecd 100644 --- a/lua/custom/plugins/snippets.lua +++ b/lua/custom/plugins/snippets.lua @@ -3,6 +3,7 @@ local s = ls.snippet local t = ls.text_node local i = ls.insert_node local rep = require('luasnip.extras').rep +local fmt = require('luasnip.extras.fmt').fmt return { -- Snippet pour la déclaration de fonction Tcl @@ -57,7 +58,7 @@ return { }, -- Déclaration de snippet typst typst = { - s('images', { + s('image', { t { '#figure(caption: "' }, i(1, 'caption'), t { '")[', '' }, @@ -66,6 +67,20 @@ return { t { '")', '' }, t { ']' }, }), + s('image_paysage', { + t { '#page(flipped:true)[', ' #figure(caption: "' }, + i(1, ''), + t { '")[', ' #align(center + horizon)[#image("' }, + i(2, ''), + t { '")]', ' ]', ']' }, + }), + s('code_fig', { + t { '#figure(caption:"' }, + i(1, 'Légende'), + t { '")[```', '' }, + i(2, 'Contenu'), + t { '', '```]' }, + }), }, c = { s('main', { @@ -119,4 +134,92 @@ return { t { '', 'int foo(int x); /* An example function declaration */', '', '#endif' }, }), }, + bib = { + s('online', { + t { '@online{' }, + i(1, 'citekey'), + t { ',', '\tauthor = {' }, + i(2, 'Author Name'), + t { '},' }, + t { '', '\ttitle = {' }, + i(3, 'Title of Webpage'), + t { '},' }, + t { '', '\turl = {' }, + i(4, 'https://example.com'), + t { '},' }, + t { '', '\turldate = {' }, + i(5, '2025-01-08'), + t { '}', '}' }, + }), + }, + js = { + s('func', { + t { 'function ' }, + i(1, 'functionName'), + t '() {', + t { '', ' ' }, + i(2, '// code'), + t { '', '}' }, + }), + + -- If statement snippet + s('if', { + t { 'if (' }, + i(1, 'condition'), + t ') {', + t { '', ' ' }, + i(2, '// code'), + t { '', '}' }, + }), + + -- For loop snippet + s('for', { + t { 'for (let ' }, + i(1, 'i'), + t ' = ', + i(2, '0'), + t '; ', + i(3, 'i'), + t ' < ', + i(4, '10'), + t '; ', + i(5, 'i'), + t '++) {', + t { '', ' ' }, + i(6, '// code'), + t { '', '}' }, + }), + + -- While loop snippet + s('while', { + t { 'while (' }, + i(1, 'condition'), + t ') {', + t { '', ' ' }, + i(2, '// code'), + t { '', '}' }, + }), + + -- Foreach snippet + s('foreach', { + i(1, 'array'), + t '.forEach(', + i(2, 'element'), + t ' => {', + t { '', ' ' }, + i(3, '// code'), + t { '', '});' }, + }), + s('javadoc', { + t { '/**', ' * ' }, + i(1, 'Description...'), + t { '', ' * ', ' * @param ' }, + i(2, 'paramName'), + t ' ', + i(3, 'description of parameter'), + t { '', ' * @return ' }, + i(4, 'description of return value'), + t { '', ' */' }, + }), + }, }