This repository has been archived by the owner on Mar 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
.vimfunctions
132 lines (119 loc) · 3.55 KB
/
.vimfunctions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
function! IndentPHP()
let old_ft = &l:ft
let old_et = &l:et
set ft=php et ts=4 sw=4
:'<,'>s/^\(\t\| \)*//g
:'<,'>s/\(class .*\) *{/\1{ /ge
:'<,'>s/\(function .*\) *{/\1{ /ge
:'<,'>s/function\n\s*/function /g
:'<,'>s/ }/}/ge
normal `<O<?php
normal gv=
normal `<-1dd
:'<,'>s/^/ /
:'<,'>s/ *$//e
:'<,'>s/}\n\n\n\( *}\)/}\1/e
:'<,'>s/\\_\([A-Z]\)/_\1/ge
normal `>A
let &l:ft = old_ft
let &l:et = old_et
endfunction
noremap <Leader>ip :<C-U>call IndentPHP()<CR>
function! IndentTable()
:'<,'>s/\n/ /g
:'<,'>s/\s*\\|\\|\s\{1,5}\\|\\|\s*//g
:'<,'>s/^\s*//g
:'<,'>s/\s*\\|\\|\s*/\t/g
endfunction
noremap <Leader>it :<C-U>call IndentTable()<CR>
function! IndentSql()
:'{,'}s/\C^\s*SELECT\(\n\|\s*\)/SELECT/
:'{,'}s/,\s*\([a-z]\.[a-z]\+ AS [a-z]__[a-z]\+\)/, \1/g
:'{,'}s/\C\(FROM\|WHERE\|ORDER BY\|GROUP BY\|HAVING\|LIMIT\|OFFSET\)\(\s*\|\n\)/\1 /g
:'{,'}s/\C\(\n\|\s\)*\(\(LEFT\|RIGHT\|INNER\|OUTER\) JOIN\)\s*/ \2 /g
:'{,'}s/\C\(\n\|\s)*\(ON \)\s*/ \2/g
:FixWhitespace
endfunction
noremap <Leader>is :<C-U>call IndentSql()<CR>
function! IndentQuery()
:'<,'>s/\n/ /g
:'<,'>s/ ->/ ->/g
:'<,'>s/; /;/g
endfunction
noremap <Leader>iq :<C-U>call IndentQuery()<CR>
function! FixCautions()
/\*\*[A-Z]\+\*\*
:g/\*\*[A-Z]\+\*\*/.s/^\(.*\)\*\*\([A-Z]\+\)\*\* \(.*\)$/.. \L\2\E::\1\3/
endfunction
noremap <Leader>fc :call FixCautions()<CR>
function! FixRoles()
:%s/``Doctrine``/:php:class:`Doctrine`/g
:%s/``Doctrine_Manager``/:php:class:`Doctrine_Manager`/g
:%s/``Doctrine_Connection``/:php:class:`Doctrine_Connection`/g
:%s/``Doctrine_Query``/:php:class:`Doctrine_Query`/g
:%s/``Doctrine_Collection``/:php:class:`Doctrine_Collection`/g
:%s/``Doctrine_Record``/:php:class:`Doctrine_Record`/g
:%s/``Doctrine_Table``/:php:class:`Doctrine_Table`/g
:%s/``Doctrine_Core::autoload``/:php:meth:`Doctrine_Core::autoload`/g
:%s/``Doctrine_Core::getTable``/:php:meth:`Doctrine_Core::getTable`/g
:%s/``Doctrine_Core::\([A-Z_]\+\)``/:php:const:`Doctrine_Core::\1`/g
:%s/``Doctrine_Manager::connection``/:php:meth:`Doctrine_Manger::connection`/g
:%s/``Doctrine_Record::hasMany``/:php:meth:`Doctrine_Record::hasMany`/g
:%s/``Doctrine_Record::hasOne``/:php:meth:`Doctrine_Record::hasOne`/g
:%s/``\([^`]*.php\)``/:file:`\1`/g
:%s/``\([^`]*\)()``/:php:meth:`\1`/g
endfunction
noremap <Leader>fr :call FixRoles()<CR>
function! FixExamples()
:%s/^\/\/ ... //
:%s/^\n \(\/\/ [a-z]*.php\)\n\n/\1/
:%s/:code:`\(.*\)`\\ /$\1$/
endfunction
noremap <Leader>fe :call FixExamples()<CR>
function! FixTitles()
:g/^++ /normal ^3dlVypVr=VykP
:g/^+++ /normal ^4dlVypVr-VykP
:g/^++++ /normal ^5dlVypVr^VykP
:g/^+++++ /normal ^6dlVypVr"VykP
:g/^\*\*[^\*]*:\*\*$/normal ^2dl$h2dl^i
:%s/\.\.\.\n===\n\n//e
endfunction
noremap <Leader>ft :call FixTitles()<CR>
function! FixTitlesJP()
:g/^++ /normal ^3dl^yv$o ppVr=VykP
:g/^+++ /normal ^4dl^yv$o ppVr-VykP
:g/^++++ /normal ^5dl^yv$o ppVr^VykP
:g/^+++++ /normal ^6dl^yv$o ppVr"VykP
:%s/\.\.\.\n===\n\n//e
endfunction
function! FixLinks()
:%s/\[\(http:\/\/\_.\{-}\) \(\_.\{-}\)\]/`\2 <\1>`_/g
:%s/\[doc \([A-Za-z-]\+\) :name\]/:doc:`\1`/g
:%s/\[doc \([A-Za-z-]\+\) \([A-za-z ]\{-}\)\]/:doc:`\2 <\1>`/g
endfunction
noremap <Leader>fl :call FixLinks()<CR>
function! FixMisc()
:%s/\\_/_/g
:%s/\\\*/*/g
:%s/^- /* /g
:%s/:code:`\(.*\)`\\ /$\1$/g
endfunction
noremap <Leader>fm :call FixMisc()<CR>