nvim: snippets for python and tex

master
tiyn 2 years ago
parent 622431936e
commit 546f8f7ded

@ -399,10 +399,11 @@ endfun
autocmd BufWritePre * :call TrimWhitespace()
" read files correctly
autocmd BufRead,BufNewFile *.tex set filetype=tex
autocmd BufRead,BufNewFile *.html set filetype=html
autocmd BufRead,BufNewFile *.h set filetype=c
autocmd BufRead,BufNewFile *.html set filetype=html
autocmd BufRead,BufNewFile *.nim set filetype=nim
autocmd BufRead,BufNewFile *.py set filetype=python
autocmd BufRead,BufNewFile *.tex set filetype=tex
" formatting options
autocmd FileType java setlocal shiftwidth=2 softtabstop=2
@ -423,16 +424,16 @@ autocmd FileType tex,latex setlocal formatprg=latexindent\ -
autocmd FileType tex,latex noremap <F8> gggqG
" cleanup certain files after leaving the editor
autocmd VimLeave *.tex !texclear %
autocmd VimLeave *.c !cclear
autocmd VimLeave *.tex !texclear %
" highlighting break line
autocmd BufEnter,FileType c set colorcolumn=80
autocmd BufEnter,FileType java set colorcolumn=100
autocmd BufEnter,FileType markdown set colorcolumn=80
autocmd BufEnter,FileType tex set colorcolumn=80
autocmd BufEnter,FileType nim set colorcolumn=80
autocmd BufEnter,FileType python set colorcolumn=80
autocmd BufEnter,FileType tex set colorcolumn=80
"" colorscheme
set background=dark

@ -0,0 +1,199 @@
# shbang 3
snippet #!
#!/usr/bin/env python3
# shbang 2
snippet #!2
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# shbang 3
snippet #!3
#!/usr/bin/env python3
# import
snippet imp
import ${0:module}
# from ... import
snippet from
from ${1:package} import ${0:module}
# while
snippet wh
while ${1:condition}:
${0:${VISUAL}}
# do ... while
snippet dowh
while True:
${1}
if ${0:condition}:
break
# with
snippet with
with ${1:expr} as ${2:var}:
${0:${VISUAL}}
# async with
snippet awith
async with ${1:expr} as ${2:var}:
${0:${VISUAL}}
# class
snippet cla
class ${1:class_name}:
"""${0:description}"""
# class with init
snippet clai
class ${1:class_name}:
"""${2:description}"""
def __init__(self, ${3:args}):
${0}
# function with docstring
snippet def
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
${0}
# function
snippet deff
def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
${0}
# async function with docstring
snippet adef
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
"""${3:docstring for $1}"""
${0}
# async function
snippet adeff
async def ${1:fname}(${2:`indent('.') ? 'self' : ''`}):
${0}
# init function
snippet defi
def __init__(self, ${1:args}):
${0}
# if
snippet if
if ${1:condition}:
${0:${VISUAL}}
# else
snippet el
else:
${0:${VISUAL}}
# else if
snippet ei
elif ${1:condition}:
${0:${VISUAL}}
# for
snippet for
for ${1:item} in ${2:items}:
${0}
# return
snippet ret
return ${0}
# self reference
snippet .
self.
# self attribute
snippet sa self.attribute = attribute
self.${1:attribute} = $1
# try ... except
snippet try Try/Except
try:
${1:${VISUAL}}
except ${2:Exception} as ${3:e}:
${0:raise $3}
# try ... except ... else
snippet trye Try/Except/Else
try:
${1:${VISUAL}}
except ${2:Exception} as ${3:e}:
${4:raise $3}
else:
${0}
# try ... except ... finally
snippet tryf Try/Except/Finally
try:
${1:${VISUAL}}
except ${2:Exception} as ${3:e}:
${4:raise $3}
finally:
${0}
# try ... except ... else ... finally
snippet tryef Try/Except/Else/Finally
try:
${1:${VISUAL}}
except ${2:Exception} as ${3:e}:
${4:raise $3}
else:
${5}
finally:
${0}
# if name is main
snippet ifmain
if __name__ == '__main__':
${0:main()}
# docstring
snippet "
"""${0:doc}
"""
# test function
snippet test
def test_${1:description}(${2:`indent('.') ? 'self' : ''`}):
${0}
# list comprehension
snippet lcp list comprehension
[${1} for ${2} in ${3:${VISUAL}}]${0}
# dict comprehension
snippet dcp dict comprehension
{${1}: ${2} for ${3} in ${4:${VISUAL}}}${0}
# set comprehension
snippet scp set comprehension
{${1} for ${2} in ${3:${VISUAL}}}${0}
# print
snippet pr
print($0)
# print string
snippet prs
print("$0")
# fprint string
snippet prf
print(f"$0")
# print to file
snippet fpr
print($0, file=${1:sys.stderr})
# print string to file
snippet fprs
print("$0", file=${1:sys.stderr})
# fprint string to file
snippet fprf
print(f"$0", file=${1:sys.stderr})

