1 个不稳定版本
0.1.0 | 2023 年 12 月 18 日 |
---|
#2143 in 命令行工具
47KB
925 行
A CLI (snipr) Tool for Managing Neovim and VSCode Snippets
注意:这是与我的 Neovide Neovim rust 设置一起使用的额外工具。
VSCode Snippet 兼容
安装
- 您可以在发布页面下载并安装 snipr 注意:在 MacOS 上,您可能需要转到系统偏好设置 > 安全与隐私 > 一般,然后点击“仍要打开”来安装它
注意:在 Windows 上,您可能需要将命令添加到环境变量 PATH 中
或使用 Cargo 安装它
cargo install snipr
- 从源码构建
克隆
git clone htps://github.com/codeitlikemiley/snipr.git
cd snipr
对于 MacOS
./provision.sh
对于 Linux
cargo build --release
mv ./target/release/snipr /usr/local/bin/snipr
chmod +x /usr/local/bin/snipr
对于 Windows
cargo build --release
# Replace 'YourUsername' with your actual username
Move-Item .\target\release\snipr.exe C:\Users\YourUsername\bin\snipr.exe
# Again, replace 'YourUsername' with your actual username
$env:Path += ";C:\Users\YourUsername\bin"
管理不同语言的多个 Snippets 文件
您可以使用命令 snipr config <path>
在运行时更改 Snippets 文件。
注意:这当您想管理不同语言的 Snippets 文件时非常有用。
配置路径位置
默认配置路径 DEFAULT_CONFIG_PATH
是 ~/.config/nvim/snippets/rust/rust.json
,在 src/constants.rs
中设置,并在构建过程中使用,
但您可以通过设置环境变量 SNIP_CONFIG_PATH
来更改它。
使用方法
- 帮助
snipr
# or
snipr --help
输出
snipr
/Users/uriah/.config/nvim/snippets/rust/rust.json
A CLI tool for managing Neovim LuaSnip Rust snippets
Usage: snipr <COMMAND>
Commands:
add Adds entry to Snippet Collection file
rm Removes entry from Snippet Collection file
edit Edits entry in Snippet Collection file
ls Lists all entries in Snippet Collection file
show Gets entry from Snippet Collection file
search Searches for entries in Snippet Collection file
config Configures the Snippet Collection file
update-key
help Print this message or the help of the given subcommand(s)
Options:
-h, --help Print help
-V, --version Print version
- 添加新片段
# help
snipr add --help
# Add Snippet
snipr add --key <key> --value <value> --description <description> -- "<snippet>"
- 删除片段
# help
snipr remove --help
# Remove Snippet
snipr remove --key <key>
- 列出所有片段
# help
snipr ls --help
# Usage
snipr ls <LIST_OPTION | (key or prefix)>
# List all Keys
snipr ls key
# List all Prefixes
snipr ls prefix
输出
snipr ls key
/Users/uriah/.config/nvim/snippets/rust/rust.json
[src/main.rs:468] list_option = Key
impl_iterator
serialize_to_json_string
impl_add_trait
impl_vec_iterator
unwrap_or_else
impl_deref
impl_debug_single_field
deserialize_json_string
impl_display_single_field
import_serde_traits
impl_clone_single_field
- 更新键
# help
snipr update-key --help
# Update Key
snipr update-key --old-key <old-key> --new-key <new-key>
输出
snipr update-key --old-key "Fuzz match String" --new-key "fuzzy-match-string"
/Users/uriah/.config/nvim/snippets/rust/rust.json
[src/main.rs:499] &old_key = "Fuzz match String"
[src/main.rs:499] &new_key = "fuzzy-match-string"
- 更新片段
# help
snipr edit --help
# Update snippet Value
snipr edit --key <key> --prefix <prefix> --description <description> -- "<snippet>"
- 搜索片段
# help
snipr search --help
# Search Snippet
snipr search <ID | (key or prefix)> -- "<search_term>"
输出
snipr search key -- impl
/Users/uriah/.config/nvim/snippets/rust/rust.json
[src/main.rs:490] id = Some(
Key,
)
[src/main.rs:490] &name = "impl"
impl_deref
impl_clone_single_field
impl_iter_range
impl_partialeq_single_field
- 显示片段
# help
snipr show --help
# Show Snippet
snipr show <key_id>
输出
snipr show impl_deref
/Users/uriah/.config/nvim/snippets/rust/rust.json
[src/main.rs:484] &key = "impl_deref"
+-------------+-------------------------------------------------------------+
| Key | impl_deref |
+-------------+-------------------------------------------------------------+
| Prefix | impl_deref |
+-------------+-------------------------------------------------------------+
| Description | Impl Deref and DerefMut traits for a custom type |
+-------------+-------------------------------------------------------------+
| Body | use std::ops::{Deref, DerefMut}; |
| | |
| | impl<${1:T}> Deref for ${2:YourConcreteStruct}<${1:T}> { |
| | type Target = ${1:T}; |
| | fn deref(&self) -> &Self::Target { |
| | &self.${3:your_field} |
| | } |
| | } |
| | |
| | impl<${1:T}> DerefMut for ${2:YourConcreteStruct}<${1:T}> { |
| | fn deref_mut(&mut self) -> &mut Self::Target { |
| | &mut self.${3:your_field} |
| | } |
| | } |
+-------------+-------------------------------------------------------------+
- 配置片段 注意:这可以用来切换配置,例如,如果您想管理 Python 片段,您只需传入配置文件的路径。
# help
snipr config --help
# Config Snippet
snipr config <path>
依赖项
~8–19MB
~237K SLoC