Added luasnip snippets, enabled completion, go, org, rust, all snippets

- url for vim snippets is: https://github.com/honza/vim-snippets
This commit is contained in:
2024-09-20 11:58:51 +02:00
parent 0b3ea1098a
commit d95dc4442c
5 changed files with 686 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ require("lazy").setup({
"hrsh7th/cmp-buffer", -- buffer auto-completion
"hrsh7th/cmp-path", -- path auto-completion
"hrsh7th/cmp-cmdline", -- cmdline auto-completion
"saadparwaiz1/cmp_luasnip", -- luasnip auto-completion
},
config = function()
require("config.nvim-cmp")
@@ -37,6 +38,9 @@ require("lazy").setup({
{
"L3MON4D3/LuaSnip",
version = "v2.*",
config = function()
require("luasnip.loaders.from_snipmate").lazy_load()
end,
},
-- LSP manager

11
snippets/all.snippets Normal file
View File

@@ -0,0 +1,11 @@
# ccflow local snippets for all modes
snippet todo "Add a TODO marker"
// TODO.`strftime("%Y-%m-%d")`
snippet note "Add a NOTE marker"
// NOTE.`strftime("%Y-%m-%d")`
snippet lorem
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

280
snippets/go.snippets Normal file
View File

@@ -0,0 +1,280 @@
snippet v "shorthand variable declaration"
${1} := ${2}
snippet vr "variable initialization"
var ${1:t} ${0:string}
snippet var "variable declaration"
var ${1} ${2} = ${3}
snippet vars "variables declaration"
var (
${1} ${2} = ${3}
)
snippet ap "append"
append(${1:slice}, ${0:value})
snippet bl "bool"
bool
snippet bt "byte"
byte
snippet br "break"
break
snippet ch "channel"
chan ${0:int}
snippet cs "case"
case ${1:value}:
${0:${VISUAL}}
snippet co "constants with iota"
const (
${1:NAME1} = iota
${0:NAME2}
)
snippet cn "continue"
continue
snippet df "defer"
defer ${0:func}()
snippet dfr "defer recover"
defer func() {
if err := recover(); err != nil {
${0:${VISUAL}}
}
}()
snippet im "import"
import (
"${1:package}"
)
snippet in "interface"
interface{}
snippet inf "full interface "
type ${1:name} interface {
${2:/* methods */}
}
snippet if "if condition"
if $1 {
${2:${VISUAL}}
}
snippet ife "if else condition"
if $1 {
${2:${VISUAL}}
} else {
${0}
}
snippet el "else"
else {
${0:${VISUAL}}
}
snippet ir "if error not nil, return err"
if err != nil {
return err
}
${0}
snippet f "false"
false
snippet ft "fallthrough"
fallthrough
snippet fl "float"
float32
snippet f3 "float32"
float32
snippet f6 "float64"
float64
snippet for "for loop"
for ${1}{
${0:${VISUAL}}
}
snippet fori "for int loop"
for ${2:i} := 0; $2 < ${1:count}; $2${3:++} {
${0:${VISUAL}}
}
snippet forr "for range loop"
for ${1:e} := range ${2:collection} {
${0:${VISUAL}}
}
snippet fun "function"
func ${1:funcName}(${2}) ${3:error} {
${4}
}
${0}
snippet fum "method"
func (${1:receiver} ${2:type}) ${3:funcName}(${4}) ${5:error} {
${6}
}
${0}
snippet fumh "http handler function on receiver"
func (${1:receiver} ${2:type}) ${3:funcName}(${4:w} http.ResponseWriter, ${5:r} *http.Request) {
${0:${VISUAL}}
}
snippet lf "log printf"
log.Printf("%${1:s}", ${2:var})
snippet lp "log println"
log.Println("${1}")
snippet mk "make"
make(${1:[]string}, ${0:0})
snippet mp "map"
map[${1:string}]${0:int}
snippet main "func main()"
func main() {
${1}
}
${0}
snippet nw "new"
new(${0:type})
snippet pa "package"
package ${1:main}
snippet pn "panic"
panic("${0:msg}")
snippet pf "fmt.Printf()"
fmt.Printf("%${1:s}\n", ${2:var})
snippet pl "fmt.Println()"
fmt.Println("${1:s}")
snippet rn "range"
range ${0}
snippet rt "return"
return ${0}
snippet rs "result"
result
snippet sl "select"
select {
case ${1:v1} := <-${2:chan1}
${3}
default:
${0}
}
snippet sr "string"
string
snippet st "struct"
type ${1:name} struct {
${2:/* data */}
}
${0}
snippet sw "switch"
switch ${1:var} {
case ${2:value1}:
${3}
case ${4:value2}:
${5}
default:
${0}
}
snippet ps "fmt.Sprintf"
fmt.Sprintf("%${1:s}", ${2:var})
snippet t "true"
true
snippet g "goroutine named function"
go ${1:funcName}(${0})
snippet ga "goroutine anonymous function"
go func(${1} ${2:type}) {
${3:/* code */}
}(${0})
snippet test "test function"
func Test${1:name}(t *testing.T) {
${0:${VISUAL}}
}
snippet testt "table test function"
func Test${1:name}(t *testing.T) {
tests := []struct {
name string
}{
{
name: "${2:test name}",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
${0:${VISUAL}}
})
}
}
snippet bench "benchmark function"
func Benchmark${1:name}(b *testing.B) {
for i := 0; i < b.N; i++ {
${2}
}
}
${0}
snippet cl "composite literals"
type ${1:name} struct {
${2:attrName} ${3:attrType}
}
snippet om "if key in a map"
if ${1:value}, ok := ${2:map}[${3:key}]; ok == true {
${4:/* code */}
}
snippet gg "Grouped globals with anonymous struct"
var ${1:var} = struct{
${2:name} ${3:type}
}{
$2: ${4:value},
}
snippet ja "Marshalable json alias"
type ${1:parentType}Alias $1
func (p *$1) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct{ *$1Alias }{(*$1Alias)(p)})
}
snippet errwr "Error handling with fmt.Errorf"
if ${1}err != nil {
return fmt.Errorf("${2} %w", err)
}

