Skip to content

doganalper/template.nvim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Filetype Based Template Plugin For Neovim

template-plugin

Installation

Using lazy.nvim

-- init.lua:
{
  'doganalper/template.nvim', 
  config = function()
    require("template").setup({
      -- custom config
    })
  end

}

Defaults

{
  mappings = {
    switch_template = "<leader>st",
  },
  templates = {
    [filetype] = {
      name = "<name of the template to be displayed on selector>",
      template = {
        "template lines"
      }
    }
  },
}

Customization

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 = {}
})

Example 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>",
      },
    },
  },
},

Default Mappings

Mappings Action
<leader>st [S]witch [T]emplate
]m Jump To Next Marker
[m Jump To Prev Marker

File Variables

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.

Jump Markers

You can place pipe | to mark a place on template to jump to that location with default or user given mapping.

TODO List

  • Add switching places with <Tab> and <S-Tab>.
  • Find a way to easily add indents to templates.

About

File template plugin based on buffer filetype

Topics

Resources

Stars

Watchers

Forks

Languages