1 " Tranlate umlauts to tex-syntax umlauts
2 function TexTransUmlaute()
3 execute ':%s/ü/\\\"u/ge'
4 execute ':%s/Ü/\\\"U/&'
5 execute ':%s/ö/\\\"o/&'
6 execute ':%s/Ö/\\\"O/&'
7 execute ':%s/ä/\\\"a/&'
8 execute ':%s/Ä/\\\"A/&'
9 execute ':%s/ß/\\\"s/&'
13 function! s:texTableBfEntries()
14 execute 's/\( *\)\([^ &][^&]*[^ &]\)\( \+\)/\1\\textbf{\2}\3/g'
17 command! -range TexTableBfEntries call s:texTableBfEntries()
19 "Open current file with a specific program
21 silent execute ":!" . a:prog . " % &"
25 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
26 "those in C/C++ comments.
27 function PrependCppNamespaceToIdent(ns, id)
29 " To match Not to match
33 "|/* */ /* */ id |/* */ // id
41 " In order to not match '* id' it is assumed that multi-line comment lines
42 " in the middle begin with a star.
44 " If #include and // and /* and ^* and :: is not prepend:
45 execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
46 " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
47 execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
52 "Prepend STL namespace 'std::' to several identifiers
53 function PrependSTLNamespace()
54 " This list of identifier is not complete, but adding all of them is too
55 " much. We rather like to add identifieres that are 'typical' for C++.
56 " Others, like 'move' are likely to not be C++ specific. In this cases the
57 " user is asked to call PrependCppNamespaceToIdent by hand.
59 let id = id +['cin', 'cout', 'cerr', 'endl']
60 let id = id +['swap', 'sort', 'max', 'min']
61 let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set']
62 let id = id +['queue', 'stack', 'priority_queue']
63 let id = id +['ostream', 'istream', 'sstream']
64 let id = id +['pair', 'string']
67 call PrependCppNamespaceToIdent("std", i)
72 function EscapeHexToChar()
73 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
75 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
76 execute '%s/^\(.*\)$/"\1"/'
80 function InsertIncludeGuardsWithoutEndif()
81 " Build name of guard: Take filename, replace some chars by _ and
82 " prepend a random sequence to make guard robust against file name
84 let guardname = substitute(expand("%:t"), "[\\.-]", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
85 execute "normal! i#ifndef " . guardname
86 execute "normal! o#define " . guardname
90 function AddIncludeGuards()
91 execute "normal! Go#endif"
93 call InsertIncludeGuardsWithoutEndif()
98 " If pandoc.css exists, use it
100 if findfile("pandoc.css", ".") == "pandoc.css"
101 let cssopts = "-c pandoc.css"
104 execute ":!pandoc " . cssopts . " --self-contained --toc '" . @% . "' -o '" . @% . "'.html"
108 function RunMarkdownpy(prog)
109 execute ":!" . a:prog . " " . @% . " > " . @% . ".html"
113 function RunAsciidoctor()
114 execute ":!asciidoctor " . @%
118 function RunMarkdown()
119 if executable("pandoc")
121 elseif executable("markdown2")
122 call RunMarkdownpy("markdown2")
123 elseif executable("markdown_py")
124 call RunMarkdownpy("markdown_py")
126 echo "No markdown implementation found."
131 function RunAsciidoc()
132 if executable("asciidoctor")
133 call RunAsciidoctor()
135 echo "No asciidoc implementation found."
142 return match(system('pmset -g batt'), "Now drawing from 'Battery Power'") != -1
144 if filereadable('/sys/class/power_supply/AC/online')
145 return readfile('/sys/class/power_supply/AC/online') == ['0']
152 if filereadable($HOME . '/.vim/macros-local.vim')
153 source ~/.vim/macros-local.vim