135
snippets/org.snippets Normal file
View File

@@ -0,0 +1,135 @@
# Org Mode Snippets Imported from (https://github.com/doomemacs/snippets/)
# Imported by ybenel (github.com/m1ndo)
# Begin
snippet begin
#+begin_${1:type} ${2:options}
$0
#+end_$1
# Begin Center
snippet <C
#+begin_center
$0
#+end_center
# Begin Comment
snippet <c
#+begin_comment
$0
#+end_comment
# Begin Example
snippet <e
#+begin_example
$0
#+end_example
# Begin Export Ascii
snippet <a
#+begin_export ascii
$0
#+end_export
# Begin export html
snippet <h
#+begin_export html
$0
#+end_export
# Begin export Latex
snippet <l
#+begin_export latex
$0
#+end_export
# Begin export python
snippet <p
#+begin_export python
$0
#+end_export
# Begin export shell
snippet <s
#+begin_export shell
$0
#+end_export
# dot
snippet dot
#+begin_src dot :file ${1:file}.${2:svg} :results file graphics
$0
#+end_src
# elisp
snippet elisp
#+begin_src emacs-lisp :tangle yes
$0
#+end_src
# Entry
snippet entry
#+begin_html
---
layout: ${1:default}
title: ${2:title}
---
#+end_html
$0
# Begin example
snippet ex
#+begin_example
$0
#+end_example
# Begin export
snippet export
#+begin_export ${1:type}
$0
#+end_export
# Figure
snippet fig
#+caption: ${1:caption}
#+attr_latex: ${2:scale=0.75}
#+name: fig-${3:label}
# Org Header
snippet head
#+title: ${1:untitled document}
#+author: ${2:user-full-name}
#+email: ${3:user-mail-address}
# Image
snippet img
#+attr_html: :alt $2 :align ${3:left} :class img
[[${1:src}]${4:[${5:title}]}]
$0
# Inline
snippet inl
src_${1:language}${2:[${3::exports code}]}{${4:code}}
# Inline source
snippet srci
src_${1:language}[${2:header}]{${0:body}}
# Jupyter
snippet jupyter
#+begin_src jupyter-${1:$$(yas-choose-value '("python" "julia" "R"))}${2: :session $3}${4: :async yes}
$0
#+end_src
# Matrix (latex)
snippet matrix
\left \(
\begin{array}{${1:ccc}}
${2:v1 & v2} \\
$0
\end{array}
\right \)
# Name
snippet name
#+name: $0
# Quote
snippet quote
#+begin_quote
$0
#+end_quote
# Source
snippet src
#+begin_src $1
$0
#+end_src
# Todo
snippet todo
TODO ${1:task description}
# Verse
snippet verse
#+begin_verse
$0
#+end_verse
# Atrribute Width
snippet #+attr_html:width
#+attr_html: :width ${1:500px}

