Initial commit

This commit is contained in:
Martin Pander
2020-09-10 09:54:18 +02:00
commit 03c7bc3c59
50 changed files with 7816 additions and 0 deletions

123
nvim/UltiSnips/all.snippets Normal file
View File

@ -0,0 +1,123 @@
# This file contains snippets that are always defined. I personally
# have snippets for signatures and often needed texts
# sligthly lower priority than everything else since specialized versions
# should overwrite. The user needs to adjust her priority in her snippets to
# ~-55 so that other filetypes will still overwrite.
priority -60
##############
# NICE BOXES #
##############
global !p
import string, vim
""" Maps a filetype to comment format used for boxes.
Automatically filled during usage"""
_commentDict = { }
def _parse_comments(s):
""" Parses vim's comments option to extract comment format """
i = iter(s.split(","))
rv = []
try:
while True:
# get the flags and text of a comment part
flags, text = next(i).split(':', 1)
if len(flags) == 0:
rv.append((text, text, text, ""))
# parse 3-part comment, but ignore those with O flag
elif flags[0] == 's' and 'O' not in flags:
ctriple = []
indent = ""
if flags[-1] in string.digits:
indent = " " * int(flags[-1])
ctriple.append(text)
flags,text = next(i).split(':', 1)
assert(flags[0] == 'm')
ctriple.append(text)
flags,text = next(i).split(':', 1)
assert(flags[0] == 'e')
ctriple.append(text)
ctriple.append(indent)
rv.append(ctriple)
elif flags[0] == 'b':
if len(text) == 1:
rv.insert(0, (text,text,text, ""))
except StopIteration:
return rv
def _get_comment_format():
""" Returns a 4-element tuple representing the comment format for
the current file. """
return _parse_comments(vim.eval("&comments"))[0]
def make_box(twidth, bwidth=None):
b, m, e, i = _get_comment_format()
bwidth_inner = bwidth - 3 - max(len(b), len(i + e)) if bwidth else twidth + 2
sline = b + m + bwidth_inner * m[0] + 2 * m[0]
nspaces = (bwidth_inner - twidth) // 2
mlines = i + m + " " + " " * nspaces
mlinee = " " + " "*(bwidth_inner - twidth - nspaces) + m
eline = i + m + bwidth_inner * m[0] + 2 * m[0] + e
return sline, mlines, mlinee, eline
def foldmarker():
"Return a tuple of (open fold marker, close fold marker)"
return vim.eval("&foldmarker").split(",")
endglobal
snippet box "A nice box with the current comment symbol" b
`!p
box = make_box(len(t[1]))
snip.rv = box[0] + '\n' + box[1]
`${1:content}`!p
box = make_box(len(t[1]))
snip.rv = box[2] + '\n' + box[3]`
$0
endsnippet
snippet bbox "A nice box over the full width" b
`!p
width = int(vim.eval("&textwidth")) or 71
box = make_box(len(t[1]), width)
snip.rv = box[0] + '\n' + box[1]
`${1:content}`!p
box = make_box(len(t[1]), width)
snip.rv = box[2] + '\n' + box[3]`
$0
endsnippet
snippet fold "Insert a vim fold marker" b
`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]`${2:1} `!p snip.rv = _get_comment_format()[2]`
endsnippet
snippet foldc "Insert a vim fold close marker" b
`!p snip.rv = _get_comment_format()[0]` ${2:1}`!p snip.rv = foldmarker()[1]` `!p snip.rv = _get_comment_format()[2]`
endsnippet
snippet foldp "Insert a vim fold marker pair" b
`!p snip.rv = _get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]` `!p snip.rv = _get_comment_format()[2]`
${2:${VISUAL:Content}}
`!p snip.rv = _get_comment_format()[0]` `!p snip.rv = foldmarker()[1]` $1 `!p snip.rv = _get_comment_format()[2]`
endsnippet
##########################
# LOREM IPSUM GENERATORS #
##########################
snippet lorem "Lorem Ipsum - 50 Words" b
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,
no sea takimata sanctus est Lorem ipsum dolor sit amet.
endsnippet
# vim:ft=snippets:

154
nvim/UltiSnips/c.snippets Normal file
View File

