Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 1.7

- g:vikiHomePage: If you call VikiEdit! (with "bang"), the homepage is opened
first so that its customizations are in effect. Also, if you call :VikiHome or
:VikiEdit *, the homepage is opened.
- basic highlighting & indentation of emacs-planner style task lists (sort of)
- command line completion for :VikiEdit
- new command/function VikiDefine for defining intervikis
- added <LocalLeader>ve map for :VikiEdit
- fixed problem in VikiEdit (when the cursor was on a valid viki link, the
text argument was ignored)
- fixed opening special files/urls in a designated window
- fixed highlighting of comments
- vikiLowerCharacters and vikiUpperCharacters can be buffer local
- fixed problem when an url contained an ampersand
- fixed error message when the &hidden option wasn't set (see g:vikiHide)
  • Loading branch information...
commit fa31ddc9205fc170c51f13f0780191d78ddd7d37 1 parent 8243b04
Tom Link authored October 31, 2005 vim-scripts committed November 13, 2010
83  doc/viki.txt
@@ -253,12 +253,11 @@ A viki name is either:
253 253
 
254 254
                 Couldn't SCI::ThisIdeaOfMine be combined with COMP::ThisIdeaOfMine?
255 255
 <
256  
-            NOTE: An "inter wiki" is defined by setting a variable with the 
257  
-            prefix "g:vikiInter". Example:
  256
+            NOTE: You can define intervikis with the VikiDefine command: >
258 257
 
259  
-                let g:vikiInterOTHERVIKI = "$HOME/bla"
  258
+                VikiDefine OTHERVIKI /home/t/Wiki .vik
260 259
 
261  
-            Then OTHERVIKI::VikiName points to the file "$HOME/bla/VikiName".
  260
+<           Then OTHERVIKI::VikiName points to the file "/home/t/Wiki/VikiName.vik".
262 261
 
263 262
             NOTE: Set the string variable g:vikiInter{NAME}_suffix (see 
264 263
             |curly-braces-names|) in order to override the settings of 
@@ -358,6 +357,7 @@ Headings~
358 357
 
359 358
                                                     *viki-lists*
360 359
 Lists: (indented)~
  360
+
361 361
     - Item
362 362
         * Item
363 363
             + Item
@@ -370,15 +370,39 @@ Lists: (indented)~
370 370
                 @ Item A
371 371
                 @ Item B
372 372
 
373  
-    NOTE: "@" (unordered lists) and "#" (ordered lists) are the preferred 
374  
-    markers.
  373
+NOTE: "@" (unordered lists) and "#" (ordered lists) are the preferred markers.
375 374
 
376 375
 
377 376
                                                     *viki-descriptions*
378 377
 Descriptions: (indented)~
  378
+
379 379
     Item :: Description
380 380
 
381 381
 
  382
+                                                    *viki-tasks*
  383
+Tasks: (indented)~
  384
+emacs-planer compatible mode: >
  385
+
  386
+    #A1 _           Important task
  387
+    #A2 x           Less important task (done)
  388
+    #A2 90%         Less important task (mostly completed)
  389
+    #B2 2005-10-30  Less important task with deadline
  390
+    #B2 x2005-10-25 Less important task (completed)
  391
+
  392
+You can also switch category and priority: >
  393
+
  394
+    #1A _           Important task
  395
+    #2A x           Less important task (done)
  396
+
  397
+If you want to sort by date, you have to use this form: >
  398
+
  399
+    #T: 2005-10-30  2A: Important task
  400
+    #T: 2005-11-11  1A: Most important task
  401
+    #T: x2005-10-30 3A: Less important task (done)
  402
+
  403
+NOTE: deplate doesn't currently support task lists.
  404
+
  405
+
382 406
                                                     *viki-tables*
383 407
 Tables~
384 408
 || Head || Category ||
@@ -386,8 +410,8 @@ Tables~
386 410
 #CAPTION: This Table
387 411
 #label
388 412
 