252
snippets/rust.snippets Normal file
View File

@@ -0,0 +1,252 @@
#################
# Rust Snippets #
#################
# Functions
snippet fn "Function definition"
fn ${1:function_name}(${2})${3} {
${0}
}
snippet pfn "Function definition"
pub fn ${1:function_name}(${2})${3} {
${0}
}
snippet afn "Async function definition"
async fn ${1:function_name}(${2})${3} {
${0}
}
snippet pafn "Async function definition"
pub async fn ${1:function_name}(${2})${3} {
${0}
}
snippet bench "Bench function" b
#[bench]
fn ${1:bench_function_name}(b: &mut test::Bencher) {
b.iter(|| {
${0}
})
}
snippet new "Constructor function"
pub fn new(${2}) -> ${1:Self} {
$1 { ${3} }
}
snippet main "Main function"
pub fn main() {
${0}
}
snippet let "let variable declaration with type inference"
let ${1} = ${2};
snippet lett "let variable declaration with explicit type annotation"
let ${1}: ${2} = ${3};
snippet letm "let mut variable declaration with type inference"
let mut ${1} = ${2};
snippet lettm "let mut variable declaration with explicit type annotation"
let mut ${1}: ${2} = ${3};
snippet pri "print!"
print!("${1}");
snippet pri, "print! with format param"
print!("${1}{${2}}", ${3});
snippet pln "println!"
println!("${1}");
snippet pln, "println! with format param"
println!("${1}{${2}}", ${3});
snippet fmt "format!"
format!("${1}{${2}}", ${3});
snippet d "dbg! debugging macro"
dbg!(${0:${VISUAL}})
snippet d; "dbg! debugging macro statement"
dbg!(&${1});
${0}
# Modules
snippet ec "extern crate"
extern crate ${1:sync};
snippet ecl "extern crate log"
#[macro_use]
extern crate log;
snippet mod
mod ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
} /* $1 */
# Testing
snippet as "assert!"
assert!(${1:predicate});
snippet ase "assert_eq!"
assert_eq!(${1:expected}, ${2:actual});
snippet test "Unit test function"
#[test]
fn ${1:function_name}_test() {
${0}
}
snippet testmod "Test module" b
#[cfg(test)]
mod tests {
use super::${1:*};
test${0}
}
snippet ig "#[ignore]"
#[ignore]
# Attributes
snippet allow "allow lint attribute" b
#[allow(${1:unused_variables})]
snippet cfg "cfg attribute" b
#[cfg(${1:target_os = "linux"})]
snippet feat "feature attribute" b
#![feature(${1:plugin})]
snippet der "#[derive(..)]" b
#[derive(${1:Debug})]
snippet attr "#[..]" b
#[${1:inline}]
snippet crate "Define create meta attributes"
// Crate name
#![crate_name = "${1:crate_name}"]
// Additional metadata attributes
#![desc = "${2:Description.}"]
#![license = "${3:BSD}"]
#![comment = "${4:Comment.}"]
// Specify the output type
#![crate_type = "${5:lib}"]
# Common types
snippet opt "Option<T>"
Option<${1:i32}>
snippet res "Result<T, E>"
Result<${1:&str}, ${2:()}>
# Control structures
snippet if
if ${1} {
${0:${VISUAL}}
}
snippet ife "if / else"
if ${1} {
${2:${VISUAL}}
} else {
${0}
}
snippet ifl "if let (...)"
if let ${1:Some($2)} = $3 {
${0:${VISUAL}}
}
snippet el "else"
else {
${0:${VISUAL}}
}
snippet eli "else if"
else if ${1} {
${0:${VISUAL}}
}
snippet mat "match pattern"
match ${1} {
${2} => ${3}
}
snippet case "Case clause of pattern match"
${1:_} => ${2:expression}
snippet = "=> "
=> $0
snippet loop "loop {}" b
loop {
${0:${VISUAL}}
}
snippet wh "while loop"
while $1 {
${0:${VISUAL}}
}
snippet whl "while let (...)"
while let ${1:Some($2)} = $3 {
${0:${VISUAL}}
}
snippet for "for ... in ... loop"
for ${1:i} in ${2} {
${0}
}
# TODO commenting
snippet todo "TODO comment"
// TODO: $0
snippet fixme "FIXME comment"
// FIXME: $0
# Struct
snippet st "Struct definition"
struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
}
snippet impl "Struct/Trait implementation"
impl ${1:Type/Trait}${2: for $3} {
${0}
}
snippet stn "Struct with new constructor"
pub struct ${1:`substitute(vim_snippets#Filename(), '\(_\|^\)\(.\)', '\u\2', 'g')`} {
${0}
}
impl$2 $1$2 {
pub fn new(${4}) -> Self {
$1 { ${5} }
}
}
snippet ty "Type alias"
type ${1:NewName} = $2;
snippet enum "enum definition"
enum ${1:Name} {
${2},
}
snippet penum "pub enum definition"
pub enum ${1:Name} {
${2},
}
# Traits
snippet trait "Trait definition"
trait ${1:Name} {
${0}
}
snippet drop "Drop trait implementation (destructor)"
impl Drop for $1 {
fn drop(&mut self) {
${0}
}
}
# Statics
snippet ss "static string declaration"
static ${1}: &'static str = "${0}";
snippet stat "static item declaration"
static ${1}: ${2:usize} = ${0};
# Concurrency
snippet spawn "spawn a thread"
thread::spawn(${1:move }|| {
${0}
});
snippet chan "Declare (Sender, Receiver) pair of asynchronous channel()"
let (${1:tx}, ${2:rx}): (Sender<${3:i32}>, Receiver<${4:i32}>) = channel();
# Implementations
snippet asref "AsRef trait implementation"
impl AsRef<${1:Ref}> for ${2:Type} {
fn as_ref(&self) -> &${3:$1} {
&self.${0:field}
}
}
snippet asmut "AsMut trait implementation"
impl AsMut<${1:Ref}> for ${2:Type} {
fn as_mut(&mut self) -> &mut ${3:$1} {
&mut self.${0:field}
}
}
snippet fd "Struct field definition" w
${1:name}: ${2:Type},
snippet || "Closure, anonymous function (inline)" i
${1:move }|$2| { $3 }
snippet |} "Closure, anonymous function (block)" i
${1:move }|$2| {
$3
}
snippet macro "macro_rules!" b
macro_rules! ${1:name} {
(${2:matcher}) => (
$3
)
}
snippet boxp "Box::new()"
Box::new(${0:${VISUAL}})
snippet rc "Rc::new()"
Rc::new(${0:${VISUAL}})
snippet unim "unimplemented!()"
unimplemented!()
snippet use "use ...;" b
use ${1:std::$2};