@ -0,0 +1,154 @@
###########################################################################
# TextMate Snippets #
###########################################################################
priority -50
snippet def "#define ..."
#define ${1}
endsnippet
snippet ifndef "#ifndef ... #define ... #endif"
#ifndef ${1/([A-Za-z0-9_]+).*/$1/}
#define ${1:SYMBOL} ${2:value}
#endif
endsnippet
snippet #if "#if #endif" b
#if ${1:0}
${VISUAL}${0:${VISUAL/(.*)/(?1::code)/}}
#endif
endsnippet
snippet inc "#include local header (inc)"
#include "${1:`!p snip.rv = snip.basename + '.h'`}"
endsnippet
snippet Inc "#include <> (Inc)"
#include <${1:.h}>
endsnippet
snippet mark "#pragma mark (mark)"
#if 0
${1:#pragma mark -
}#pragma mark $2
#endif
$0
endsnippet
snippet main "main() (main)"
int main(int argc, char *argv[])
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
return 0;
}
endsnippet
# snippet for "for loop (for)"
# for (${2:i} = 0; $2 < ${1:count}; ${3:++$2})
# {
# ${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
# }
# endsnippet
snippet for "for int loop (for)"
for ( ${4:int} ${2:i}=0; $2<${1:count}; ${3:$2++} ) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet enum "Enumeration"
enum ${1:name} { $0 };
endsnippet
snippet once "Include header once only guard"
#ifndef ${1:`!p
if not snip.c:
import random, string
name = re.sub(r'[^A-Za-z0-9]+','_', snip.fn).upper()
rand = ''.join(random.sample(string.ascii_letters+string.digits, 8))
snip.rv = ('%s_%s' % (name,rand)).upper()
else:
snip.rv = snip.c`}
#define $1
${0}
#endif /* end of include guard: $1 */
endsnippet
snippet td "Typedef"
typedef ${1:int} ${2:MyCustomType};
endsnippet
snippet wh "while loop"
while(${1:/* condition */}) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet do "do...while loop (do)"
do {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
} while(${1:/* condition */});
endsnippet
snippet fprintf "fprintf ..."
fprintf(${1:stderr}, "${2:%s}\n"${2/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$3${2/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet
snippet if "if .. (if)"
if (${1:/* condition */})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet el "else .. (else)"
else {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet eli "else if .. (eli)"
else if (${1:/* condition */}) {
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet ife "if .. else (ife)"
if (${1:/* condition */})
{
${2:/* code */}
}
else
{
${3:/* else */}
}
endsnippet
snippet printf "printf .. (printf)"
printf("${1:%s}\n"${1/([^%]|%%)*(%.)?.*/(?2:, :\);)/}$2${1/([^%]|%%)*(%.)?.*/(?2:\);)/}
endsnippet
snippet st "struct"
struct ${1:`!p snip.rv = (snip.basename or "name") + "_t"`}
{
${0:/* data */}
};
endsnippet
snippet fun "function" b
${1:void} ${2:function_name}(${3})
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}
endsnippet
snippet fund "function declaration" b
${1:void} ${2:function_name}(${3});
endsnippet
# vim:ft=snippets:

View File

@ -0,0 +1,89 @@
priority -50
extends c
# We want to overwrite everything in parent ft.
priority -49
###########################################################################
# TextMate Snippets #
###########################################################################
snippet beginend "$1.begin(), $1.end() (beginend)"
${1:v}${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}begin(), $1${1/^.*?(-)?(>)?$/(?2::(?1:>:.))/}end()
endsnippet
snippet cl "class .. (class)"
class ${1:`!p snip.rv = snip.basename or "name"`}
{
public:
${1/(\w+).*/$1/} (${2:arguments});
virtual ~${1/(\w+).*/$1/} ();
private:
${0:/* data */}
};
endsnippet
snippet ns "namespace .. (namespace)"
namespace${1/.+/ /m}${1:`!p snip.rv = snip.basename or "name"`}
{
${VISUAL}${0:${VISUAL/(.*)/(?1::\/* code *\/)/}}
}${1/.+/ \/* /m}$1${1/.+/ *\/ /m}
endsnippet
snippet readfile "read file (readF)"
std::vector<char> v;
if (FILE *fp = fopen(${1:"filename"}, "r"))
{
char buf[1024];
while(size_t len = fread(buf, 1, sizeof(buf), fp))
v.insert(v.end(), buf, buf + len);
fclose(fp);
}
endsnippet
snippet map "std::map (map)"
std::map<${1:key}, ${2:value}> map$0;
endsnippet
snippet vector "std::vector (v)"
std::vector<${1:char}> v$0;
endsnippet
snippet tp "template <typename ..> (template)"
template <typename ${1:_InputIter}>
endsnippet
## my own snippets
snippet dv "debug with var"
std::cout << "$1\n" << ${1:var} << "\n" << std::endl;
endsnippet
snippet dvif "debug with var (if)"
if ( output_ ) std::cout << "$1\n" << ${1:var} << "\n" << std::endl;
endsnippet
snippet pm "debug with message"
std::cout << "${1:message}" << std::endl;
endsnippet
snippet pmif "debug with message (if)"
if ( output_ ) std::cout << "${1:message}" << std::endl;
endsnippet
snippet cb "function comment block" s
// =============================================================================
// ${1:comment}
// =============================================================================
endsnippet
snippet cf "function comment block" s
// == Function =================================================================
// Name : ${1:Name}
// Description: ${2:Description}
// =============================================================================
endsnippet
# vim:ft=snippets:

View File

@ -0,0 +1,6 @@
priority -50
snippet disp "Display variable" i
disp('${1:${VISUAL:variableName}}')
disp(${2:${VISUAL:variable}})
endsnippet

View File

@ -0,0 +1,92 @@
priority -50
global !p
import vim
# Tests for the existence of a variable declared by Vim's filetype detection
# suggesting the type of shell script of the current file
def testShell(scope, shell):
return vim.eval("exists('" + scope + ":is_" + shell + "')")
# Loops over the possible variables, checking for global variables
# first since they indicate an override by the user.
def getShell():
for scope in ["g", "b"]:
for shell in ["bash", "posix", "sh", "kornshell"]:
if testShell(scope, shell) == "1":
if shell == "kornshell":
return "ksh"
if shell == "posix":
return "sh"
return shell
return "sh"
endglobal
###########################################################################
# TextMate Snippets #
###########################################################################
snippet #!
`!p snip.rv = '#!/bin/' + getShell() + "\n\n" `
endsnippet
snippet !env "#!/usr/bin/env (!env)"
`!p snip.rv = '#!/usr/bin/env ' + getShell() + "\n\n" `
endsnippet
snippet temp "Tempfile"
${1:TMPFILE}="$(mktemp -t ${2:`!p
snip.rv = re.sub(r'[^a-zA-Z]', '_', snip.fn) or "untitled"
`})"
${3:${4/(.+)/trap "/}${4:rm -f '$${1/.*\s//}'}${4/(.+)/" 0 # EXIT\n/}${5/(.+)/trap "/}${5:rm -f '$${1/.*\s//}'; exit 1}${5/(.+)/" 2 # INT\n/}${6/(.+)/trap "/}${6:rm -f '$${1/.*\s//}'; exit 1}${6/(.+)/" 1 15 # HUP TERM\n/}}
endsnippet
snippet case "case .. esac (case)"
case ${1:word} in
${2:pattern} )
$0;;
esac
endsnippet
snippet elif "elif .. (elif)"
elif ${2:[[ ${1:condition} ]]}; then
${0:#statements}
endsnippet
snippet for "for ... done (for)"
for (( i = 0; i < ${1:10}; i++ )); do
${0:#statements}
done
endsnippet
snippet forin "for ... in ... done (forin)"
for ${1:i}${2/.+/ in /}${2:words}; do
${0:#statements}
done
endsnippet
snippet here "here document (here)"
<<-${2:'${1:TOKEN}'}
$0
${1/['"`](.+)['"`]/$1/}
endsnippet
snippet if "if ... then (if)"
if ${2:[[ ${1:condition} ]]}; then
${0:#statements}
fi
endsnippet
snippet until "until ... (done)"
until ${2:[[ ${1:condition} ]]}; do
${0:#statements}
done
endsnippet
snippet while "while ... (done)"
while ${2:[[ ${1:condition} ]]}; do
${0:#statements}
done
endsnippet
# vim:ft=snippets:

View File

158
nvim/UltiSnips/tex.snippets Normal file
View File

@ -0,0 +1,158 @@
priority -50
extends texmath
snippet document "document setup"
\documentclass[a4paper]{article}
\usepackage{defaultTex}
% \usepackage[style=alphabetic]{biblatex}
% \addbibresource{lib.bib}
\begin{document}
${1:text}
\end{document}
endsnippet
snippet "b(egin)?" "begin{} / end{}" br
\begin{${1:something}}
${0:${VISUAL}}
\label{${2}}
\end{$1}
endsnippet
snippet bo "bold"
\textbf{${1:${VISUAL}}}$0
endsnippet
snippet tab
\begin{${1:t}${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}{${2:c}}
$0${2/((?<=.)c|l|r)|./(?1: & )/g}
\end{$1${1/(t)$|(a)$|(.*)/(?1:abular)(?2:rray)/}}
endsnippet
snippet fig "Figure environment" b
\begin{figure}${2:[htpb]}
\centering
\includegraphics[width=${3:0.8}\linewidth]{${4:name.ext}}
\caption{${4/(\w+)\.\w+/\u$1/}$0}
\label{fig:${4/(\w+)\.\w+/$1/}}
\end{figure}
endsnippet
snippet enum "Enumerate" b
\begin{enumerate}
\item $1
\end{enumerate}
endsnippet
snippet item "Itemize" b
\begin{itemize}
\item $1
\end{itemize}
endsnippet
snippet desc "Description" b
\begin{description}
\item[$1] $0
\end{description}
endsnippet
snippet eq "equation"
\begin{equation}
${2:${VISUAL}}
\end{equation}
endsnippet
snippet eql "equation with label"
\begin{equation}
${2:${VISUAL}}
\label{$1}
\end{equation}
endsnippet
snippet eqs "aligned equations"
\begin{equation}
\begin{aligned}
${2:${VISUAL}}
\end{aligned}
\end{equation}
endsnippet
snippet eqsl "aligned equations with label"
\begin{equation}
\begin{aligned}
${2:${VISUAL}}
\end{aligned}
\label{$1}
\end{equation}
endsnippet
snippet align "align"
\begin{align}
${2:${VISUAL}}
\label{$1}
\end{align}
endsnippet
snippet it "Individual item" b
\item $1
endsnippet
snippet part "Part" b
\part{${1:part name}}
\label{prt:${2:${1/(\w+)|\W+/(?1:\L$0\E:_)/ga}}}
${0}
endsnippet
snippet cha "Chapter" b
\chapter{${1:chapter name}}
\label{cha:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet sec "Section" b
\section{${1:section name}}
\label{sec:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet sub "Subsection" b
\subsection{${1:subsection name}}
\label{sub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet ssub "Subsubsection" b
\subsubsection{${1:subsubsection name}}
\label{ssub:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet par "Paragraph" b
\paragraph{${1:paragraph name}}
\label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet subp "Subparagraph" b
\subparagraph{${1:subparagraph name}}
\label{par:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3\E)/ga}}}
${0}
endsnippet
snippet ni "Non-indented paragraph" b
\noindent
${0}
endsnippet
snippet pac "Package" b
\usepackage[${1:options}]{${2:package}}$0
endsnippet
# vim:ft=snippets:

View File

@ -0,0 +1,85 @@
priority -50
##############
# MATH STUFF #
##############
# snippet eq "Equation" b
# \begin{equation}
# $0
# \end{equation}
# endsnippet
# snippet eqnn "Equation without number" b
# \begin{equation*}
# $0
# \end{equation*}
# endsnippet
# snippet eqa "Equation array" b
# \begin{eqnarray}
# $1 & $2 & $0
# \end{eqnarray}
# endsnippet
# snippet eqann "Equation array without numbers" b
# \begin{eqnarray*}
# $1 & $2 & $0
# \end{eqnarray*}
# endsnippet
snippet frac "Fraction" w
\frac{${1:${VISUAL:nom}}}{${2:denom}}
endsnippet
snippet mat "Smart Matrix"
\begin{${1:p/b/v/V/B/small}matrix}
$0
\end{$1matrix}
endsnippet
snippet lrb "left( right)" w
\left( ${1:${VISUAL}} \right)
endsnippet
snippet lrv "left| right|" w
\left| ${1:${VISUAL}} \right|
endsnippet
snippet lrB "left\{ right\}" w
\left\\{ ${1:${VISUAL}} \right\\}
endsnippet
snippet lre "left[ right]" w
\left[ ${1:${VISUAL}} \right]
endsnippet
# my snippets
snippet func "Function" w
\func{${1:${VISUAL}}}{${2}}
endsnippet
snippet funcb "Function with brackets" w
\funcb{${1:${VISUAL}}}{${2}}
endsnippet
snippet int "integral"
\int_{${1}}^{${2}}
endsnippet
snippet sum "sum"
\sum_{${1}}^{${2}}
endsnippet
snippet eqr "eqref"
\eqref{${1}}
endsnippet
snippet v "Vector" w
\vec
endsnippet
snippet bis "bis" w
\bis{${1}}{${2}}
endsnippet
# vim:ft=snippets: