Using lazy.nvim
-- init.lua:
{
'doganalper/template.nvim',
config = function()
require("template").setup({
-- custom config
})
end
}
{
mappings = {
switch_template = "<leader>st",
},
templates = {
[filetype] = {
name = "<name of the template to be displayed on selector>",
template = {
"template lines"
}
}
},
}
require('doganalper/template.nvim').setup({
-- configuration for mappings
mappings = {
-- this will call a function for switching templates
-- if filetype has multiple template
switch_template = "<leader>st",
jump_to_next_marker = "]m",
jump_to_prev_marker = "[m",
},
templates = {}
})
templates = {
vue = {
{
name = "Vue 2 JS",
template = {
"<template>",
"<div>",
"</div>",
"<template>",
"",
"<script>",
"export default {}",
"</script>",
},
},
{
name = "Vue 2 Ts",
template = {
"<template>",
"<div>",
"</div>",
"</template>",
"",
'<script lang="ts">',
"import Vue from 'vue';",
"export default Vue.extend({})",
"</script>",
},
},
{
name = "Vue 3",
template = {
'<script lang="ts" setup></script>',
"",
"<template></template>",
},
},
},
},
Mappings | Action |
---|---|
<leader>st |
[S]witch [T]emplate |
]m |
Jump To Next Marker |
[m |
Jump To Prev Marker |
Currently you can use {F_NAME}
to insert filename and {F_NAME_NO_EXTENSION}
to insert filename without file extensions to your templates. More variables will be implemented depending on usage/request.
You can place pipe |
to mark a place on template to jump to that location with default or user given mapping.
- Add switching places with
<Tab>
and<S-Tab>
. - Find a way to easily add indents to templates.