diff options
author | Oxbian <got.dacs@slmail.me> | 2024-06-06 12:38:37 +0200 |
---|---|---|
committer | Oxbian <got.dacs@slmail.me> | 2024-06-06 12:38:37 +0200 |
commit | 375403fff8d45f850e68391cebba20fd77d92e15 (patch) | |
tree | 2915ad4d969fbac6b04e4df706d72c6d5b9b8666 | |
parent | 29f83df862462ec2b6ce7e545bd9e2853a5ee0c3 (diff) | |
download | vimrc-375403fff8d45f850e68391cebba20fd77d92e15.tar.gz vimrc-375403fff8d45f850e68391cebba20fd77d92e15.zip |
ADD: C, C++, PHP snippets
-rw-r--r-- | coc-settings.json | 6 | ||||
-rw-r--r-- | conf/keymaps.vim | 5 | ||||
-rwxr-xr-x | install.sh | 1 | ||||
-rw-r--r-- | snippets/c.json | 319 | ||||
-rw-r--r-- | snippets/cpp.json | 385 | ||||
-rw-r--r-- | snippets/php.json | 50 |
6 files changed, 764 insertions, 2 deletions
diff --git a/coc-settings.json b/coc-settings.json new file mode 100644 index 0000000..211a014 --- /dev/null +++ b/coc-settings.json @@ -0,0 +1,6 @@ +{ + "snippets.userSnippetsDirectory": "~/.config/vim/snippets", + "snippet.statusText": "true", + "snippets.ultisnips.directories": ["~/.config/vim/snippets"], + "snippets.textmateSnippetsRoots": ["~/.config/vim/snippets"] +} diff --git a/conf/keymaps.vim b/conf/keymaps.vim index d68b8c4..afef3ca 100644 --- a/conf/keymaps.vim +++ b/conf/keymaps.vim @@ -153,8 +153,9 @@ inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>" " Make <CR> to accept selected completion item or notify coc.nvim to format " <C-g>u breaks current undo, please make your own choice -inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm() - \: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" +inoremap <silent><expr> <cr> pumvisible() ? coc#_select_confirm() : + \"\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>" +let g:coc_snippet_next = '<tab>' nmap <silent> gp <Plug>(coc-diagnostic-prev) nmap <silent> gn <Plug>(coc-diagnostic-next) @@ -5,3 +5,4 @@ cd "$DIR" || exit rm "$HOME/.vimrc" ln -sf "$(pwd)/.vimrc" "$HOME/.vimrc" rm -rf "$HOME/.vim" +ln -sf "$(pwd)/coc-settings.json" "$HOME/.vim/coc-settings.json" diff --git a/snippets/c.json b/snippets/c.json new file mode 100644 index 0000000..9a4eebe --- /dev/null +++ b/snippets/c.json @@ -0,0 +1,319 @@ +{ + "Basic C main template": { + "scope": "c", + "prefix": "main", + "body": [ + "#include <stdio.h>", + "", + "int main (int argc, char *argv[]) ", + "{", + " $0", + " return 0;", + "}" + ], + "description": "Basic main template in C" + }, + "Basic C stdlib main template": { + "scope": "c", + "prefix": "libmain", + "body": [ + "#include <stdio.h>", + "#include <stdlib.h>", + "", + "int main (int argc, char *argv[]) ", + "{", + " $0", + " return 0;", + "}" + ], + "description": "Basic stdlib main templace in C" + }, + "If statement": { + "scope": "c", + "prefix": "if", + "body": [ + "if ($1) {", + " ${2:/* code here */} ", + "}" + ], + "description": "Creates an if statement" + }, + "Else statement": { + "scope": "c", + "prefix": "else", + "body": [ + "else {", + " ${0:/* code here */}", + "}" + ], + "description": "Creates an else statement" + }, + "Else if statement": { + "scope": "c", + "prefix": "elif", + "body": [ + "else if ($1) {", + " ${2:/* code here */}", + "}" + ], + "description": "Creates an else if statement" + }, + "Switch": { + "scope": "c", + "prefix": "switch", + "body": [ + "switch ($1) ", + "{", + " case $2:", + " $3;", + " break;", + "", + " default:", + " $4;", + " break;", + "}" + ], + "description": "Creates a void function" + }, + "For loop": { + "scope": "c", + "prefix": "for", + "body": [ + "for (int ${1:i} = ${2:0}; ${1:i} < $3; ++${1:i}) {", + " ${4:/* code goes here */}", + "}" + ], + "description": "Creates a for loop" + }, + "Reverse For loop": { + "scope": "c", + "prefix": "forrev", + "body": [ + "for (int ${1:i} = $2; ${1:i} >= ${3:0}; --${1:i}) {", + " ${4:/* code goes here */}", + "}" + ], + "description": "Creates a reverse for loop" + }, + "Range For loop": { + "scope": "cpp", + "prefix": "forrange", + "body": [ + "for (auto &${1:element} : ${2:containeur}) {", + " ${3:/* code goes here */}", + "}" + ], + "description": "Creates a range for loop" + }, + "While loop": { + "scope": "c", + "prefix": "while", + "body": [ + "while ($1) {", + " ${2:/* code goes here */}", + "}" + ], + "description": "Creates a while loop" + }, + "Do...while loop": { + "scope": "c", + "prefix": "dowhile", + "body": [ + "do {", + " ${1:/* code goes here */}", + "} while($2)" + ], + "description": "Creates a do...while loop" + }, + "Create linked list": { + "scope": "c", + "prefix": "clist", + "body": [ + "typedef struct {", + " ${1:int} value;", + " struct node_t* next;", + "} node_t;" + ], + "description": "Creates a linked list template" + }, + "Create int function": { + "scope": "c", + "prefix": "intf", + "body": [ + "int $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns an int" + }, + "Create float function": { + "scope": "c", + "prefix": "floatf", + "body": [ + "float $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a float" + }, + "Create double function": { + "scope": "c", + "prefix": "doublef", + "body": [ + "double $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a double" + }, + "Create string function": { + "scope": "c", + "prefix": "strf", + "body": [ + "char* $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a string" + }, + "Create long function": { + "scope": "c", + "prefix": "longf", + "body": [ + "long $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a long" + }, + "Create short function": { + "scope": "c", + "prefix": "shortf", + "body": [ + "short $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a short" + }, + "Create void function": { + "scope": "c", + "prefix": "voidf", + "body": [ + "void $1 (${2:void}) ", + "{", + " $3", + "}" + ], + "description": "Creates a void function" + }, + "Creates a header include guard C": { + "scope": "c", + "prefix": "ig", + "body": [ + "#ifndef ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_H/}", + "#define ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_H/}", + "", + "${0:// Code for header body}", + "", + "#endif // ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_H/}" + ], + "description": "Creates header include guard based on file name for C projets" + }, + "Creates a header include guard C++": { + "scope": "cpp", + "prefix": "ig", + "body": [ + "#ifndef ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}", + "#define ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}", + "", + "${0:// Code for header body}", + "", + "#endif // ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}" + ], + "description": "Creates header include guard based on file name for C++ projects" + }, + "Include": { + "scope": "c", + "prefix": "inc", + "body": [ + "#include <$0>" + ], + "description": "Include a header into a file" + }, + "Malloc": { + "scope": "c", + "prefix": "malloc", + "body": [ + "malloc($1 * sizeof(${2:int}))" + ], + "description": "Arrow for pointers in C & C++" + }, + "fopen": { + "scope": "c", + "prefix": "fopen", + "body": [ + "fopen(\"${1:monfichier}\", \"${2|r,r+,w,w+,a,a+|}\")" + ], + "description": "Open a file" + }, + "define": { + "scope": "c", + "prefix": "define", + "body": [ + "#define $1 $2" + ], + "description": "Define a constant" + }, + "enum": { + "scope": "c", + "prefix": "enum", + "body": [ + "enum $1 {$2, $3}" + ], + "description": "Arrow for pointers in C & C++" + }, + "union": { + "scope": "c", + "prefix": "union", + "body": [ + "union $1 {", + " $2;", + " $3;", + "}" + ], + "description": "Arrow for pointers in C & C++" + }, + "struct": { + "scope": "c", + "prefix": "struct", + "body": [ + "struct $1 {", + "${2:// Code goes here}", + "};" + ], + "description": "Struct in C & C++" + }, + "typedef": { + "scope": "c", + "prefix": "type", + "body": [ + "typedef struct _$1 {", + "${2:// Code goes here}", + "} t_$1;" + ], + "description": "Typedef struct in C & C++" + } +} diff --git a/snippets/cpp.json b/snippets/cpp.json new file mode 100644 index 0000000..aca55d0 --- /dev/null +++ b/snippets/cpp.json @@ -0,0 +1,385 @@ +{ + "Basic C++ main template": { + "scope": "cpp", + "prefix": "main", + "body": [ + "#include <cstdio>", + "", + "int main (int argc, char *argv[]) ", + "{", + " $0", + " return 0;", + "}" + ], + "description": "Basic main template in C++" + }, + "Basic C++ iostream main template": { + "scope": "cpp", + "prefix": "iomain", + "body": [ + "#include <cstdio>", + "#include <iostream>", + "", + "int main (int argc, char *argv[])", + "{", + " $0", + " return 0;", + "}" + ], + "description": "Basic iostream main templace in C++" + }, + "If statement": { + "scope": "c", + "prefix": "if", + "body": [ + "if ($1) {", + " ${2:/* code here */} ", + "}" + ], + "description": "Creates an if statement" + }, + "Else statement": { + "scope": "c", + "prefix": "else", + "body": [ + "else {", + " ${0:/* code here */}", + "}" + ], + "description": "Creates an else statement" + }, + "Else if statement": { + "scope": "c", + "prefix": "elif", + "body": [ + "else if ($1) {", + " ${2:/* code here */}", + "}" + ], + "description": "Creates an else if statement" + }, + "Switch": { + "scope": "c", + "prefix": "switch", + "body": [ + "switch ($1) ", + "{", + " case $2:", + " $3;", + " break;", + "", + " default:", + " $4;", + " break;", + "}" + ], + "description": "Creates a void function" + }, + "For loop": { + "scope": "c", + "prefix": "for", + "body": [ + "for (int ${1:i} = ${2:0}; ${1:i} < $3; ++${1:i}) {", + " ${4:/* code goes here */}", + "}" + ], + "description": "Creates a for loop" + }, + "Reverse For loop": { + "scope": "c", + "prefix": "forrev", + "body": [ + "for (int ${1:i} = $2; ${1:i} >= ${3:0}; --${1:i}) {", + " ${4:/* code goes here */}", + "}" + ], + "description": "Creates a reverse for loop" + }, + "Range For loop": { + "scope": "cpp", + "prefix": "forrange", + "body": [ + "for (auto &${1:element} : ${2:containeur}) {", + " ${3:/* code goes here */}", + "}" + ], + "description": "Creates a range for loop" + }, + "While loop": { + "scope": "c", + "prefix": "while", + "body": [ + "while ($1) {", + " ${2:/* code goes here */}", + "}" + ], + "description": "Creates a while loop" + }, + "Do...while loop": { + "scope": "c", + "prefix": "dowhile", + "body": [ + "do {", + " ${1:/* code goes here */}", + "} while($2)" + ], + "description": "Creates a do...while loop" + }, + "Create linked list": { + "scope": "c", + "prefix": "clist", + "body": [ + "typedef struct {", + " ${1:int} value;", + " struct node_t* next;", + "} node_t;" + ], + "description": "Creates a linked list template" + }, + "Create int function": { + "scope": "c", + "prefix": "intf", + "body": [ + "int $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns an int" + }, + "Create float function": { + "scope": "c", + "prefix": "floatf", + "body": [ + "float $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a float" + }, + "Create double function": { + "scope": "c", + "prefix": "doublef", + "body": [ + "double $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a double" + }, + "Create string function": { + "scope": "c", + "prefix": "strf", + "body": [ + "char* $1 (${2:void})", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a string" + }, + "Create long function": { + "scope": "c", + "prefix": "longf", + "body": [ + "long $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a long" + }, + "Create short function": { + "scope": "c", + "prefix": "shortf", + "body": [ + "short $1 (${2:void}) ", + "{", + " $4", + " return $3;", + "}" + ], + "description": "Creates a function that returns a short" + }, + "Create void function": { + "scope": "c", + "prefix": "voidf", + "body": [ + "void $1 (${2:void}) ", + "{", + " $3", + "}" + ], + "description": "Creates a void function" + }, + "Creates a header include guard C++": { + "scope": "cpp", + "prefix": "ig", + "body": [ + "#ifndef ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}", + "#define ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}", + "", + "${0:// Code for header body}", + "", + "#endif // ${TM_FILENAME/(.*)\\..+$/${1:/upcase}_HPP/}" + ], + "description": "Creates header include guard based on file name for C++ projects" + }, + "Include": { + "scope": "c", + "prefix": "inc", + "body": [ + "#include <$0>" + ], + "description": "Include a header into a file" + }, + "Malloc": { + "scope": "c", + "prefix": "malloc", + "body": [ + "malloc($1 * sizeof(${2:int}))" + ], + "description": "Arrow for pointers in C & C++" + }, + "fopen": { + "scope": "c", + "prefix": "fopen", + "body": [ + "fopen(\"${1:monfichier}\", \"${2|r,r+,w,w+,a,a+|}\")" + ], + "description": "Open a file" + }, + "define": { + "scope": "c", + "prefix": "define", + "body": [ + "#define $1 $2" + ], + "description": "Define a constant" + }, + "enum": { + "scope": "c", + "prefix": "enum", + "body": [ + "enum $1 {$2, $3}" + ], + "description": "Arrow for pointers in C & C++" + }, + "union": { + "scope": "c", + "prefix": "union", + "body": [ + "union $1 {", + " $2;", + " $3;", + "}" + ], + "description": "Arrow for pointers in C & C++" + }, + "struct": { + "scope": "c", + "prefix": "struct", + "body": [ + "struct $1 {", + "${2:// Code goes here}", + "};" + ], + "description": "Struct in C & C++" + }, + "typedef": { + "scope": "c", + "prefix": "type", + "body": [ + "typedef struct _$1 {", + "${2:// Code goes here}", + "} t_$1;" + ], + "description": "Typedef struct in C & C++" + }, + "vector": { + "scope": "cpp", + "prefix": "vector", + "body": [ + "std::vector<$1> $2;" + ], + "description": "std::vector in C++" + }, + "array": { + "scope": "cpp", + "prefix": "array", + "body": [ + "std::array<$1,$2> $3;" + ], + "description": "std::array in C++" + }, + "fichier": { + "scope": "cpp", + "prefix": "file", + "body": [ + "std::${1|ofstream,ifstream|} $2 {${3:'monfichier.txt'}${4:, std::ios::app}};" + ], + "description": "Files in C++" + }, + "lambda": { + "scope": "cpp", + "prefix": "lambda", + "body": [ + "[${1:// Capture zone}](${2:// Parameters}) -> ${3:// Return type} {${4:// Your code goes here}};" + ], + "description": "Lambda in C++" + }, + "template": { + "scope": "cpp", + "prefix": "template", + "body": [ + "template <${1:typename T}>", + "${2:void} $3($4) {", + "${5:// Code goes here}", + "}" + ], + "description": "Template in C++" + }, + "class": { + "scope": "cpp", + "prefix": "class", + "body": [ + "class $1", + "{", + " public:", + " $2", + " private:", + " $3", + "};" + ], + "description": "Class in C++" + }, + "set": { + "scope": "cpp", + "prefix": "set", + "body": [ + "$1 set_$2 ($3 $4)", + "{", + " this->$2 = $4;", + "}" + ], + "description": "Setteur in C++" + }, + "get": { + "scope": "cpp", + "prefix": "get", + "body": [ + "$1 get_$2 ()", + "{", + " return this->$2;", + "}" + ], + "description": "Getteur in C++" + } +} diff --git a/snippets/php.json b/snippets/php.json new file mode 100644 index 0000000..bb3b932 --- /dev/null +++ b/snippets/php.json @@ -0,0 +1,50 @@ +{ + "Class":{ + "scope": "php", + "prefix": "class", + "body": [ + "class $1", + "{", + " ${2:// Attributes}", + "", + " public function __construct($3)", + " {", + " ${4:// Attributes construction}", + " }", + "", + " public function __destruct($5)", + " {", + " ${6:// Attributes destruction}", + " }", + "", + " public function info()", + " {", + " ${7:// Showing attributes data}", + " }", + "}" + ], + "description": "Class with constructor, destructor, info" + }, + "Class Get":{ + "scope":"php", + "prefix":"get", + "body": [ + "public function get_$1()", + "{", + " return \\$this->${2:$1};", + "}" + ], + "description": "Class get function for an attribute" + }, + "Class Set":{ + "scope":"php", + "prefix":"set", + "body": [ + "public function set_$1($2)", + "{", + " \\$this->$1 = $2;", + "}" + ], + "description": "Class set function for an attribute" + } +}
\ No newline at end of file |