389  
-    NOTE: Rows can span more than one line by putting a backslash ('\') at 
390  
-    the end of the line.
  413
+NOTE: Rows can span more than one line by putting a backslash ('\') at the end 
  414
+of the line.
391 415
 
392 416
 
393 417
                                                     *viki-symbols*
@@ -404,7 +428,7 @@ Markers~
404 428
 Strings~
405 429
 "Text in \"quotes\""
406 430
 
407  
-    NOTE: See also |g:vikiMarkupEndsWithNewline|.
  431
+NOTE: See also |g:vikiMarkupEndsWithNewline|.
408 432
 
409 433
 
410 434
                                                     *viki-textstyles*
@@ -538,6 +562,8 @@ Default Key Binding~
538 562
 a wiki syntax group -- if the second argument is 1 it tries to interpret the 
539 563
 text under the cursor as a wiki name anyway.
540 564
 
  565
+<LocalLeader>ve ... |:VikiEdit| edit a viki page
  566
+
541 567
 <LocalLeader><c-r> or <LocalLeader>vs ... Open in a new window
542 568
 <LocalLeader>vv ... Open in a new window but split vertically
543 569
     - see also |vikiSplit|
@@ -557,8 +583,8 @@ If |g:vikiMapMouse| is true then these mappings are active, too:
557 583
 
558 584
 Additional Key Binding In Full Viki Mode
559 585
 
560  
-<c-tab>    ... |:VikiFindNext|
561  
-<s-c-tab>  ... |:VikiFindPrev|
  586
+<c-tab>, <LocalLeader>vn   ... |:VikiFindNext|
  587
+<s-c-tab>, <LocalLeader>vN ... |:VikiFindPrev|
562 588
 
563 589
 
564 590
 ================================================================================
@@ -591,13 +617,18 @@ Commands~
591 617
   Mark selected text as a quoted simple viki name, i.e., enclose it in 
592 618
   [- and -].
593 619
 
594  
-- VikiEdit NAME                                     *:VikiEdit*
595  
-  Edit the wiki page called NAME. This is a convenient way to edit any wiki 
596  
-  page from vim's command line. There are a few gotchas, though:
  620
+- VikiEdit[!] NAME                                     *:VikiEdit*
  621
+  Edit the wiki page called NAME. If the NAME is '*', the |viki-homepage| will 
  622
+  be opened. This is a convenient way to edit any wiki page from vim's command 
  623
+  line. If you call :VikiEdit! (with bang), the homepage will be opened first, 
  624
+  so that the homepage's customizations (and not the current buffer's one) are 
  625
+  in effect. There are a few gotchas:
597 626
 
598 627
   1. Viki doesn't define a default directory for wiki pages. Thus a wiki page 
599 628
   will be looked for in the directory of the current buffer -- whatever this 
600  
-  is. You can circumvent this problem by using |interviki| names.
  629
+  is -- and the customizations of this buffer are in effect. You can 
  630
+  circumvent this problem by using |interviki| names or define a 
  631
+  |viki-homepage| and call :VikiEdit! with a bang.
601 632
 
602 633
   2. Viki relies on some buffer local variables to be set. As customizability 
603 634
   is one viki's main design goal (although, one might want to discuss whether 
@@ -607,8 +638,14 @@ Commands~
607 638
   wiki page of this type. E.g.: If the current buffer contains a LaTeX file, 
608 639
   |vikiFamily| is most likely set to "LaTeX" (see |viki-latex|). For the LaTeX 
609 640
   family, e.g., CamelCase and interwiki names are disabled. Consequently, you 
610  
-  can't do, e.g., ":VikiEdit IDEAS::WikiPage".
  641
+  can't do, e.g., ":VikiEdit IDEAS::WikiPage". Again, you can circumvent this 
  642
+  problem by defining a |viki-homepage| and call :VikiEdit! with a bang.
  643
+
  644
+- VikiHome                                          *:VikiHome*
  645
+  Open the |viki-homepage|.
611 646
 
  647
+- VikiDefine NAME BASE ?SUFFIX                      *:VikiDefine*
  648
+    Define an interviki.
612 649
 
613 650
 ================================================================================
614 651
                                                     *viki-functions*
@@ -675,6 +712,12 @@ Functions~
675 712
                                                     *viki-variables*
676 713
 Variables~
677 714
 
  715
+Homepage:                                           *viki-homepage*
  716
+                                                    *g:vikiHomePage*
  717
+- g:vikiHomePage:
  718
+    An absolute filename that is the general viki homepage (see also 
  719
+    |:VikiEdit| and |:VikiHome|).
  720
+
678 721
 Simple Viki Names [2]:                              *viki-vars-simple-names*
679 722
                                                     *g:vikiLowerCharacters* 
680 723
                                                     *g:vikiUpperCharacters*
@@ -842,6 +885,14 @@ Etc:
842 885
     Disable certain viki name types (see |vikiNameTypes|).
843 886
     E.g., in order to disable CamelCase names only, set this variable to 'c'.
844 887
 
  888
+- g:vikiHide                                        *g:vikiHide*
  889
+    Default: ''
  890
+    If a dirty buffers gets hidden, vim usually complains. This can be 
  891
+    tiresome -- depending on your editing habits. When this variable is set to 
  892
+    "hide", vim won't complain. If you set it to "update", a viki buffer will 
  893
+    be automatically updated before editing a different file.  If you leave 
  894
+    this empty (""), the default behaviour is in effect. See also |hidden|.
  895
+
845 896
 
846 897
 ================================================================================
847 898
                                                     *viki-highlight*
15  indent/viki.vim
@@ -3,8 +3,8 @@
3 3
 " @Website:     http://members.a1.net/t.link/
4 4
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 5
 " @Created:     16-Jän-2004.
6  
-" @Last Change: 01-Okt-2005.
7  
-" @Revision: 0.216
  6
+" @Last Change: 29-Okt-2005.
  7
+" @Revision: 0.222
8 8
 
9 9
 if !g:vikiEnabled
10 10
     finish
@@ -82,14 +82,16 @@ fun! VikiGetIndent()
82 82
 
83 83
         let markRx = '^\s\+\([#?!+]\)\1\{2,2}\s\+'
84 84
         let listRx = '^\s\+\([-+*#?@]\|[0-9#]\+\.\|[a-zA-Z?]\.\)\s\+'
  85
+        let priRx  = '^\s\+#[A-F]\d\? \+[x_] \+'
85 86
         let descRx = '^\s\+.\{-1,}\s::\s\+'
86 87
         
87 88
         let clMark = matchend(cline, markRx)
88 89
         let clList = matchend(cline, listRx)
  90
+        let clPri  = matchend(cline, priRx)
89 91
         let clDesc = matchend(cline, descRx)
90 92
         " let cln    = clList >= 0 ? clList : clDesc
91 93
 
92  
-        if clList >= 0 || clDesc >= 0 || clMark >= 0
  94
+        if clList >= 0 || clDesc >= 0 || clMark >= 0 || clPri >= 0
93 95
             let spaceEnd = matchend(cline, '^\s\+')
94 96
             let rv = (spaceEnd / &sw) * &sw
95 97
             " echom "DBG clList=". clList ." clDesc=". clDesc
@@ -101,12 +103,17 @@ fun! VikiGetIndent()
101 103
             endif
102 104
             
103 105
             let plList = matchend(pline, listRx)
104  
-            " echom "DBG plList=". plList ." plDesc=". plDesc
105 106
             if plList >= 0
106 107
                 " echom "DBG plList ". plList ." ". pline
107 108
                 return plList
108 109
             endif
109 110
 
  111
+            let plPri = matchend(pline, priRx)
  112
+            " echom "DBG plPri=". plPri
  113
+            if plPri >= 0
  114
+                return plPri
  115
+            endif
  116
+
110 117
             let plDesc = matchend(pline, descRx)
111 118
             if plDesc >= 0
112 119
                 " echom "DBG plDesc ". pind + (&sw / 2)
465  plugin/viki.vim
@@ -2,8 +2,8 @@
2 2
 " @Author:      Thomas Link (samul AT web.de)
3 3
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
4 4
 " @Created:     08-Dec-2003.
5  
-" @Last Change: 01-Okt-2005.
6  
-" @Revision: 1.6.3.101
  5
+" @Last Change: 31-Okt-2005.
  6
+" @Revision: 1.7.314
7 7
 "
8 8
 " vimscript #861
9 9
 "
@@ -23,6 +23,8 @@
23 23
 " - kpsewhich (not a vim plugin :-) for vikiLaTeX
24 24
 "
25 25
 " TODO:
  26
+" - PIM or planner mode features (or rather make it an extra plugin)
  27
+"   - Special plan:// or rather pim:// urls
26 28
 " - VikiRename: rename links/files
27 29
 " - don't know how to deal with viki names that span several lines (e.g. 
28 30
 "   in LaTeX mode)
@@ -40,7 +42,7 @@ if !exists("loaded_multvals") || loaded_multvals < 308
40 42
     echoerr "Viki.vim requires multvals.vim >= 308"
41 43
     finish
42 44
 endif
43  
-let loaded_viki = 106
  45
+let loaded_viki = 107
44 46
 
45 47
 let g:vikiDefNil  = ''
46 48
 let g:vikiDefSep  = "\n"
@@ -111,13 +113,17 @@ if !exists("g:vikiDirSeparator")     | let g:vikiDirSeparator = "/"     | endif
111 113
 if !exists("g:vikiTextstylesVer")    | let g:vikiTextstylesVer = 2      | endif "{{{2
112 114
 if !exists("g:vikiBasicSyntax")      | let g:vikiBasicSyntax = 0        | endif "{{{2
113 115
 if !exists("g:vikiFolds")            | let g:vikiFolds = 'h'            | endif "{{{2
  116
+if !exists("g:vikiFancyHeadings")    | let g:vikiFancyHeadings = 0      | endif "{{{2
  117
+if !exists("g:vikiHomePage")         | let g:vikiHomePage = ''          | endif "{{{2
  118
+if !exists("g:vikiHide")             | let g:vikiHide = ''              | endif "{{{2
114 119
 
115 120
 if !exists("g:vikiMapFunctionality") "{{{2
116 121
     " f ... follow link
117 122
     " i ... check for inexistant
118 123
     " q ... quote
119 124
     " b ... go back
120  
-    let g:vikiMapFunctionality = "fiqbF"
  125
+    " e ... edit
  126
+    let g:vikiMapFunctionality = "fiqbFe"
121 127
 endif
122 128
 
123 129
 if !exists("g:vikiOpenFileWith_ANY") "{{{2
@@ -141,12 +147,12 @@ if !exists("*VikiOpenSpecialFile") "{{{2
141 147
             let prot = ''
142 148
         endif
143 149
         if prot != ''
144  
-            let openFile = VikiSubstituteArgs(prot, "FILE", escape(a:file, ' '))
  150
+            let openFile = VikiSubstituteArgs(prot, "FILE", escape(a:file, ' %&'))
145 151
             exec openFile
146 152
         else
147 153
             throw "Viki: Please define g:vikiOpenFileWith_". proto ." or g:vikiOpenFileWith_ANY!"
148 154
         endif
149  
-    endfun
  155
+    endf
150 156
 endif
151 157
 
152 158
 if !exists("g:vikiOpenUrlWith_mailbox") "{{{2
@@ -159,7 +165,7 @@ if !exists("g:vikiOpenUrlWith_mailbox") "{{{2
159 165
         else
160 166
             throw "Viki: Can't find mailbox url: ".filename
161 167
         endif
162  
-    endfun
  168
+    endf
163 169
 endif
164 170
 
165 171
 " Possible values: special*, query, normal
@@ -189,7 +195,7 @@ if !exists("g:vikiOpenUrlWith_file") "{{{2
189 195
         else
190 196
             throw "Viki: Can't find file url: ".filename
191 197
         endif
192  
-    endfun
  198
+    endf
193 199
 endif
194 200
 
195 201
 if !exists("g:vikiOpenUrlWith_ANY") "{{{2
@@ -213,15 +219,25 @@ if !exists("*VikiOpenSpecialProtocol") "{{{2
213 219
         endif
214 220
         if protp
215 221
             exec "let openURL = ". prot
216  
-            let openURL = VikiSubstituteArgs(openURL, "URL", a:url)
  222
+            let openURL = VikiSubstituteArgs(openURL, "URL", escape(a:url, ' &%'))
217 223
             exec openURL
218 224
         else
219 225
             throw "Viki: Please define g:vikiOpenUrlWith_". proto ." or g:vikiOpenUrlWith_ANY!"
220 226
         endif
221  
-    endfun
  227
+    endf
222 228
 endif
223 229
 
224 230
 let s:InterVikiRx = '^\(['. g:vikiUpperCharacters .']\+\)::\(.\+\)$'
  231
+let s:InterVikis  = ''
  232
+
  233
+" VikiDefine(name, prefix, ?suffix=g:vikiNameSuffix)
  234
+fun! VikiDefine(name, prefix, ...)
  235
+    let s:InterVikis = s:InterVikis . a:name ."::\n"
  236
+    let g:vikiInter{a:name}          = a:prefix
  237
+    let g:vikiInter{a:name}_suffix   = a:0 >= 1 ? a:1 : g:vikiNameSuffix
  238
+endf
  239
+
  240
+command! -nargs=+ VikiDefine call VikiDefine(<f-args>)
225 241
 
226 242
 fun! <SID>AddToRegexp(regexp, pattern) "{{{3
227 243
     if a:pattern == ""
@@ -231,7 +247,7 @@ fun! <SID>AddToRegexp(regexp, pattern) "{{{3
231 247
     else
232 248
         return a:regexp .'\|'. a:pattern
233 249
     endif
234  
-endfun
  250
+endf
235 251
 
236 252
 fun! <SID>VikiFindRx() "{{{3
237 253
     let rx = <SID>AddToRegexp("", b:vikiSimpleNameSimpleRx)
@@ -240,27 +256,49 @@ fun! <SID>VikiFindRx() "{{{3
240 256
     return rx
241 257
 endf
242 258
 
  259
+fun! <SID>EditWrapper(cmd, fname) "{{{3
  260
+    if g:vikiHide == 'hide'
  261
+        exec 'hide '. a:cmd .' '. a:fname
  262
+    elseif g:vikiHide == 'update'
  263
+        update
  264
+        exec a:cmd .' '. a:fname
  265
+    else
  266
+        try
  267
+            exec a:cmd .' '. a:fname
  268
+        catch /^Vim\%((\a\+)\)\=:E37/
  269
+            echoerr 'Vim raised E37: You tried to abondon a dirty buffer (see :h E37)'
  270
+            echoerr 'Viki: You may want to reconsider your g:vikiHide or 'hidden' settings'
  271
+        endtry
  272
+    endif
  273
+endf
  274
+
243 275
 fun! VikiFind(flag) "{{{3
244 276
     let rx = <SID>VikiFindRx()
245 277
     if rx != ""
246 278
         call search(rx, a:flag)
247 279
     endif
248  
-endfun
  280
+endf
249 281
 
250  
-command! VikiFindNext call VikiDispatchOnFamily("VikiFind", "")
251  
-command! VikiFindPrev call VikiDispatchOnFamily("VikiFind", "b")
  282
+command! VikiFindNext call VikiDispatchOnFamily('VikiFind', '')
  283
+command! VikiFindPrev call VikiDispatchOnFamily('VikiFind', 'b')
252 284
 
253  
-fun! <SID>IsSupportedType(type)
254  
-    " return stridx(b:vikiNameTypes, a:type) >= 0
255  
-    return b:vikiNameTypes =~# '['. a:type .']'
  285
+" <SID>IsSupportedType(type, ?types=b:vikiNameTypes)
  286
+fun! <SID>IsSupportedType(type, ...)
  287
+    let types = a:0 >= 1 ? a:1 : b:vikiNameTypes
  288
+    if types == ''
  289
+        return 1
  290
+    else
  291
+        " return stridx(b:vikiNameTypes, a:type) >= 0
  292
+        return b:vikiNameTypes =~# '['. a:type .']'
  293
+    endif
256 294
 endf
257 295
 
258 296
 fun! <SID>VikiRxFromCollection(coll)
259 297
     " let rx = strpart(a:coll, 0, strlen(a:coll) - 1)
260 298
     " let rx = substitute(rx, "\n", '\\|', "g")
261  
-    let rx = substitute(a:coll, '\\|$', '', "")
262  
-    if rx == ""
263  
-        return ""
  299
+    let rx = substitute(a:coll, '\\|$', '', '')
  300
+    if rx == ''
  301
+        return ''
264 302
     else
265 303
         return '\V\('. rx .'\)'
266 304
     endif
@@ -270,76 +308,76 @@ endf
270 308
 " maxcol ... check only up to maxcol
271 309
 " quick  ... check only if the cursor is located after a link
272 310
 fun! <SID>VikiMarkInexistent(line1, line2, ...)
273  
-    let li0 = line(".")
274  
-    let co0 = virtcol(".")
  311
+    let li0 = line('.')
  312
+    let co0 = virtcol('.')
275 313
     let li  = li0
276  
-    let co  = col(".")
277  
-    if a:0 >= 2 && a:2 && !(synIDattr(synID(li, co - 1, 1), "name") =~ '^viki.*Link$')
  314
+    let co  = col('.')
  315
+    if a:0 >= 2 && a:2 && !(synIDattr(synID(li, co - 1, 1), 'name') =~ '^viki.*Link$')
278 316
         return
279 317
     endif
280 318
 
281 319
     let maxcol = a:0 >= 1 ? (a:1 == -1 ? 9999999 : a:1) : 9999999
282 320
     
283 321
     if a:line1 > 0
284  
-        exe "norm! ". a:line1 ."G"
  322
+        exe 'norm! '. a:line1 .'G'
285 323
         let min = a:line1
286 324
     else
287 325
         go
288 326
         let min = 1
289 327
     endif
290  
-    let max = a:line2 > 0 ? a:line2 : line("$")
  328
+    let max = a:line2 > 0 ? a:line2 : line('$')
291 329
 
292  
-    if line(".") == 1 && line("$") == max
293  
-        let b:vikiNamesNull = ""
294  
-        let b:vikiNamesOk   = ""
  330
+    if line('.') == 1 && line('$') == max
  331
+        let b:vikiNamesNull = ''
  332
+        let b:vikiNamesOk   = ''
295 333
     else
296  
-        if !exists("b:vikiNamesNull") | let b:vikiNamesNull = "" | endif
297  
-        if !exists("b:vikiNamesOk")   | let b:vikiNamesOk   = "" | endif
  334
+        if !exists('b:vikiNamesNull') | let b:vikiNamesNull = '' | endif
  335
+        if !exists('b:vikiNamesOk')   | let b:vikiNamesOk   = '' | endif
298 336
     endif
299 337
 
300 338
     try
301 339
         let feedback = (max - min) > 5
302 340
         if feedback
303 341
             let sl  = &statusline
304  
-            let rng = min ."-". max
305  
-            let &statusline="Viki: checking line ". rng
306  
-            let rng = " (". min ."-". max .")"
  342
+            let rng = min .'-'. max
  343
+            let &statusline='Viki: checking line '. rng
  344
+            let rng = ' ('. min .'-'. max .')'
307 345
             redrawstatus
308 346
         endif
309 347
 
310  
-        if line(".") == 1
  348
+        if line('.') == 1
311 349
             norm! G$
312 350
         else
313 351
             norm! k$
314 352
         endif
315 353
 
316 354
         let rx = <SID>VikiFindRx()
317  
-        let t  = search(rx, "w")
  355
+        let t  = search(rx, 'w')
318 356
         let pp = 0
319 357
         let ll = 0
320  
-        while t >= min && t <= max && col(".") < maxcol
  358
+        while t >= min && t <= max && col('.') < maxcol
321 359
             if feedback
322  
-                let li = line(".")
  360
+                let li = line('.')
323 361
                 if li % 10 == 0 && li != ll
324  
-                    let &statusline="Viki: checking line ". line(".") . rng
  362
+                    let &statusline='Viki: checking line '. line('.') . rng
325 363
                     redrawstatus
326 364
                     let ll = li
327 365
                 endif
328 366
             endif
329  
-            let def = VikiGetLink("-", 1)
330  
-            if def == "-"
331  
-                echom "Internal error: VikiMarkInexistent: ". def
  367
+            let def = VikiGetLink('-', 1)
  368
+            if def == '-'
  369
+                echom 'Internal error: VikiMarkInexistent: '. def
332 370
             else
333 371
                 let dest = MvElementAt(def, g:vikiDefSep, 1)
334 372
                 let part = MvElementAt(def, g:vikiDefSep, 3)
335  
-                if part =~ "^". b:vikiSimpleNameSimpleRx ."$"
  373
+                if part =~ '^'. b:vikiSimpleNameSimpleRx .'$'
336 374
                     let check = 1
337 375
                     if part =~ '^\[-.*-\]$'
338 376
                         let partx = escape(part, "'\"\\/")
339 377
                     else
340 378
                         let partx = '\<'. escape(part, "'\"\\/") .'\>'
341 379
                     endif
342  
-                elseif dest =~ "^". b:vikiUrlSimpleRx ."$"
  380
+                elseif dest =~ '^'. b:vikiUrlSimpleRx .'$'
343 381
                     let check = 0
344 382
                     let partx = escape(part, "'\"\\/")
345 383
                     let b:vikiNamesNull = MvRemoveElementAll(b:vikiNamesNull, '\\|', partx, '\|')
@@ -366,19 +404,19 @@ fun! <SID>VikiMarkInexistent(line1, line2, ...)
366 404
                     endif
367 405
                 endif
368 406
             endif
369  
-            let t = search(rx, "W")
  407
+            let t = search(rx, 'W')
370 408
         endwh
371 409
         if b:vikiMarkInexistent == 1
372 410
             exe 'syntax clear '. b:vikiInexistentHighlight
373 411
             let rx = <SID>VikiRxFromCollection(b:vikiNamesNull)
374  
-            if rx != ""
  412
+            if rx != ''
375 413
                 exe 'syntax match '. b:vikiInexistentHighlight .' /'. rx .'/'
376 414
             endif
377 415
         elseif  b:vikiMarkInexistent == 2
378 416
             syntax clear vikiOkLink
379 417
             syntax clear vikiExtendedOkLink
380 418
             let rx = <SID>VikiRxFromCollection(b:vikiNamesOk)
381  
-            if rx != ""
  419
+            if rx != ''
382 420
                 exe 'syntax match vikiOkLink /'. rx .'/'
383 421
             endif
384 422
         endif
@@ -387,9 +425,9 @@ fun! <SID>VikiMarkInexistent(line1, line2, ...)
387 425
             let &statusline=sl
388 426
         endif
389 427
     endtry
390  
-    exe "norm! ". li0 ."G". co0 ."|"
  428
+    exe 'norm! '. li0 .'G'. co0 .'|'
391 429
     let b:vikiCheckInexistent = 0
392  
-endfun
  430
+endf
393 431
 
394 432
 command! -nargs=* -range=% VikiMarkInexistent call <SID>VikiMarkInexistent(<line1>, <line2>, <f-args>)
395 433
 command! VikiMarkInexistentInParagraph '{,'}VikiMarkInexistent
