From 0dbcf730bf0eebeb4142ff2a7136cd436242460b Mon Sep 17 00:00:00 2001 From: iGor milhit Date: Fri, 9 Jun 2023 13:00:41 +0200 Subject: [PATCH] snippets: load my own, add markdown snippets - Renames the snippets folder to my_snippets. - Loads my snippets. - Creates two snippet example available for all filetypes. - Creates three snippets for markdown filetype. - Adds the telescope luasnip plugin. - Sets a keymaping to fuzzy search all available snippets (ss). - Adds a snippet to create a link in markdown reference syntax. - Adds a frontmatter snippet for my incremental notes (journal). - Replace the fronmatter snippet for markdown with a formatted one, easier to read. - Improves the description of my markdown snippets. - Enables the search highlighting. - Removes unnecessary lualine separator. - Renames the neo-tree plugin file. - Lazy loads the zen-mode for markdown files. Co-Authored-by: iGor milhit --- init.lua | 13 +- .../plugins/{filetree.lua => neo-tree.lua} | 3 +- lua/custom/plugins/zen-mode.lua | 4 + {snippets => my_snippets}/boilerplate.html | 0 my_snippets/markdown.lua | 119 ++++++++++++++++++ {snippets => my_snippets}/template.md | 0 spell/en.utf-8.add | 4 + spell/en.utf-8.add.spl | Bin 58 -> 105 bytes 8 files changed, 139 insertions(+), 4 deletions(-) rename lua/custom/plugins/{filetree.lua => neo-tree.lua} (82%) rename {snippets => my_snippets}/boilerplate.html (100%) create mode 100644 my_snippets/markdown.lua rename {snippets => my_snippets}/template.md (100%) diff --git a/init.lua b/init.lua index e43be48..3403eaa 100644 --- a/init.lua +++ b/init.lua @@ -160,7 +160,7 @@ require('lazy').setup({ icons_enabled = true, theme = 'nord', component_separators = '|', - section_separators = '/', + section_separators = '', }, }, }, @@ -195,6 +195,8 @@ require('lazy').setup({ end, }, + { 'benfowler/telescope-luasnip.nvim' }, + { -- Highlight, edit, and navigate code 'nvim-treesitter/nvim-treesitter', @@ -227,7 +229,7 @@ vim.opt.rtp:append (vim.fn.stdpath ('data') .. '/site') -- NOTE: You can change these options as you wish! -- Set highlight on search -vim.o.hlsearch = false +vim.o.hlsearch = true -- Make line numbers default vim.wo.number = true @@ -320,6 +322,7 @@ require('telescope').setup { -- Enable telescope fzf native, if installed pcall(require('telescope').load_extension, 'fzf') +pcall(require('telescope').load_extension, 'luasnip') -- See `:help telescope.builtin` vim.keymap.set('n', '?', require('telescope.builtin').oldfiles, { desc = '[?] Find recently opened files' }) @@ -339,6 +342,7 @@ vim.keymap.set('n', 'sw', require('telescope.builtin').grep_string, { de vim.keymap.set('n', 'sg', require('telescope.builtin').live_grep, { desc = '[S]earch by [G]rep' }) vim.keymap.set('n', 'sd', require('telescope.builtin').diagnostics, { desc = '[S]earch [D]iagnostics' }) vim.keymap.set('n', 'sb', require('telescope.builtin').buffers, { desc = '[S]earch [B]uffers' }) +vim.keymap.set('n', 'ss', require'telescope'.extensions.luasnip.luasnip , { desc = '[S]earch [S]nippets' }) -- [[ Configure Treesitter ]] -- See `:help nvim-treesitter` @@ -519,9 +523,12 @@ luasnip.config.setup { snippets = { markdown = {}, }, - luasnip.filetype_extend("pandoc", {"markdown"}) + luasnip.filetype_extend("pandoc", {"markdown"}), } +-- Load snippets from ~/.config/nvim/LuaSnip/ +require("luasnip.loaders.from_lua").load({paths = "~/.config/nvim/my_snippets/"}) + cmp.setup { snippet = { expand = function(args) diff --git a/lua/custom/plugins/filetree.lua b/lua/custom/plugins/neo-tree.lua similarity index 82% rename from lua/custom/plugins/filetree.lua rename to lua/custom/plugins/neo-tree.lua index 471e19b..d26c0bd 100644 --- a/lua/custom/plugins/filetree.lua +++ b/lua/custom/plugins/neo-tree.lua @@ -1,4 +1,5 @@ --- Trying to add a custom plugin for file tree +-- Plugin for file tree: neo-tree +-- Using the kickstart and the neo-tree documentations -- Unless you are still migrating, remove the deprecated commands from v1.x vim.cmd([[ let g:neo_tree_remove_legacy_commands = 1 ]]) diff --git a/lua/custom/plugins/zen-mode.lua b/lua/custom/plugins/zen-mode.lua index 6ca6d4c..868ba43 100644 --- a/lua/custom/plugins/zen-mode.lua +++ b/lua/custom/plugins/zen-mode.lua @@ -3,6 +3,10 @@ return { "folke/zen-mode.nvim", + ft = { + "markdown", + "pandoc" + }, -- Twilight allows to dim text outside of the cursor line. dependencies = { "folke/twilight.nvim", diff --git a/snippets/boilerplate.html b/my_snippets/boilerplate.html similarity index 100% rename from snippets/boilerplate.html rename to my_snippets/boilerplate.html diff --git a/my_snippets/markdown.lua b/my_snippets/markdown.lua new file mode 100644 index 0000000..231450b --- /dev/null +++ b/my_snippets/markdown.lua @@ -0,0 +1,119 @@ +local ls = require("luasnip") +local s = ls.snippet +local t = ls.text_node +local i = ls.insert_node +local f = ls.function_node +local fmt = require("luasnip.extras.fmt").fmt + +-- Function to get the datetime +-- with daylight saving time +-- according to the locale +local get_date = function() + return os.date("%Y-%m-%dT%H:%M:%S%z") +end + +local get_month = function() + return os.date("%B") +end + +local get_month_year = function() + return os.date("%B-%Y") +end + +-- Function to get an id based on the datetime +local get_id = function() + return os.date("%Y%m%d%H%M%S") +end + +return { + s( + { + trig = "datetime", + name = "Datetime", + dscr = "Insert datetime with locale daylight saving" + }, + { + f(get_date, {}) + } + ), + s( + { + trig = "id", + Name = "ID", + dscr = "Insert an id based on the datetime" + }, + { + f(get_id, {}) + } + ), + s( + { + trig = "fm", + name = "YAML frontmatter", + dscr = "Insert a YAML frontmatter for markdown files.\n\nIt has a datetime with the locale daylight saving time, and an ID based on the datetime.\nTab to jump to next text input." + }, + fmt( + [[ + --- + title: {1} + date: {3} + id: {4} + tags: [{2}] + --- + + ]], + { + i(1, "title"), + i(2, "tags"), + f(get_date, {}), + f(get_id, {}) + } + ) + ), + s( + { + trig = "inc", + name = "INC YAML frontmatter", + dscr = "Insert a YAML frontmatter for INC notes.\n\nIt has a datetime with the locale daylight saving time, prefilled title, author, categories and tags.\nAdjust the title manually." + }, + fmt( + [[ + --- + title: {1} + creation_date: {2} + author: iGor milhit + categories: [inc] + tags: [notes, quotidien, {3}] + --- + + ]], + { + f(get_month_year, {}), + f(get_date, {}), + f(get_month, {}) + } + ) + ), + s( + { + trig="reflink", + name = "Reference link", + dscr="Insert a link with reference syntax", + docstring = "[Link text][Reference]\n\n[Reference]: Link Target \"Title\"\n\nTab to jump to next text input. \"Reference\" is automatically repeated." + }, + fmt( + [[ + [{1}][{2}] + + [{2}]: {3} "{4}" + ]], + { + i(1, "Link text"), + i(2, "Reference"), + i(3, "Link target"), + i(4, "Title") + }, + { repeat_duplicates = true } + ) + ) +} diff --git a/snippets/template.md b/my_snippets/template.md similarity index 100% rename from snippets/template.md rename to my_snippets/template.md diff --git a/spell/en.utf-8.add b/spell/en.utf-8.add index f283b05..796fdcb 100644 --- a/spell/en.utf-8.add +++ b/spell/en.utf-8.add @@ -1,2 +1,6 @@ AoU Floriane +Séverine +HEG +neovim +lua diff --git a/spell/en.utf-8.add.spl b/spell/en.utf-8.add.spl index 5405ebaeed291dfea285da903f99b5f77517c665..99ecb19774e8c686bd4640e5a4716165ffa5e936 100644 GIT binary patch delta 88 zcmcD@6biG{J0F_Do0$jN6cW6We^ hWMELwWjxHd639zsECTVxGl4oe7#)EsLV;Wm005++5cvQA literal 58 zcmWIZ^erw(&B-zP&%nSS$&{GJn9o?s$kf1?17s92W-=x+<}s!+GBE+AIT#&*f}xB+ HCJ+Dsm7EHY