Advertisement
QinghaoHu

Luasnip

May 9th, 2024
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. local ls = require "luasnip"
  2. local s = ls.snippet
  3. local sn = ls.snippet_node
  4. local isn = ls.indent_snippet_node
  5. local t = ls.text_node
  6. local i = ls.insert_node
  7. local f = ls.function_node
  8. local c = ls.choice_node
  9. local d = ls.dynamic_node
  10. local r = ls.restore_node
  11. local events = require "luasnip.util.events"
  12. local ai = require "luasnip.nodes.absolute_indexer"
  13. local extras = require "luasnip.extras"
  14. local fmt = extras.fmt
  15. local m = extras.m
  16. local l = extras.l
  17. local postfix = require "luasnip.extras.postfix".postfix
  18. local snip = ls.snippet
  19. local text = ls.text_node
  20.  
  21. -- Define the C++ template snippet.
  22.  
  23.  
  24. ls.add_snippets(nil, {
  25. all = {
  26. snip({
  27. trig = "cppimport",
  28. name = "C++ Template",
  29. dscr = "C++ Template with common includes and main function structure.",
  30. }, {
  31. text({ "#include <iostream>" }),
  32. text({ "", "#include <iomanip>" }),
  33. text({ "", "#include <fstream>" }),
  34. text({ "", "#include <sstream>" }),
  35. text({ "", "#include <cstdio>" }),
  36. text({ "", "#include <algorithm>" }),
  37. text({ "", "#include <numeric>" }),
  38. text({ "", "#include <functional>" }),
  39. text({ "", "#include <vector>" }),
  40. text({ "", "#include <array>" }),
  41. text({ "", "#include <list>" }),
  42. text({ "", "#include <deque>" }),
  43. text({ "", "#include <set>" }),
  44. text({ "", "#include <map>" }),
  45. text({ "", "#include <unordered_set>" }),
  46. text({ "", "#include <unordered_map>" }),
  47. text({ "", "#include <queue>" }),
  48. text({ "", "#include <stack>" }),
  49. text({ "", "#include <bitset>" }),
  50. text({ "", "#include <cmath>" }),
  51. text({ "", "#include <cstdlib>" }),
  52. text({ "", "#include <cstring>" }),
  53. text({ "", "#include <cctype>" }),
  54. text({ "", "#include <ctime>" }),
  55. text({ "", "#include <climits>" }),
  56. text({ "", "" }),
  57. text({ "", "using namespace std;" }),
  58. text({ "", "using ll = long long;" }),
  59. text({ "", "" }),
  60. text({ "", "void solve() {" }),
  61. text({ "", "\t" }),
  62. text({ "", "}" }),
  63. text({ "", "" }),
  64. text({ "", "int main() {" }),
  65. text({ "", "\tios::sync_with_stdio(false);" }),
  66. text({ "", "\tcin.tie (nullptr);" }),
  67. text({ "", "" }),
  68. text({ "", "\tint T = 1;" }),
  69. text({ "", "\t//cin >> T;" }),
  70. text({ "", "" }),
  71. text({ "", "\twhile(T --) {" }),
  72. text({ "", "\t\tsolve();" }),
  73. text({ "", "\t}" }),
  74. text({ "", "" }),
  75. text({ "", "\treturn 0;" }),
  76. text({ "", "}" }),
  77. text({ "", "" }),
  78. text({ "", "/* stuff you should look for" }),
  79. text({ "", " * int overflow, array bounds" }),
  80. text({ "", " * special cases (n=1?)" }),
  81. text({ "", " * do smth instead of nothing and stay organized" }),
  82. text({ "", " * WRITE STUFF DOWN" }),
  83. text({ "", " * DON'T GET STUCK ON ONE APPROACH" }),
  84. text({ "", " */" }),
  85. }),
  86. },
  87. })
  88.  
  89. ls.add_snippets(nil, {
  90. all = {
  91. snip({
  92. trig = "constintinf", -- Change trigger to something meaningful, e.g., "cpptemplate".
  93. name = "Infinite", -- Corrected typo: "name" instead of "namr".
  94. dscr = "0x3f3f3f3f", -- Corrected typo: "dscr" instead of "dsc".
  95. }, {
  96. text({ "const int INF = 0x3f3f3f3f;" }),
  97. }),
  98. },
  99. })
  100.  
  101. ls.add_snippets(nil, {
  102. all = {
  103. snip({
  104. trig = "constdoubleeps", -- Change trigger to something meaningful, e.g., "cpptemplate".
  105. name = "EPS", -- Corrected typo: "name" instead of "namr".
  106. dscr = "eps=1e-12", -- Corrected typo: "dscr" instead of "dsc".
  107. }, {
  108. text({ "const double eps = 1e-12;" }),
  109. }),
  110. },
  111. })
  112.  
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement