]> git.sthu.org Git - vimconf.git/blob - macros.vim
init: New detectspelllang conf
[vimconf.git] / macros.vim
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/&'
10 execute ':%s/²/\^2/&'
11 endfunction
12
13
14 "Open current file with a specific program
15 function OpenIn(prog)
16 silent execute ":!" . a:prog . " % &"
17 endfunction
18
19
20 "Prepend the namespace to an identifier, e.g. 'std::' before 'map' excluding
21 "those in C/C++ comments.
22 function PrependCppNamespaceToIdent(ns, id)
23
24 " To match Not to match
25 "
26 "|id |// id
27 "| id |// /* */ id
28 "|/* */ /* */ id |/* */ // id
29 "|id /* */ |/* id
30 "|*/ id | * id
31 " |/* id */
32 " |::id
33 " |/**/ ::id
34 " |#include <id>
35 "
36 " In order to not match '* id' it is assumed that multi-line comment lines
37 " in the middle begin with a star.
38
39 " If #include and // and /* and ^* and :: is not prepend:
40 execute ':%s@\(\(#include\|\/\/\|\/\*\|^\s*\*[^/]\).*\|::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
41 " If #include and // and :: is not prepend, but */ is, and no further /* or // are found
42 execute ':%s@\(\(#include\|\/\/\).*\)\@<!\*\/\(\/[^\/\*]\|[^\/]\)*\zs\(::\)\@<!\<' . a:id . '\>@' . a:ns . '::' . a:id . '@ge'
43
44 endfunction
45
46
47 "Prepend STL namespace 'std::' to several identifiers
48 function PrependSTLNamespace()
49 " This list of identifier is not complete, but adding all of them is too
50 " much. We rather like to add identifieres that are 'typical' for C++.
51 " Others, like 'move' are likely to not be C++ specific. In this cases the
52 " user is asked to call PrependCppNamespaceToIdent by hand.
53 let id = []
54 let id = id +['cin', 'cout', 'cerr', 'endl']
55 let id = id +['swap', 'sort', 'max', 'min']
56 let id = id +['vector', 'deque', 'list', 'map', 'multimap', 'set']
57 let id = id +['queue', 'stack', 'priority_queue']
58 let id = id +['ostream', 'istream', 'sstream']
59 let id = id +['pair', 'string']
60
61 for i in id
62 call PrependCppNamespaceToIdent("std", i)
63 endfor
64 endfunction
65
66
67 function EscapeHexToChar()
68 echo 'Call "x/Nxb addr" in GDB to print N bytes at addr'
69 execute '%s/^.*://'
70 execute '%s/\s*0x\(\x\x\)/\\x\1/g'
71 execute '%s/^\(.*\)$/"\1"/'
72 endfunction
73
74
75 function InsertIncludeGuardsWithoutEndif()
76 let gatename = substitute(expand("%:t"), "\\.", "_", "g") . '_' . strpart(system('pwgen -c 16 1'), 0, 16)
77 execute "normal! i#ifndef " . gatename
78 execute "normal! o#define " . gatename
79 endfunction
80
81
82 function AddIncludeGuards()
83 execute "normal! Go#endif"
84 execute "normal! gg"
85 call InsertIncludeGuardsWithoutEndif()
86 endfunction
87
88
89 function RunPandoc()
90 " If pandoc.css exists, use it
91 let cssopts = ""
92 if findfile("pandoc.css", ".") == "pandoc.css"
93 let cssopts = "-c pandoc.css"
94 endif
95
96 execute ":!pandoc " . cssopts . " --self-contained --toc '" . @% . "' -o '" . @% . "'.html"
97 endfunction
98
99 function RunMarkdownpy(prog)
100 execute ":!" . a:prog . " " . @% . " > " . @% . ".html"
101 endfunction
102
103 function RunMarkdown()
104 if executable("pandoc")
105 call RunPandoc()
106 elseif executable("markdown2")
107 call RunMarkdownpy("markdown2")
108 elseif executable("markdown_py")
109 call RunMarkdownpy("markdown_py")
110 else
111 echo "No markdown implementation found."
112 endif
113 endfunction
114
115
116 if filereadable($HOME . '/.vim/macros-local.vim')
117 source ~/.vim/macros-local.vim
118 endif