@@ -405,7 +443,7 @@ fun! VikiCheckInexistent()
405 443
         " VikiMarkInexistent
406 444
         " VikiMarkInexistentInParagraph
407 445
     endif
408  
-endfun
  446
+endf
409 447
 
410 448
 " autocmd VimLeavePre * let g:vikiMarkInexistent = 0
411 449
 autocmd VimLeavePre * let g:vikiEnabled = 0
@@ -432,7 +470,7 @@ fun! VikiSetBufferVar(name, ...) "{{{3
432 470
             exe "let b:".a:name." = g:".a:name
433 471
         endif
434 472
     endif
435  
-endfun
  473
+endf
436 474
 
437 475
 fun! <SID>VikiLetVar(name, var) "{{{3
438 476
     if exists("b:".a:var)
@@ -442,7 +480,7 @@ fun! <SID>VikiLetVar(name, var) "{{{3
442 480
     else
443 481
         return ""
444 482
     endif
445  
-endfun
  483
+endf
446 484
 
447 485
 fun! VikiDispatchOnFamily(fn, ...) "{{{3
448 486
     let fam = exists("b:vikiFamily") ? b:vikiFamily : g:vikiFamily
@@ -464,7 +502,7 @@ fun! VikiDispatchOnFamily(fn, ...) "{{{3
464 502
         let i = i + 1
