diff --git a/TEMPLATES_INTEGRATION.md b/TEMPLATES_INTEGRATION.md index 5605f4a..c95b412 100644 --- a/TEMPLATES_INTEGRATION.md +++ b/TEMPLATES_INTEGRATION.md @@ -11,8 +11,16 @@ Integrated template.nvim with custom Snacks picker for quick code scaffolding ac ## ⚡ Quick Start -### Open Template Picker -Press `` or run `:TemplateSnacks` +### Keybindings +- **``** - Open Snacks template picker (primary) +- **`t`** - Create a new template file +- **`T`** - Open Telescope template picker (alternative) + +### Commands +- `:TemplateSnacks` - Open Snacks picker for templates +- `:TemplateCreate [filetype]` - Create new template +- `:TemplateTelescope [type=insert|name=template] [filter_ft=true|false]` - Telescope picker +- `:Template ` - Use native template.nvim command ### Usage Flow 1. Press `` to open picker @@ -33,11 +41,13 @@ Features: - ✅ Custom template markers - ✅ Interactive variable prompts -### Keybinding +### Keybindings Location: `/home/prad/.config/nvim/lua/plugins/astrocore.lua` ```lua [""] = { "TemplateSnacks", desc = "Open template picker" } +["t"] = { function() vim.fn.feedkeys(":TemplateCreate ") end, desc = "Create new template" } +["T"] = { "TemplateTelescope type=insert", desc = "Template picker (Telescope)" } ``` ## 📁 Template Structure @@ -74,6 +84,12 @@ Location: `/home/prad/.config/nvim/lua/plugins/astrocore.lua` - `{{_email_}}` → `prad@sonr.io` - `{{_cursor_}}` → Cursor position after insertion +### Custom Registered Variables (New!) +- `{{_path_}}` → `/full/path/to/current/file.go` +- `{{_relative_path_}}` → `src/services/file.go` +- `{{_dir_}}` → `/full/path/to/current` +- `{{_project_}}` → `nvim` (current directory name) + ### Interactive Variables - `{{_variable_}}` → Prompts for custom input - `{{_lua:_}}` → Execute Lua code @@ -331,6 +347,18 @@ function DashboardPage() { ### Adding New Templates +#### Quick Method (Recommended) +1. Press `t` to start TemplateCreate command +2. Type category and filename: `vite/form.tsx` or `cosmos/store.go` +3. Optional: specify filetype as second argument (defaults to current buffer's filetype) +4. Template file is created with filetype marker and opens automatically + +Example: +```vim +:TemplateCreate vite/form.tsx typescriptreact +``` + +#### Manual Method 1. **Create template file** in templates directory: ```bash nvim ~/.config/nvim/templates/vite/form.tsx.tpl @@ -362,11 +390,26 @@ export function {{_camel_case_file_}}Form() { ### Modifying Configuration Edit `lua/plugins/template.lua` to change: -- Author name -- Email address -- Template directory +- Author name and email +- Template directory location - Custom variable processors +#### Adding Custom Variables +```lua +-- In lua/plugins/template.lua, add after setup: +template.register("{{_custom_var_}}", function() + return "your value here" +end) +``` + +Example: +```lua +-- Add project root detection +template.register("{{_git_root_}}", function() + return vim.fn.systemlist("git rev-parse --show-toplevel")[1] +end) +``` + ## 📊 Template Statistics - **Total Templates:** 14 @@ -391,11 +434,14 @@ Edit `lua/plugins/template.lua` to change: ## 🔥 Pro Tips -1. **Filetype Filtering:** Templates auto-filter by current filetype -2. **Variable Naming:** Use descriptive names for `{{_variable_}}` -3. **Nested Directories:** Organize templates in subdirectories -4. **Custom Markers:** Add your own `{{_custom_}}` variables +1. **Filetype Filtering:** Templates auto-filter by current filetype in Snacks picker +2. **Variable Naming:** Use descriptive names for `{{_variable_}}` prompts +3. **Nested Directories:** Organize templates in subdirectories (shown as `[category] filename`) +4. **Custom Markers:** Register your own variables with `template.register()` 5. **Lua Expressions:** Use `{{_lua:vim.fn.getcwd()_}}` for dynamic content +6. **Quick Template Creation:** Use `t` to quickly create new templates with auto-completion +7. **Telescope Alternative:** Use `T` for Telescope picker with Snacks backend +8. **Path Variables:** Use new `{{_path_}}`, `{{_relative_path_}}`, `{{_dir_}}`, `{{_project_}}` variables --- diff --git a/lazy-lock.json b/lazy-lock.json index 349453c..08b43ee 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -59,7 +59,7 @@ "nvim-vtsls": { "branch": "main", "commit": "0b5f73c9e50ce95842ea07bb3f05c7d66d87d14a" }, "nvim-web-devicons": { "branch": "master", "commit": "4c3a5848ee0b09ecdea73adcd2a689190aeb728c" }, "nvim-window-picker": { "branch": "main", "commit": "6382540b2ae5de6c793d4aa2e3fe6dbb518505ec" }, - "octo.nvim": { "branch": "master", "commit": "c17e5625df97d08940d6e66865d08b5945ad127d" }, + "octo.nvim": { "branch": "master", "commit": "f6ecb853217c3e82fe1d324c35012d3bcf655166" }, "overseer.nvim": { "branch": "master", "commit": "c77c78b35d0b4d244e1cd77c25ec93a16fbbfc94" }, "package-info.nvim": { "branch": "master", "commit": "a1de9eb91fa52ab8361f0c05032673670a3d10ff" }, "plenary.nvim": { "branch": "master", "commit": "857c5ac632080dba10aae49dba902ce3abf91b35" }, @@ -67,7 +67,7 @@ "resession.nvim": { "branch": "master", "commit": "cc819b0489938d03e4f3532a583354f0287c015b" }, "schemastore.nvim": { "branch": "main", "commit": "54994d58c2bc9260908a6c59e8698e9629098389" }, "smart-splits.nvim": { "branch": "master", "commit": "ddb23c1a1cf1507bda487cda7f6e4690965ef9f5" }, - "snacks.nvim": { "branch": "main", "commit": "8625e4bd72f624ea0daaf44dc53a0ce5a2b9ad9d" }, + "snacks.nvim": { "branch": "main", "commit": "277ba028b3b764ee49c9be8fd4d1282aff86812a" }, "supermaven-nvim": { "branch": "main", "commit": "07d20fce48a5629686aefb0a7cd4b25e33947d50" }, "telescope-fzf-native.nvim": { "branch": "main", "commit": "1f08ed60cafc8f6168b72b80be2b2ea149813e55" }, "telescope.nvim": { "branch": "master", "commit": "a17d611a0e111836a1db5295f04945df407c5135" },