Code Monkey home page Code Monkey logo

template.nvim's Introduction

Template.nvim

Quickly insert templates into file.

Install

-- with packer

use {'glepnir/template.nvim'}

Options

local temp = require('template')

temp.temp_dir -- template directory
temp.author   -- your name
temp.email    -- email address

Basic Usage

Template Grammer

  • {{_date_}} insert current date

  • {{_cursor_}} set cursor here

  • {{_file_name_}} current file name

  • {{_author_}} author info

  • {{_email_}} email adrress

  • {{_variable_}} variable name

  • {{_upper_file_}} all-caps file name

Define your template

Define a template for a go file. template named main_owner.go in temp.temp_dir .in my local config it to ~/.config/nvim/template

// Copyright {{_date_}} {{_author_}}. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package {{_file_name_}}

func main() {
 {{_cursor_}}
}
  • Work with exist file

if there has a file main.go, and open it input Template <Tab> . select the template main_owner

It will insert template to this file like

// Copyright 2022-07-05 21:05:36 glephunter. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package main

func main() {
 | -- cusror in there
}
  • Work with not exist file

use Template test.go <TAB>, it will create a file named test.go in current path and auto open this file insert template.

  • Work with not exist file and custom variable

a lua template file named nvim_temp.lua, content is

local api,fn = vim.api,vim.fn
local {{_variable_}}

{{_cursor_}}

return {{_variable_}}

use Template test.lua var=template <TAB> then it will auto fill template name nvim_temp if there only has one lua template file.

local api,fn = vim.api,vim.fn
local template

| -- cursor here

return template
  • Work with exist file and custom variable

use Template var=template <TAB>

  • Find all templates

template.nvim use telescope. so you need register template telescope extension to telescope

require("telescope").load_extension('find_template')

Then you can use Telescope find_template to check all templates

Donate

If you'd like to support my work financially, buy me a drink through paypal

Licenese MIT

template.nvim's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.