@ -1,10 +1,257 @@
# Section
# documentclass without options
snippet dcl \documentclass{}
\\documentclass{${1:class}} ${0}
# documentclass with options
snippet dclo \documentclass[]{}
\\documentclass[${1:options}]{${2:class}} ${0}
# newcommand
snippet nc \newcommand
\\newcommand{\\${1:cmd}}[${2:opt}]{${3:realcmd}} ${0}
# usepackage
snippet up \usepackage
\\usepackage[${1:options}]{${2:package}} ${0}
# \begin{}...\end{}
snippet begin \begin{} ... \end{} block
\\begin{${1:env}}
${0:${VISUAL}}
\\end{$1}
# maketitle
snippet mkt maketitle
\\maketitle
# tabular
snippet tab tabular (or arbitrary) environment
\\begin{${1:tabular}}{${2:c}}
${0:${VISUAL}}
\\end{$1}
snippet center center environment
\\begin{center}
${0:${VISUAL}}
\\end{center}
# align(ed)
snippet ali align(ed) environment
\\begin{align${1:ed}}
\\label{eq:${2}}
${0:${VISUAL}}
\\end{align$1}
# equation
snippet eq equation environment
\\begin{equation}
${0:${VISUAL}}
\\end{equation}
# equation
snippet eql Labeled equation environment
\\begin{equation}
\\label{eq:${2}}
${0:${VISUAL}}
\\end{equation}
# equation
snippet eq* unnumbered equation environment
\\begin{equation*}
${0:${VISUAL}}
\\end{equation*}
# label
snippet lab \label
\\label{${1:eq:}${2:fig:}${3:tab:}${0}}
# enumerate
snippet enum enumerate environment
\\begin{enumerate}
\\item ${0}
\\end{enumerate}
# itemize
snippet item itemize environment
\\begin{itemize}
\\item ${0}
\\end{itemize}
# item
snippet it \item
\\item ${1:${VISUAL}}
# endless new item
snippet ]i \item (recursive)
\\item ${1}
${0:]i}
# matrix
snippet mat smart matrix environment
\\begin{${1:p/b/v/V/B/small}matrix}
${0:${VISUAL}}
\\end{$1matrix}
# chapter
snippet cha \chapter
\\chapter{${1:chapter name}}%
\\label{cha:${2:$1}}
${0}
# section
snippet sec \section
\\section{${1:section name}}%
\\label{sec:${2:$1}}
${0}
# Section without number
# section without number
snippet sec* \section*
\\section*{${1:section name}}%
\\label{sec:${2:$1}}
${0}
# sub section
snippet sub \subsection
\\subsection{${1:subsection name}}%
\\label{sub:${2:$1}}
${0}
# sub section without number
snippet sub* \subsection*
\\subsection*{${1:subsection name}}%
\\label{sub:${2:$1}}
${0}
# sub sub section
snippet ssub \subsubsection
\\subsubsection{${1:subsubsection name}}%
\\label{ssub:${2:$1}}
${0}
# sub sub section without number
snippet ssub* \subsubsection*
\\subsubsection*{${1:subsubsection name}}%
\\label{ssub:${2:$1}}
${0}
# paragraph
snippet par \paragraph
\\paragraph{${1:paragraph name}}%
\\label{par:${2:$1}}
${0}
# sub paragraph
snippet subp \subparagraph
\\subparagraph{${1:subparagraph name}}%
\\label{subp:${2:$1}}
${0}
# text italic
snippet ita italic text
\\textit{${1:${VISUAL:text}}}${0}
# text bold
snippet bf bold face text
\\textbf{${1:${VISUAL:text}}}${0}
# text underline
snippet under underline text
\\underline{${1:${VISUAL:text}}}${0}
# text overline
snippet over overline text
\\overline{${1:${VISUAL:text}}}${0}
# text emphasize
snippet emp emphasize text
\\emph{${1:${VISUAL:text}}}${0}
# text small caps
snippet sc small caps text
\\textsc{${1:${VISUAL:text}}}${0}
# text sans serife
snippet sf sans serife text
\\textsf{${1:${VISUAL:text}}}${0}
# text roman
snippet rm roman font text
\\textrm{${1:${VISUAL:text}}}${0}
# text typewriter
snippet tt typewriter (monospace) text
\\texttt{${1:${VISUAL:text}}}${0}
# text subscripted
snippet tsub subscripted text
\\textsubscript{${1:${VISUAL:text}}}${0}
# text superscripted
snippet tsup superscripted text
\\textsuperscript{${1:${VISUAL:text}}}${0}
# footnote
snippet ft \footnote
\\footnote{${1:${VISUAL:text}}}${0}
# figure includegraphics
snippet fig figure environment (includegraphics)
\\begin{figure}[htpb]
\\begin{center}
\\includegraphics[scale=${1}]{Figures/${2}}
\\end{center}
\\caption{${3}}
\\label{fig:${4}}
\\end{figure}
${0}
# figure tikz
snippet tikz figure environment (tikzpicture)
\\begin{figure}[htpb]
\\begin{center}
\\begin{tikzpicture}[scale=${1:1}, transform shape]
${2}
\\end{tikzpicture}
\\end{center}
\\caption{${3}}%
\\label{fig:${4}}
\\end{figure}
${0}
# math fraction
snippet frac \frac{}{}
\\frac{${1:num}}{${2:denom}} ${0}
# math sum
snippet sum \sum^{}_{}
\\sum^{${1:n}}_{${2:i=1}} ${0}
# math limes
snippet lim \lim_{}
\\lim_{${1:n \\to \\infty}} ${0}
# code listing
snippet lst
\\begin{listing}[language=${1:language}]
${0:${VISUAL}}
\\end{listing}
# code listing inline
snippet lsi
\\lstinline|${1}| ${0}
# hyperlink url
snippet url
\\url{${1}} ${0}
# hyperlink href
snippet href
\\href{${1}}{${2}} ${0}
# right arrow
snippet ra rightarrow
\\rightarrow {$0}
# long right arrow
snippet lra longrightarrow
\\longrightarrow {$0}

Loading…
Cancel
Save