This is a neovim plugin to help refactoring code when using snippets/partials.
Visual select some code that you want to extract into a partial or snippet.
Type :Extract then enter path/to/snippets/file.extension
- The selected code gets extracted to that file.
- If the file extension is found in templates the code gets substituted by the replacement with the path
- optional the path gets cut if any string in
extract_dirsis found. ex. if the entered path issnippets/mysnippet.phpthe replacement is<?php snippet('mysnippet') ?>
You can add or modify the given templates.
Default setup:
templates = {
css = {
replacement = "@import '##path##.css';",
extract_dirs = {
'css',
'stylesheets',
},
},
php = {
replacement = "<?php snippet('##path##') ?>",
extract_dirs = {
'snippets',
},
},
lua = {
replacement = "require('##path##')"
}
}{
'caplod/extract.vim',
}Setup a key mapping like this:
vim.keymap.set('v', '<leader>x', ":Extract<cr>", { desc = "extract to partial" })