465 503
     endwh
466 504
     exe "return ". cmd . "(" . args . ")"
467  
-endfun
  505
+endf
468 506
 
469 507
 fun! VikiSetupBuffer(state, ...) "{{{3
470 508
     if !g:vikiEnabled
@@ -487,6 +525,9 @@ fun! VikiSetupBuffer(state, ...) "{{{3
487 525
     call VikiSetBufferVar("vikiSpecialProtocolsExceptions")
488 526
     call VikiSetBufferVar("vikiMarkInexistent")
489 527
     call VikiSetBufferVar("vikiTextstylesVer")
  528
+    call VikiSetBufferVar("vikiTextstylesVer")
  529
+    call VikiSetBufferVar("vikiLowerCharacters")
  530
+    call VikiSetBufferVar("vikiUpperCharacters")
490 531
 
491 532
     if a:state =~ '1$'
492 533
         call VikiSetBufferVar("vikiCommentStart", 
@@ -504,8 +545,8 @@ fun! VikiSetupBuffer(state, ...) "{{{3
504 545
     let b:vikiQuotedSelfRef        = "^". b:vikiSimpleNameQuoteBeg . b:vikiSimpleNameQuoteEnd ."$"
505 546
     let b:vikiQuotedRef            = "^". b:vikiSimpleNameQuoteBeg .'.\+'. b:vikiSimpleNameQuoteEnd ."$"
506 547
 
507  
-    let b:vikiAnchorNameRx         = '['. g:vikiLowerCharacters .']['. 
508  
-                \ g:vikiLowerCharacters . g:vikiUpperCharacters .'_0-9]\+'
  548
+    let b:vikiAnchorNameRx         = '['. b:vikiLowerCharacters .']['. 
  549
+                \ b:vikiLowerCharacters . b:vikiUpperCharacters .'_0-9]\+'
509 550
     
510 551
     if <SID>IsSupportedType("sSc") && !(dontSetup =~? "s")
511 552
         if <SID>IsSupportedType("S") && !(dontSetup =~# "S")
@@ -516,19 +557,17 @@ fun! VikiSetupBuffer(state, ...) "{{{3
516 557
             let quotedVikiName = ""
517 558
         endif
518 559
         if <SID>IsSupportedType("c") && !(dontSetup =~# "c")
519  
-            let simpleWikiName = '\<['. g:vikiUpperCharacters .']['. g:vikiLowerCharacters
520  
-                        \ .']\+\(['. g:vikiUpperCharacters.']['.g:vikiLowerCharacters
521  
-                        \ .'0-9]\+\)\+\>'
  560
+            let simpleWikiName = <SID>GetSimpleRx4SimpleWikiName()
522 561
             if quotedVikiName != ""
523 562
                 let quotedVikiName = quotedVikiName .'\|'
524 563
             endif
525 564
         else
526 565
             let simpleWikiName = ""
527 566
         endif
528  
-        let b:vikiSimpleNameRx = '\C\(\(\<['. g:vikiUpperCharacters .']\+::\)\?'
  567
+        let b:vikiSimpleNameRx = '\C\(\(\<['. b:vikiUpperCharacters .']\+::\)\?'
529 568
                     \ .'\('. quotedVikiName . simpleWikiName .'\)\)'
530 569
                     \ .'\(#\('. b:vikiAnchorNameRx .'\)\>\)\?'
531  
-        let b:vikiSimpleNameSimpleRx = '\C\(\<['.g:vikiUpperCharacters.']\+::\)\?'
  570
+        let b:vikiSimpleNameSimpleRx = '\C\(\<['.b:vikiUpperCharacters.']\+::\)\?'
532 571
                     \ .'\('. quotedVikiName . simpleWikiName .'\)'
533 572
                     \ .'\(#'. b:vikiAnchorNameRx .'\>\)\?'
534 573
         let b:vikiSimpleNameNameIdx   = 1
@@ -568,8 +607,8 @@ fun! VikiSetupBuffer(state, ...) "{{{3
568 607
     endif
569 608
    
570 609
     if <SID>IsSupportedType("x") && !(dontSetup =~# "x")
571  
-        let b:vikiCmdRx        = '\({\S\+\|#['. g:vikiUpperCharacters .']\w*\)\(.\{-}\):\s*\(.\{-}\)\($\|}\)'
572  
-        let b:vikiCmdSimpleRx  = '\({\S\+\|#['. g:vikiUpperCharacters .']\w*\).\{-}\($\|}\)'
  610
+        let b:vikiCmdRx        = '\({\S\+\|#['. b:vikiUpperCharacters .']\w*\)\(.\{-}\):\s*\(.\{-}\)\($\|}\)'
  611
+        let b:vikiCmdSimpleRx  = '\({\S\+\|#['. b:vikiUpperCharacters .']\w*\).\{-}\($\|}\)'
573 612
         let b:vikiCmdNameIdx   = 1
574 613
         let b:vikiCmdDestIdx   = 3
575 614
         let b:vikiCmdAnchorIdx = 2
@@ -606,19 +645,26 @@ fun! VikiSetupBuffer(state, ...) "{{{3
606 645
     endif
607 646
 
608 647
     let b:vikiInexistentHighlight = "vikiInexistentLink"
609  
-endfun
  648
+endf
610 649
 
611 650
 fun! VikiDefineMarkup(state) "{{{3
612  
-    if <SID>IsSupportedType("sS") && b:vikiSimpleNameRx != ""
613  
-        exe "syntax match vikiLink /" . b:vikiSimpleNameRx . "/"
  651
+    if <SID>IsSupportedType("sS") && b:vikiSimpleNameSimpleRx != ""
  652
+        exe "syntax match vikiLink /" . b:vikiSimpleNameSimpleRx . "/"
614 653
     endif
615  
-    if <SID>IsSupportedType("e") && b:vikiExtendedNameRx != ""
616  
-        exe "syntax match vikiExtendedLink '" . b:vikiExtendedNameRx . "' skipnl"
  654
+    if <SID>IsSupportedType("e") && b:vikiExtendedNameSimpleRx != ""
  655
+        exe "syntax match vikiExtendedLink '" . b:vikiExtendedNameSimpleRx . "' skipnl"
617 656
     endif
618  
-    if <SID>IsSupportedType("u") && b:vikiUrlRx != ""
619  
-        exe "syntax match vikiURL /" . b:vikiUrlRx . "/"
  657
+    if <SID>IsSupportedType("u") && b:vikiUrlSimpleRx != ""
  658
+        exe "syntax match vikiURL /" . b:vikiUrlSimpleRx . "/"
620 659
     endif
621  
-endfun
  660
+endf
  661
+
  662
+fun! <SID>GetSimpleRx4SimpleWikiName()
  663
+    let upper = exists('b:vikiUpperCharacters') ? b:vikiUpperCharacters : g:vikiUpperCharacters
  664
+    let lower = exists('b:vikiLowerCharacters') ? b:vikiLowerCharacters : g:vikiLowerCharacters
  665
+    let simpleWikiName = '\<['.upper.']['.lower.']\+\(['.upper.']['.lower.'0-9]\+\)\+\>'
  666
+    return simpleWikiName
  667
+endf
622 668
 
623 669
 fun! VikiDefineHighlighting(state) "{{{3
624 670
     if version < 508
@@ -646,7 +692,7 @@ fun! VikiDefineHighlighting(state) "{{{3
646 692
         VikiHiLink vikiURL vikiHyperLink
647 693
     endif
648 694
     delcommand VikiHiLink
649  
-endfun
  695
+endf
650 696
 
651 697
 fun! <SID>MapMarkInexistent(key, element, insert, before)
652 698
     let arg = maparg(a:key, "i")
@@ -692,6 +738,9 @@ fun! VikiMapKeys(state)
692 738
         "nnoremap <buffer> <s-c-cr> :call VikiMaybeFollowLink(0,1)<cr>
693 739
         "inoremap <buffer> <s-c-cr> <c-o><c-cr>
694 740
     endif
  741
+    if mf =~# 'e' && !hasmapto("VikiEdit")
  742
+        noremap <buffer> <LocalLeader>ve :VikiEdit 
  743
+    endif
695 744
     if mf =~# 'i' && !hasmapto("VikiMarkInexistent")
696 745
         noremap <buffer> <silent> <LocalLeader>vd :VikiMarkInexistent<cr>
697 746
         noremap <buffer> <silent> <LocalLeader>vp :VikiMarkInexistentInParagraph<cr>
@@ -758,7 +807,7 @@ fun! VikiMinorMode(state) "{{{3
758 807
         let b:vikiEnabled = 1
759 808
         return 1
760 809
     endif
761  
-endfun
  810
+endf
762 811
 
763 812
 command! VikiMinorMode call VikiMinorMode(1)
764 813
 command! VikiMinorModeMaybe call VikiMinorMode(-1)
@@ -775,7 +824,7 @@ fun! VikiMode(state) "{{{3
775 824
     elseif a:state
776 825
         set filetype=viki
777 826
     endif
778  
-endfun
  827
+endf
779 828
 
780 829
 command! VikiMode call VikiMode(2)
781 830
 command! VikiModeMaybe call VikiMode(-2)
@@ -789,7 +838,7 @@ fun! <SID>AddVarToMultVal(var, val) "{{{3
789 838
         exe "let ". a:var ."=MvAddElement('', '". g:vikiDefSep ."', ". a:val .")"
790 839
         return -1
791 840
     endif
792  
-endfun
  841
+endf
793 842
 
794 843
 fun! VikiIsInRegion(line)
795 844
     let i   = 0
@@ -801,7 +850,7 @@ fun! VikiIsInRegion(line)
801 850
         let i = i + 1
802 851
     endw
803 852
     return 0
804  
-endfun
  853
+endf
805 854
 
806 855
 fun! <SID>VikiSetBackRef(file, li, co) "{{{3
807 856
     let i = <SID>AddVarToMultVal("b:VikiBackFile", "'". a:file ."'")
@@ -812,7 +861,7 @@ fun! <SID>VikiSetBackRef(file, li, co) "{{{3
812 861
         call <SID>AddVarToMultVal("b:VikiBackLine", a:li)
813 862
         call <SID>AddVarToMultVal("b:VikiBackCol",  a:co)
814 863
     endif
815  
-endfun
  864
+endf
816 865
 
817 866
 fun! VikiSelect(array, seperator, queryString) "{{{3
818 867
     let n = MvNumberOfElements(a:array, a:seperator)
@@ -843,13 +892,13 @@ fun! VikiSelect(array, seperator, queryString) "{{{3
843 892
         endif
844 893
     endif
845 894
     return -1
846  
-endfun
  895
+endf
847 896
 
848 897
 fun! <SID>VikiSelectThisBackRef(n) "{{{3
849 898
     return "let vbf = '". MvElementAt(b:VikiBackFile, g:vikiDefSep, a:n) ."'".
850 899
                 \ " | let vbl = ". MvElementAt(b:VikiBackLine, g:vikiDefSep, a:n) .
851 900
                 \ " | let vbc = ". MvElementAt(b:VikiBackCol, g:vikiDefSep, a:n)
852  
-endfun
  901
+endf
853 902
 
854 903
 fun! <SID>VikiSelectBackRef(...) "{{{3
855 904
     if exists("b:VikiBackFile") && exists("b:VikiBackLine") && exists("b:VikiBackCol")
@@ -863,12 +912,12 @@ fun! <SID>VikiSelectBackRef(...) "{{{3
863 912
         endif
864 913
     endif
865 914
     return ""
866  
-endfun
  915
+endf
867 916
 
868 917
 if g:vikiSaveHistory && exists("*GetPersistentVar") && exists("*PutPersistentVar") "{{{2
869 918
     fun! VikiGetSimplifiedBufferName() "{{{3
870 919
         return substitute( expand("%:p"), "[^a-zA-Z0-9]", "_", "g")
871  
-    endfun
  920
+    endf
872 921
     
873 922
     fun! VikiSaveBackReferences() "{{{3
874 923
         if exists("b:VikiBackFile") && b:VikiBackFile != ""
@@ -876,7 +925,7 @@ if g:vikiSaveHistory && exists("*GetPersistentVar") && exists("*PutPersistentVar
876 925
             call PutPersistentVar("VikiBackLine", VikiGetSimplifiedBufferName(), b:VikiBackLine)
877 926
             call PutPersistentVar("VikiBackCol",  VikiGetSimplifiedBufferName(), b:VikiBackCol)
878 927
         endif
879  
-    endfun
  928
+    endf
880 929
     
881 930
     fun! VikiRestoreBackReferences() "{{{3
882 931
         if exists("b:vikiEnabled") && !exists("b:VikiBackFile")
@@ -884,7 +933,7 @@ if g:vikiSaveHistory && exists("*GetPersistentVar") && exists("*PutPersistentVar
884 933
             let b:VikiBackLine = GetPersistentVar("VikiBackLine", VikiGetSimplifiedBufferName(), "")
885 934
             let b:VikiBackCol  = GetPersistentVar("VikiBackCol",  VikiGetSimplifiedBufferName(), "")
886 935
         endif
887  
-    endfun
  936
+    endf
888 937
 
889 938
     au BufEnter * call VikiRestoreBackReferences()
890 939
     au BufLeave * call VikiSaveBackReferences()
@@ -899,9 +948,9 @@ fun! VikiGoBack(...) "{{{3
899 948
         exe br
900 949
         let buf = bufnr("^". vbf ."$")
901 950
         if buf >= 0
902  
-            exe "buffer ".buf
  951
+            call <SID>EditWrapper('buffer', buf)
903 952
         else
904  
-            exe "edit " . vbf
  953
+            call <SID>EditWrapper('edit', vbf)
905 954
         endif
906 955
         if vbf == expand("%:p")
907 956
             call cursor(vbl, vbc)
@@ -909,7 +958,9 @@ fun! VikiGoBack(...) "{{{3
909 958
             throw "Viki: Couldn't open file: ". b:VikiBackFile
910 959
         endif
911 960
     endif
912  
-endfun
  961
+endf
  962
+
  963
+command! -narg=? VikiGoBack call VikiGoBack(<f-args>)
913 964
 
914 965
 fun! VikiSubstituteArgs(str, ...) "{{{3
915 966
     let i  = 1
@@ -917,13 +968,13 @@ fun! VikiSubstituteArgs(str, ...) "{{{3
917 968
     while a:0 >= i
918 969
         exec "let lab = a:". i
919 970
         exec "let val = a:". (i+1)
920  
-        let rv = substitute(rv, '\C\(^\|[^%]\)\zs%{'. lab .'}', escape(val, '\'), "g")
  971
+        let rv = substitute(rv, '\C\(^\|[^%]\)\zs%{'. lab .'}', escape(val, '\&'), "g")
921 972
         let rv = escape(rv, '\')
922 973
         let i = i + 2
923 974
     endwh
924 975
     let rv = substitute(rv, '%%', "%", "g")
925 976
     return rv
926  
-endfun
  977
+endf
927 978
 
928 979
 fun! VikiFindAnchor(anchor) "{{{3
929 980
     if a:anchor != g:vikiDefNil
@@ -943,13 +994,10 @@ fun! VikiFindAnchor(anchor) "{{{3
943 994
             endif
944 995
         endif
945 996
     endif
946  
-endfun
  997
+endf
947 998
 
948  
-fun! VikiOpenLink(filename, anchor, ...) "{{{3
949  
-    let create  = a:0 >= 1 ? a:1 : 0
950  
-    let postcmd = a:0 >= 2 ? a:2 : ""
951  
-    let winNr   = a:0 >= 3 ? a:3 : 0
952  
-    
  999
+fun! VikiGetWinNr(...)
  1000
+    let winNr = a:0 >= 1 ? a:1 : 0
953 1001
     if winNr == 0
954 1002
         if exists("b:vikiSplit")
955 1003
             let winNr = b:vikiSplit
@@ -959,14 +1007,11 @@ fun! VikiOpenLink(filename, anchor, ...) "{{{3
959 1007
             let winNr = 0
960 1008
         endif
961 1009
     endif
  1010
+    return winNr
  1011
+endf
962 1012
 
963  
-    let li = line(".")
964  
-    let co = col(".")
965  
-    let fi = expand("%:p")
966  
-    
967  
-    " let buf = bufnr("^". simplify(a:filename) ."$")
968  
-    let buf = bufnr("^". a:filename ."$")
969  
-    " let buf = bufnr(a:filename)
  1013
+fun! VikiSetWindow(winNr)
  1014
+    let winNr = VikiGetWinNr(a:winNr)
970 1015
     if winNr != 0
971 1016
         let wm = <SID>HowManyWindows()
972 1017
         if winNr == -2
@@ -974,19 +1019,27 @@ fun! VikiOpenLink(filename, anchor, ...) "{{{3
974 1019
         elseif wm == 1 || winNr == -1
975 1020
             wincmd s
976 1021
         else
977  
-            " if winNr == -1
978  
-                " let wc = winnr()
979  
-                " if wc < wm
980  
-                    " let winNr = wc + 1
981  
-                " else
982  
-                    " let winNr = wc - 1
983  
-                " endif
984  
-            " endif
985 1022
             exec winNr ."wincmd w"
986 1023
         end
987 1024
     endif
  1025
+endf
  1026
+
  1027
+" VikiOpenLink(filename, anchor, ?create=0, ?postcmd='', ?wincmd=0)
  1028
+fun! VikiOpenLink(filename, anchor, ...) "{{{3
  1029
+    let create  = a:0 >= 1 ? a:1 : 0
  1030
+    let postcmd = a:0 >= 2 ? a:2 : ""
  1031
+    let winNr   = a:0 >= 3 ? a:3 : b:vikiNextWindow
  1032
+    
  1033
+    let li = line(".")
  1034
+    let co = col(".")
  1035
+    let fi = expand("%:p")
  1036
+    
  1037
+    " let buf = bufnr("^". simplify(a:filename) ."$")
  1038
+    let buf = bufnr("^". a:filename ."$")
  1039
+    " let buf = bufnr(a:filename)
  1040
+    call VikiSetWindow(winNr)
988 1041
     if buf >= 0
989  
-        exe "buffer ".buf
  1042
+        call <SID>EditWrapper('buffer', buf)
990 1043
         call <SID>VikiSetBackRef(fi, li, co)
991 1044
         call VikiDispatchOnFamily("VikiMinorMode", -1)
992 1045
         call VikiDispatchOnFamily("VikiFindAnchor", a:anchor)
@@ -995,7 +1048,7 @@ fun! VikiOpenLink(filename, anchor, ...) "{{{3
995 1048
     elseif exists("b:editVikiPage")
996 1049
         exe b:editVikiPage . " " . a:filename
997 1050
     else
998  
-        exe "edit " . a:filename
  1051
+        call <SID>EditWrapper('edit', a:filename)
999 1052
         set buflisted
1000 1053
         call <SID>VikiSetBackRef(fi, li, co)
1001 1054
         call VikiDispatchOnFamily("VikiMinorMode", -1)
@@ -1004,7 +1057,7 @@ fun! VikiOpenLink(filename, anchor, ...) "{{{3
1004 1057
     if postcmd != ""
1005 1058
         exec postcmd
1006 1059
     endif
1007  
-endfun
  1060
+endf
1008 1061
 
1009 1062
 fun! <SID>HowManyWindows()
1010 1063
     let i = 1
@@ -1040,7 +1093,7 @@ fun! VikiDecomposeUrl(dest) "{{{3
1040 1093
         let rv     = rv
1041 1094
     end
1042 1095
     return "let filename='". rv ."'|let anchor='". anchor ."'|let args='". args ."'"
1043  
-endfun
  1096
+endf
1044 1097
 
1045 1098
 fun! <SID>GetSpecialFilesSuffixes() "{{{3
1046 1099
     if exists("b:vikiSpecialFiles")
@@ -1067,17 +1120,18 @@ fun! <SID>VikiFollowLink(def, ...) "{{{3
1067 1120
     elseif dest == g:vikiDefNil
1068 1121
 		throw "No target? ".a:def
1069 1122
     else
1070  
-        if dest =~ '^\('.b:vikiSpecialProtocols.'\):' &&
1071  
-                    \ (b:vikiSpecialProtocolsExceptions == "" ||
1072  
-                    \ !(dest =~ b:vikiSpecialProtocolsExceptions))
1073  
-            call VikiOpenSpecialProtocol(dest)
1074  
-        else
1075  
-            if VikiIsSpecialFile(dest)
  1123
+        let b:vikiNextWindow = winNr
  1124
+        try
  1125
+            if dest =~ '^\('.b:vikiSpecialProtocols.'\):' &&
  1126
+                        \ (b:vikiSpecialProtocolsExceptions == "" ||
  1127
+                        \ !(dest =~ b:vikiSpecialProtocolsExceptions))
  1128
+                call VikiOpenSpecialProtocol(dest)
  1129
+            elseif VikiIsSpecialFile(dest)
1076 1130
                 call VikiOpenSpecialFile(dest)
1077 1131
             elseif filereadable(dest)                 "reference to a local, already existing file
1078 1132
                 call VikiOpenLink(dest, anchor, 0, "", winNr)
1079 1133
             elseif bufexists(dest)
1080  
-                exec "buffer ". dest
  1134
+                call <SID>EditWrapper('buffer', dest)
1081 1135
             elseif isdirectory(dest)
1082 1136
                 exe g:vikiExplorer ." ". dest
1083 1137
             else
@@ -1087,10 +1141,12 @@ fun! <SID>VikiFollowLink(def, ...) "{{{3
1087 1141
                     call VikiOpenLink(dest, anchor, 1, '', winNr)
1088 1142
                 endif
1089 1143
             endif
1090  
-        endif
  1144
+        finally
  1145
+            let b:vikiNextWindow = 0
  1146
+        endtry
1091 1147
     endif
1092 1148
     return ""
1093  
-endfun
  1149
+endf
1094 1150
 
1095 1151
 fun! <SID>MakeVikiDefPart(txt) "{{{3
1096 1152
     if a:txt == ""
@@ -1098,7 +1154,7 @@ fun! <SID>MakeVikiDefPart(txt) "{{{3
1098 1154
     else
1099 1155
         return a:txt
1100 1156
     endif
1101  
-endfun
  1157
+endf
1102 1158
 
1103 1159
 fun! VikiMakeDef(name, dest, anchor, part) "{{{3
1104 1160
     if a:name =~ g:vikiDefSep || a:dest =~ g:vikiDefSep || a:anchor =~ g:vikiDefSep 
@@ -1112,7 +1168,7 @@ fun! VikiMakeDef(name, dest, anchor, part) "{{{3
1112 1168
         let arr = MvAddElement(arr, g:vikiDefSep, <SID>MakeVikiDefPart(a:part))
1113 1169
         return arr
1114 1170
     endif
1115  
-endfun
  1171
+endf
1116 1172
 
1117 1173
 fun! <SID>GetVikiNamePart(txt, erx, idx, errorMsg) "{{{3
1118 1174
     if a:idx
@@ -1125,7 +1181,7 @@ fun! <SID>GetVikiNamePart(txt, erx, idx, errorMsg) "{{{3
1125 1181
     else
1126 1182
         return g:vikiDefNil
1127 1183
     endif
1128  
-endfun
  1184
+endf
1129 1185
 
1130 1186
 fun! VikiLinkDefinition(txt, col, compound, ignoreSyntax) "{{{3
1131 1187
     exe a:compound
@@ -1156,7 +1212,7 @@ fun! VikiLinkDefinition(txt, col, compound, ignoreSyntax) "{{{3
1156 1212
     else
1157 1213
         return ""
1158 1214
     endif
1159  
-endfun
  1215
+endf
1160 1216
 
1161 1217
 fun! <SID>VikiGetSuffix() "{{{3
1162 1218
     if exists("b:vikiNameSuffix")
@@ -1169,7 +1225,7 @@ fun! <SID>VikiGetSuffix() "{{{3
1169 1225
         endif
1170 1226
     endif
1171 1227
     return g:vikiNameSuffix
1172  
-endfun
  1228
+endf
1173 1229
 
1174 1230
 fun! VikiExpandSimpleName(dest, name, suffix) "{{{3
1175 1231
     if a:suffix == g:vikiDefSep
@@ -1177,7 +1233,7 @@ fun! VikiExpandSimpleName(dest, name, suffix) "{{{3
1177 1233
     else
1178 1234
         return a:dest . g:vikiDirSeparator . a:name . (a:suffix == g:vikiDefSep? "" : a:suffix)
1179 1235
     endif
1180  
-endfun
  1236
+endf
1181 1237
 
1182 1238
 fun! VikiCompleteSimpleNameDef(def) "{{{3
1183 1239
     let name   = MvElementAt(a:def, g:vikiDefSep, 0)
@@ -1223,7 +1279,7 @@ fun! VikiCompleteSimpleNameDef(def) "{{{3
1223 1279
     let anchor = MvElementAt(a:def, g:vikiDefSep, 2)
1224 1280
     let part   = MvElementAt(a:def, g:vikiDefSep, 3)
1225 1281
     return VikiMakeDef(name, rdest, anchor, part)
1226  
-endfun
  1282
+endf
1227 1283
 
1228 1284
 fun! VikiCompleteExtendedNameDef(def) "{{{3
1229 1285
     let name   = MvElementAt(a:def, g:vikiDefSep, 0)
@@ -1253,7 +1309,7 @@ fun! VikiCompleteExtendedNameDef(def) "{{{3
1253 1309
         endif
1254 1310
     endif
1255 1311
     return VikiMakeDef(name, dest, anchor, part)
1256  
-endfun
  1312
+endf
1257 1313
  
1258 1314
 fun! <SID>FindFileWithSuffix(filename, suffixes) "{{{3
1259 1315
     if filereadable(a:filename)
@@ -1311,37 +1367,40 @@ fun! <SID>VikiLinkNotFoundEtc(oldmap, ignoreSyntax) "{{{3
1311 1367
     else
1312 1368
         return a:oldmap
1313 1369
     endif
1314  
-endfun
  1370
+endf
1315 1371
 
1316  
-" VikiGetLink(oldmap, ignoreSyntax, ?col, ?txt)
  1372
+" VikiGetLink(oldmap, ignoreSyntax, ?txt, ?col=0, ?supported=b:vikiNameTypes)
1317 1373
 fun! VikiGetLink(oldmap, ignoreSyntax, ...) "{{{3
1318  
-    let synName = synIDattr(synID(line('.'),col('.'),0),"name")
1319  
-    if synName ==# "vikiLink"
1320  
-        let vikiType = 1
1321  
-        let tryAll   = 0
1322  
-    elseif synName ==# "vikiExtendedLink"
1323  
-        let vikiType = 2
1324  
-        let tryAll   = 0
1325  
-    elseif synName ==# "vikiURL"
1326  
-        let vikiType = 3
1327  
-        let tryAll   = 0
1328  
-    elseif synName ==# "vikiCommand" || synName ==# "vikiMacro"
1329  
-        let vikiType = 4
1330  
-        let tryAll   = 0
1331  
-    elseif a:ignoreSyntax
  1374
+    let col   = a:0 >= 2 ? a:2 : 0
  1375
+    let types = a:0 >= 3 ? a:3 : b:vikiNameTypes
  1376
+    if a:0 >= 1
  1377
+        let txt      = a:1
1332 1378
         let vikiType = a:ignoreSyntax
1333 1379
         let tryAll   = 1
1334 1380
     else
1335  
-        return ""
1336  
-    endif
1337  
-    if a:0 >= 1
1338  
-        let txt = a:1
1339  
-        let col = a:0 >= 2 ? a:2 : 0
1340  
-    else
  1381
+        let synName = synIDattr(synID(line('.'),col('.'),0),"name")
  1382
+        if synName ==# "vikiLink"
  1383
+            let vikiType = 1
  1384
+            let tryAll   = 0
  1385
+        elseif synName ==# "vikiExtendedLink"
  1386
+            let vikiType = 2
  1387
+            let tryAll   = 0
  1388
+        elseif synName ==# "vikiURL"
  1389
+            let vikiType = 3
  1390
+            let tryAll   = 0
  1391
+        elseif synName ==# "vikiCommand" || synName ==# "vikiMacro"
  1392
+            let vikiType = 4
  1393
+            let tryAll   = 0
  1394
+        elseif a:ignoreSyntax
  1395
+            let vikiType = a:ignoreSyntax
  1396
+            let tryAll   = 1
  1397
+        else
  1398
+            return ""
  1399
+        endif
1341 1400
         let txt = getline(".")
1342 1401
         let col = col(".") - 1
1343 1402
     endif
1344  
-    if (tryAll || vikiType == 1) && <SID>IsSupportedType("s")
  1403
+    if (tryAll || vikiType == 1) && <SID>IsSupportedType("s", types)
1345 1404
         if exists("b:getVikiLink")
1346 1405
             exe "let def = " . b:getVikiLink."()"
1347 1406
         else
@@ -1351,7 +1410,7 @@ fun! VikiGetLink(oldmap, ignoreSyntax, ...) "{{{3
1351 1410
             return VikiDispatchOnFamily("VikiCompleteSimpleNameDef", def)
1352 1411
         endif
1353 1412
     endif
1354  
-    if (tryAll || vikiType == 2) && <SID>IsSupportedType("e")
  1413
+    if (tryAll || vikiType == 2) && <SID>IsSupportedType("e", types)
1355 1414
         if exists("b:getExtVikiLink")
1356 1415
             exe "let def = " . b:getExtVikiLink."()"
1357 1416
         else
@@ -1361,7 +1420,7 @@ fun! VikiGetLink(oldmap, ignoreSyntax, ...) "{{{3
1361 1420
             return VikiDispatchOnFamily("VikiCompleteExtendedNameDef", def)
1362 1421
         endif
1363 1422
     endif
1364  
-    if (tryAll || vikiType == 3) && <SID>IsSupportedType("u")
  1423
+    if (tryAll || vikiType == 3) && <SID>IsSupportedType("u", types)
1365 1424
         if exists("b:getURLViki")
1366 1425
             exe "let def = " . b:getURLViki . "()"
1367 1426
         else
@@ -1371,7 +1430,7 @@ fun! VikiGetLink(oldmap, ignoreSyntax, ...) "{{{3
1371 1430
             return VikiDispatchOnFamily("VikiCompleteExtendedNameDef", def)
1372 1431
         endif
1373 1432
     endif
1374  
-    if (tryAll || vikiType == 4) && <SID>IsSupportedType("x")
  1433
+    if (tryAll || vikiType == 4) && <SID>IsSupportedType("x", types)
1375 1434
         if exists("b:getCmdViki")
1376 1435
             exe "let def = " . b:getCmdViki . "()"
1377 1436
         else
@@ -1382,7 +1441,7 @@ fun! VikiGetLink(oldmap, ignoreSyntax, ...) "{{{3
1382 1441
         endif
1383 1442
     endif
1384 1443
     return ""
1385  
-endfun
  1444
+endf
1386 1445
 
1387 1446
 " VikiMaybeFollowLink(oldmap, ignoreSyntax, ?winNr=0)
1388 1447
 fun! VikiMaybeFollowLink(oldmap, ignoreSyntax, ...) "{{{3
@@ -1393,26 +1452,94 @@ fun! VikiMaybeFollowLink(oldmap, ignoreSyntax, ...) "{{{3
1393 1452
     else
1394 1453
         return <SID>VikiLinkNotFoundEtc(a:oldmap, a:ignoreSyntax)
1395 1454
     endif
1396  
-endfun
  1455
+endf
1397 1456
 command! VikiJump call VikiMaybeFollowLink(0,1)
1398 1457
 
  1458
+" VikiEdit(name, ?bang='', ?winNr=0)
1399 1459
 fun! VikiEdit(name, ...) "{{{3
1400  
-    let winNr = a:0 >= 1 ? a:1 : 0
  1460
+    let bang  = a:0 >= 1 ? a:1 : ''
  1461
+    let winNr = a:0 >= 2 ? a:2 : 0
1401 1462
     let ignoreSyntax = 1
1402 1463
     let oldmap = ""
  1464
+    if bang != ''
  1465
+        if g:vikiHomePage != ''
  1466
+            call <SID>EditWrapper('edit', g:vikiHomePage)
  1467
+        else
  1468
+            call <SID>EditWrapper('buffer', 1)
  1469
+        endif
  1470
+    endif
  1471
+    if a:name == '*'
  1472
+        let name = 'file://'. g:vikiHomePage
  1473
+    else
  1474
+        let name = a:name
  1475
+    end
  1476
+    let name = substitute(name, '[\\]', '/', 'g')
1403 1477
     if !exists("b:vikiNameTypes")
1404 1478
         call VikiSetBufferVar("vikiNameTypes")
1405 1479
         call VikiDispatchOnFamily("VikiSetupBuffer", 0)
1406 1480
     endif
1407  
-    let def = VikiGetLink(oldmap, ignoreSyntax, a:name)
  1481
+    let def  = VikiGetLink(oldmap, ignoreSyntax, name, 0, '')
1408 1482
     if def != ""
1409 1483
         return <SID>VikiFollowLink(def, winNr)
1410 1484
     else
1411