|
| 1 | +# LuaSnip Snippets |
| 2 | + |
| 3 | +A collection of snippets for various programming language. Some snippets are |
| 4 | +highly inspired by Jetbrain's IDEs. |
| 5 | + |
| 6 | +## Installation |
| 7 | + |
| 8 | +```lua |
| 9 | +{ |
| 10 | + "TwIStOy/luasnip-snippets", |
| 11 | + dependencies = { "L3MON4D3/LuaSnip" }, |
| 12 | + event = { "InsertEnter" }, |
| 13 | + config = function() |
| 14 | + -- register all snippets into LuaSnip |
| 15 | + require("luasnip-snippets").setup() |
| 16 | + end |
| 17 | +} |
| 18 | +``` |
| 19 | + |
| 20 | +`autosnippet` feature should be enabled in `LuaSnip`. |
| 21 | + |
| 22 | +```lua |
| 23 | +local ls = require('luasnip') |
| 24 | +ls.setup({ |
| 25 | + enable_autosnippets = true, |
| 26 | +}) |
| 27 | +``` |
| 28 | + |
| 29 | +## Snippets |
| 30 | + |
| 31 | +Snippets which trigger ends with "!" are `autosnippet`. |
| 32 | + |
| 33 | +<details> |
| 34 | +<summary>Cpp</summary> |
| 35 | + |
| 36 | +#### Normal Snippets |
| 37 | + |
| 38 | +| Trig | Desc | Context | |
| 39 | +|:-------:|--------------------------------------------------------------------------------------------------|:--------:| |
| 40 | +| `ctor!` | Expand to default constructor | In Class | |
| 41 | +| `dtor!` | Expand to default destructor | In Class | |
| 42 | +| `cc!` | Expand to default copy constructor | In Class | |
| 43 | +| `mv!` | Expand to default move constructor | In Class | |
| 44 | +| `ncc!` | Expand to delete copy constructor | In Class | |
| 45 | +| `nmv!` | Expand to delete move constructor | In Class | |
| 46 | +| `ncm!` | Expand to delete copy and move constructor | In Class | |
| 47 | +| `fn` | Expand to lambda function in argument list or function body, otherwise expand to normal function | All | |
| 48 | + |
| 49 | +#### Postfix Snippets |
| 50 | + |
| 51 | +```scheme |
| 52 | +[ |
| 53 | + (identifier) |
| 54 | + (field_identifier) |
| 55 | +] @indent |
| 56 | +
|
| 57 | +[ |
| 58 | + (call_expression) |
| 59 | + (identifier) |
| 60 | + (template_function) |
| 61 | + (subscript_expression) |
| 62 | + (field_expression) |
| 63 | + (user_defined_literal) |
| 64 | +] @any_expr |
| 65 | +``` |
| 66 | + |
| 67 | +| Trig | Desc (placehoder: `?`) | Expr before cursor | |
| 68 | +|:------:|----------------------------------------------------------------|:------------------:| |
| 69 | +| `.be` | Expand to begin and end exprs | `any_expr` | |
| 70 | +| `.mv` | Wraps with `std::move(?)` | `any_expr` | |
| 71 | +| `.fwd` | Wraps with `std::forward<decltype(?)>(?)` | `any_expr` | |
| 72 | +| `.val` | Wraps with `std::declval<?>()` | `any_expr` | |
| 73 | +| `.dt` | Wraps with `decltype(?)` | `any_expr` | |
| 74 | +| `.uu` | Wraps with `(void)?` | `any_expr` | |
| 75 | +| `.ts` | Switch indent's coding style between CamelCase and snake_case. | `indent` | |
| 76 | +| `.sc` | Wraps with `static_cast<>(?)` | `any_expr` | |
| 77 | + |
| 78 | +</details> |
| 79 | + |
| 80 | +<details> |
| 81 | +<summary>Rust</summary> |
| 82 | + |
| 83 | +#### Postfix Snippets |
| 84 | + |
| 85 | +```scheme |
| 86 | +[ |
| 87 | + (struct_expression) |
| 88 | + (call_expression) |
| 89 | + (identifier) |
| 90 | + (field_expression) |
| 91 | +] @expr |
| 92 | +
|
| 93 | +[ |
| 94 | + (struct_expression) |
| 95 | + (call_expression) |
| 96 | + (identifier) |
| 97 | + (field_expression) |
| 98 | + |
| 99 | + (generic_type) |
| 100 | + (scoped_type_identifier) |
| 101 | + (reference_type) |
| 102 | +] @expr_or_type |
| 103 | +``` |
| 104 | + |
| 105 | +| Trig | Desc (placehoder: `?`) | Expr before cursor | |
| 106 | +|:----------:|------------------------------------------------------------|:------------------:| |
| 107 | +| `.rc` | Wraps with `Rc::new(?)` if expr, `Rc<?>` if type | `expr_or_type` | |
| 108 | +| `.arc` | Wraps with `Arc::new(?)` if expr, `Arc<?>` if type | `expr_or_type` | |
| 109 | +| `.box` | Wraps with `Box::new(?)` if expr, `Box<?>` if type | `expr_or_type` | |
| 110 | +| `.mu` | Wraps with `Mutex::new(?)` if expr, `Mutex<?>` if type | `expr_or_type` | |
| 111 | +| `.rw` | Wraps with `RwLock::new(?)` if expr, `RwLock<?>` if type | `expr_or_type` | |
| 112 | +| `.cell` | Wraps with `Cell::new(?)` if expr, `Cell<?>` if type | `expr_or_type` | |
| 113 | +| `.refcell` | Wraps with `RefCell::new(?)` if expr, `RefCell<?>` if type | `expr_or_type` | |
| 114 | +| `.ref` | Wraps with `&?` | `expr` | |
| 115 | +| `.refm` | Wraps with `&mut ?` | `expr` | |
| 116 | +| `.ok` | Wraps with `Ok(?)` | `expr` | |
| 117 | +| `.err` | Wraps with `Err(?)` | `expr` | |
| 118 | +| `.some` | Wraps with `Some(?)` | `expr` | |
| 119 | +| `.println` | Wraps with `println!("{:?}", ?)` | `expr` | |
| 120 | + |
| 121 | +</details> |
| 122 | + |
0 commit comments