forked from lervag/wiki.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wiki.txt
1652 lines (1284 loc) · 62.6 KB
/
wiki.txt
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*wiki.txt* A simple wiki plugin for Vim
*wiki.vim*
Author: Karl Yngve Lervåg <[email protected]>
License: MIT license {{{
Copyright (c) 2021 Karl Yngve Lervåg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The software is provided "as is", without warranty of any kind, express or
implied, including but not limited to the warranties of merchantability,
fitness for a particular purpose and noninfringement. In no event shall the
authors or copyright holders be liable for any claim, damages or other
liability, whether in an action of contract, tort or otherwise, arising
from, out of or in connection with the software or the use or other dealings
in the software.
}}}
==============================================================================
CONTENTS *wiki-contents*
Introduction |wiki-intro|
Requirements |wiki-intro-requirements|
Usage |wiki-intro-usage|
Features |wiki-intro-features|
Guide |wiki-intro-guide|
Alternatives |wiki-intro-alternatives|
Configuration |wiki-config|
Options |wiki-config-options|
Events |wiki-config-events|
Commands |wiki-commands|
Mappings |wiki-mappings|
Text objects |wiki-mappings-text-obj|
Journal mappings |wiki-mappings-default|
Links |wiki-link|
Link URLs |wiki-link-url|
Wiki links |wiki-link-wiki|
Markdown links |wiki-link-markdown|
Markdown image links |wiki-link-image|
Reference links |wiki-link-reference|
Zotero shortlinks |wiki-link-zotero|
AsciiDoc cross references |wiki-link-adoc-xref|
AsciiDoc link macro |wiki-link-adoc-link|
Completion |wiki-completion|
Autocomplete |wiki-completion-auto|
Tags |wiki-tags|
Default tag parser |wiki-tags-default|
Templates |wiki-templates|
Template function context |wiki-templates-context|
Template file format |wiki-templates-format|
Journal summaries |wiki-templates-journal-summaries|
==============================================================================
INTRODUCTION *wiki-intro*
This is a Vim plugin for writing and maintaining a personal wiki, i.e.
a personal knowledge base. Please see |wiki-intro-usage| for a simple
quick-start guide, and |wiki-intro-guide| for more in-depth info on what this
is and how one could use such a system efficiently.
The plugin was initially based on https://github.com/vimwiki/vimwiki, but it
is written mostly from scratch and is based on a more "do one thing and do it
well" philosophy.
The plugin will activate by default for any `.wiki` files, but this may be
customized with |g:wiki_filetypes| and |g:wiki_global_load|. One may also
explicitly activate with |WikiEnable|. The wiki root is automatically detected
as long as there is a top-level `index.wiki` file available (the index name
may be changed with |g:wiki_index_name|). If no such file is found, it sets
the root to the same directory as the current file. In addition, one may
specify a main wiki with the |g:wiki_root| option. This allows convenient
mappings and commands for opening the main wiki from anywhere.
Note: |wiki.vim| is `not` a filetype plugin. It is designed so that it may be used
along with filetype plugins, e.g. for dedicated Markdown plugins. One
may also use `wiki-ft.vim` (https://github.com/lervag/wiki-ft.vim) for
simple syntax highlighting and folding of `.wiki` files, if desired.
------------------------------------------------------------------------------
REQUIREMENTS *wiki-intro-requirements*
This plugin is mainly developed on and for Linux. Some or most of the features
should still work on Windows and OSX, but currently there are no guarantees.
On Windows, it is assumed that users enable 'shellslash' to avoid issues with
backslashes versus forward slashes.
Some features require a recent version of Vim (>= 8.1) or NeoVim (>= 0.5).
The following is a list of external tools that are used for some of the
features:
Program Feature~
======= =======
`date` Journal related stuff
`xdg-open` Opening `pdf` files on Linux
`pandoc` (https://pandoc.org/) |WikiExport|
------------------------------------------------------------------------------
USAGE *wiki-intro-usage*
This outlines the basic steps to get started:
1. Create a wiki directory where the wiki files should be stored, for instance
`~/wiki`.
2. Add the following to your `vimrc` file: >
let g:wiki_root = '~/wiki'
3. Now you can open the index file (by default `index.wiki`; see also
|g:wiki_index_name|) with `<leader>ww` and start to add your notes as
desired.
Note: As one can see from the above, the default extension recognized by
|wiki.vim| is the `.wiki` extension. If one instead wants to use `.md`
(Markdown) as the default extension, then one usually wants to add the
following to `vimrc`: >
let g:wiki_filetypes = ['md']
let g:wiki_link_extension = '.md'
<
See |g:wiki_filetypes| and |g:wiki_link_extension| for more details on
these options.
------------------------------------------------------------------------------
FEATURES *wiki-intro-features*
- Wiki functionality
- Global mappings for accessing a specified wiki
- Local mappings for
- Navigation (follow links, go back, etc)
- Renaming pages (will also update links in other pages)
- Creating a table of contents
- Toggling links
- Viewing wiki link graphs
- Completion of wiki links and link anchors
- Text objects
- `iu au` Link URL
- `it at` Link text
- New page templates
- Support for journal entries
- Navigating the journal back and forth with `<Plug>(wiki-journal-next)`
and `<Plug>(wiki-journal-prev)`.
- Support for parsing journal entries in order to make weekly and monthly
summaries. The parsed result needs manual editing for good results.
- Utility functionality
- |WikiExport| command for exporting to e.g. `pdf` with `pandoc`
- Third-party support
- |CtrlP|: |CtrlPWiki| command (https://github.com/ctrlpvim/ctrlp.vim)
- |fzf|: |WikiFzfPages|, |WikiFzfToc|, and |WikiFzfTags| commands
(https://github.com/junegunn/fzf.vim)
- |unite| source (https://github.com/Shougo/unite.vim)
- |denite| source (https://github.com/Shougo/denite.nvim)
------------------------------------------------------------------------------
GUIDE *wiki-intro-guide*
The following guide is more or less an essay on how I personally use
`wiki.vim` for structuring and writing my notes. I take the liberty of writing
in the first tense, as this is clearly a subjective matter. An initial version
of this was posted as a comment in an issue thread [0] (note: the links are
listed at the bottom). I recommend anyone interested to read the entire thread
(although it is quite long!). But first, a quote that I think captures the
most important concept in a single sentence (by @mgoral [1]):
> I think that the most important thing is to not overthink things and just
> keep writing stuff down.
Executive summary~
* Speed is key - make sure you have a fast workflow.
* Use a global keyboard shortcut (e.g. <alt-n>) to open Vim with the wiki
index.
* Use |:WikiFzfPages| and `ripgrep` (with e.g. ctrlsf.vim) for searching.
* Write short pages and use links between related pages.
* Don't obsess about the wiki structure.
People write things down. Take notes. Why? Because people, or at least most of
us, don't remember things for too long. From my point of view, taking notes
is a way to extend my memory. And writing the notes is itself a useful
process, because it often helps both to learn and to remember things.
I find the idea of keeping my notes linked and easily searchable in pure text
to be extremely potent. With wiki.vim, I can very quickly locate relevant
notes for a topic. I believe strongly that speed or efficiency is the key
aspect of a good personal-knowledge system. However, before I continue, I want
to stress that `wiki.vim` is just one such system. There are probably
countless, and I encourage everyone to find a system that works for them. Some
alternatives are listed under |wiki-intro-alternatives|.
So, some context: My personal wiki consists per 2021-08-29 of 1714 pages with
a total of 71474 lines, excluding my journal. I first started taking notes in
2007, so this is perhaps 14 years worth of writing. I use Syncthing [2] to
keep my notes synchronized across my computers, phones, tablets. I've
previously also used Dropbox.
With a lot of content, it is important to be able to find things fast. I use
|:WikiFzfPages| to find a specific page, and it usually takes just a couple of
seconds from the moment I think of something until I have opened the relevant
note. A key here is to use simple names for the pages. I prefer several short
pages instead of one long, if possible.
Sometimes I search for things within pages. For this, I rely on `ripgrep` [3].
I use `ctrlsf.vim` [4] (which uses `ripgrep` as a backend). This makes it easy
and fast to search the wiki. And if my search has too many hits, I can either
narrow it down by changing the search pattern, or I can search within the
result buffer of `ctrlsf.vim`. This has generally not failed me in finding
information I'm looking for. I don't spend a lot of time searching for things.
If I know I've written about something, I always find it with |:WikiFzfPages|
and/or ":CtrlSF", and it typically goes very fast (both of the commands are
properly mapped).
How do I write my notes? I make sure to write down what I feel like at the
moment. I then clean it up and rinse/repeat as something is developing. I add
links to relevant external and internal pages/resources. I often add examples,
for instance tools I discover or libraries I learn about.
With time, I've started to adopt an unstructured approach where I avoid
complicated structure and subdirectories. I try to use the proper names of
things as the name of a page. The simple structure makes it easy to convert
text to the correct links and it makes it easy to remember the relevant page
names.
I don't worry about having many pages. I don't worry about almost empty pages.
I don't worry about keeping my pages in a hierarchy. I've found it can be
useful to split information into separate pages, as it makes it easier to link
things. I sometimes find the graph features useful, e.g. |wiki-graph-in|, but
I don't use them much.
However, sometimes I write down stuff that I don't know where to put. This is
where I use my `index.wiki`. That is, I either add loose content to the index,
or I make a link to some new scratch buffer with the new content. With time,
I work through this index (often slowly) and move content into more dedicated
pages. For this workflow to work well, it is crucial that my `index.wiki` is
extremely accessible. I therefore have a global keyboard shortcut on all my
computers to open Vim with the index. Specifically, I map <alt-n> to the
shell command `urxvt -e nvim +WikiIndex`, where `urxvt` is a well known
terminal. This way, it takes less than a second from the moment I have
a thought until I can start to add it to my `index.wiki` for later processing.
The speed allows me to write down a thought immediately and then continue with
the current work without being severely disrupted - this is what makes the
concept so important.
I also create a global shortcut <alt-j> mapped to `urxvt -e nvim +WikiJournal`
to open today's journal page. This is also very useful, especially if one
keeps a daily journal - as I do.
Although I do add a lot of text to my wiki, I've also realized that I should
not add all data there. For instance, I've come to use Zotero [5] for managing
my literature database. This is also why there is now some support for Zotero
within wiki.vim (see |wiki-link-zotero|).
For some topics, I may write a wiki page about stuff where I have links to
data files in which I can append new data and to scripts I can run to
visualize. the data. Thus, I don't keep everything in the wiki, instead, I may
write the "metadata" and general overview in the wiki, and then keep the real
data and relevant tools as a "third party".
Finally, I again stress that these are my personal experiences and opinions,
and I very much acknowledge that what works for me probably does not work for
everyone else.
[0]: https://github.com/lervag/wiki.vim/issues/101#issuecomment-709571804
[1]: https://github.com/lervag/wiki.vim/issues/101#issuecomment-718284921
[2]: https://syncthing.net/
[3]: https://github.com/BurntSushi/ripgrep
[4]: https://github.com/dyng/ctrlsf.vim
[5]: https://www.zotero.org/
------------------------------------------------------------------------------
ALTERNATIVES *wiki-intro-alternatives*
There exist a lot of alternatives to `wiki.vim`. Within the Vim ecosystem,
the main alternative is vimwiki. But there are also a lot of other
alternatives. The following list is probably not very comprehensive. It may be
useful if only as an inspiration to read about alternative approaches. The
descriptions are mostly a copy of the initial text from the relevant home
pages.
Vimwiki~
https://github.com/vimwiki/vimwiki
Type: Plugin; Vim
Vimwiki is a personal wiki system for Vim. It relies on its own filetype,
although recent versions also supports more traditional markdown formats.
Waikiki~
https://github.com/fcpg/vim-waikiki
Type: Plugin; Vim
Waikiki is a "fisherman's wiki": it provides a minimal set of features to
navigate pages and create links and pages.
Foam~
https://foambubble.github.io/foam/
Type: Plugin; Visual Studio Code
Foam is a personal knowledge management and sharing system inspired by Roam
Research, built on Visual Studio Code and GitHub.
Roam Research~
https://roamresearch.com/
Type: Software
A note-taking tool for networked thought. As easy to use as a document. As
powerful as a graph database. Roam helps you organize your research for the
long haul.
Emacs Org Mode~
https://orgmode.org/
Type: Plugin; Emacs
A GNU Emacs major mode for convenient plain text markup — and much more. Org
mode is for keeping notes, maintaining to-do lists, planning projects,
authoring documents, computational notebooks, literate programming and more
— in a fast and effective plain text system.
Obsidian.md~
https://obsidian.md/
Type: Software
"A second brain, for you, forever." Obsidian is a powerful knowledge base on
top of a local folder of plain text Markdown files.
==============================================================================
CONFIGURATION *wiki-config*
The following subsections present a list of available options and events that
can be used to customize the behaviour of wiki.vim.
------------------------------------------------------------------------------
OPTIONS *wiki-config-options*
*g:wiki_cache_root*
Specify the cache directory for |wiki.vim|.
Default value: OS dependent
`Linux and MacOS`: '~/.cache/wiki.vim/'
`Windows`: Standard temporary folder (based on |tempname()|)
*g:wiki_cache_persistent*
Specify whether to use persistent caching.
Default value: 1
*g:wiki_completion_case_sensitive*
Specify whether to use case-sensitive matching for omnicompletion of links
and tags.
Default value: 1
*g:wiki_date_exe*
Specify the executable for `date`, which is used "behind the scenes" to
manipulate and calculate dates for the journal features.
On MacOS/OSX, one can install `coreutils` from Homebrew and then use the
`gdate` program with: >
let g:wiki_date_exe = 'gdate'
<
Default: 'date'
*g:wiki_export*
A dictionary that specifies the default configuration for |WikiExport|
options. See the specifications for the options for more information.
Default: >
let g:wiki_export = {
\ 'args' : '',
\ 'from_format' : 'markdown',
\ 'ext' : 'pdf',
\ 'link_ext_replace': v:false,
\ 'view' : v:false,
\ 'output': fnamemodify(tempname(), ':h'),
\}
*g:wiki_filetypes*
List of filetypes for which |wiki.vim| should be enabled. If you want to
make Markdown the default filetype, add it as the first element to the list,
e.g.: >
let g:wiki_filetypes = ['md', 'wiki']
<
See also |g:wiki_link_extension|, which is often relevant in many filetypes.
Default: ['wiki']
*g:wiki_file_handler*
Name of a function or a |FuncRef| for a function that should be used to
handle local files (see also |wiki-link-url|). The function should give
a non-zero return value if it properly handled the URL. If not, the plugin
falls back to opening the URL with Vim. An example: >
let g:wiki_file_handler = 'WikiFileHandler'
function! WikiFileHandler(...) abort dict
if self.path =~# 'pdf$'
silent execute '!zathura' fnameescape(self.path) '&'
return 1
endif
return 0
endfunction
*g:wiki_fzf_pages_force_create_key*
Key combination that, when pressed while searching with |WikiFzfPages|, will
create a new page with the name of the query. The value must be a string
recognized by fzf's `--expect` argument; see fzf's manual page for a list of
available keys.
Default: `'alt-enter'`
*g:wiki_fzf_pages_opts*
A string with additional user options for |WikiFzfPages|. This can be used
e.g. to add a previewer. Users should be aware that the page candidates are
"prettified" with the `--with-nth=1` and `-d` options for fzf, so to obtain
the page path in a previewer option one must use the field index expression 1.
E.g.: >
let g:wiki_fzf_pages_opts = '--preview "cat {1}"'
<
Default: `''`
*g:wiki_global_load*
|wiki.vim| is inherently agnostic in that it assumes any recognized filetype
specifies a wiki. However, some people might want to load |wiki.vim| for
ONLY files within a globally specified directory |g:wiki_root|. To allow
this behaviour, one can set this option to 0.
Default: 1
*g:wiki_index_name*
A string with the index page name for the wiki. The value should not include
the file extension.
Default: `'index'`
*g:wiki_journal*
A dictionary for configuring the journal/diary feature. Available options
are:
name~
Name of journal (used to set journal path).
frequency~
One of 'daily', 'weekly', or 'monthly'.
date_format~
Dictionary of filename formats for the 'daily', 'weekly', and 'monthly'
frequencies. The formats may contain the following keys:
%y year (two digits)
%Y year (four digits)
%m month (01..12)
%d day of month (01..31)
%V ISO week number with Monday as first day of week
%U week number with Sunday as first day of week
index_use_journal_scheme~
Whether to use the `journal:` scheme when creating journal index with
|WikiJournalIndex|.
Default: >
let g:wiki_journal = {
\ 'name': 'journal',
\ 'frequency': 'daily',
\ 'date_format': {
\ 'daily' : '%Y-%m-%d',
\ 'weekly' : '%Y_w%V',
\ 'monthly' : '%Y_m%m',
\ },
\ 'index_use_journal_scheme': v:true,
\}
*g:wiki_link_extension*
Specify the extension that should be applied to wiki links. This should be
in the format `.ext`, e.g. `.md` or `.wiki`.
Default: ''
*g:wiki_link_toggle_on_follow*
This option allows to disable the toggle behaviour in |WikiLinkFollow| where
"normal" text under the cursor is transformed into links. The behaviour is
enabled by default. If disabled, one may still use |WikiLinkToggle| to
transform text into links.
Default: 1
*g:wiki_link_target_type*
This option may be used to pick the default style of link that will be used.
Available styles for the default target type are:
`md` (|wiki-link-markdown|)
Markdown style links.
`wiki` (|wiki-link-wiki|)
Wiki style links.
`adoc_xref_bracket` (|wiki-link-adoc-xref|)
`adoc_xref_inline`
AsciiDoc cross-reference style links (angled brackets style or inline
`xref:...` style).
Toggling between link types can still be achieved using |WikiLinkToggle|.
Default: 'wiki'
*g:wiki_link_toggles*
This option specifies the template for toggling a specific type of link with
|WikiLingToggle| or |<plug>(wiki-link-toggle)|.
This allows to customize how links are changed when they are toggled. For
instance, to add/remove extensions for wiki and markdown style links, one
could use: >
function WikiToggleWiki(url, text) abort dict
return wiki#link#md#template(a:url . '.wiki',
\ empty(a:text) ? a:url : a:text)
endfunction
function WikiToggleMd(url, text) abort dict
let l:url = substitute(a:url, '\.wiki$', '', '')
return wiki#link#wiki#template(l:url, a:text)
endfunction
let g:wiki_link_toggles = {
\ 'md': 'WikiToggleMd',
\ 'wiki': 'WikiToggleWiki',
\}
<
Default: >
let g:wiki_link_toggles = {
\ 'md': 'wiki#link#wiki#template',
\ 'wiki': 'wiki#link#md#template',
\ 'date': 'wiki#link#wiki#template',
\ 'shortcite': 'wiki#link#md#template',
\ 'url': 'wiki#link#md#template',
\}
*g:wiki_map_create_page*
This option may be used to specify a map or transformation for page names
provided to |WikiOpen|. For example: >
let g:wiki_map_create_page = 'MyFunction'
function MyFunction(name) abort
let l:name = wiki#get_root() . '/' . a:name
" If the file is new, then append the current date
return filereadable(l:name)
\ ? a:name
\ : a:name . '_' . strftime('%Y%m%d')
endfunction
<
With the above setting, if one enters a page name "foo" for |WikiOpen| on
the date 2020-04-11, the page "foo_20200411" will be created.
Default: ''
*g:wiki_map_link_create*
This option may be used to transform text before creating a new link. An
example: >
let g:wiki_map_link_create = 'MyFunction'
function MyFunction(text) abort
return substitute(tolower(a:text), '\s\+', '-', 'g')
endfunction
<
With the above setting, links created with |WikiLinkFollow| or
|WikiLinkToggle| (or related mappings) will be transformed by `MyFunction`.
As an example, if one creates a link from the text "Some text", the link
becomes "[[some-text|Some text]]".
Default: ''
*g:wiki_mappings_use_defaults*
Whether or not to use default mappings (see |wiki-mappings-default|). The
allowed values are:
'all' use all default mappings
'local' use only buffer-local default mappings
'global' use only global default mappings
'none' do not use any of the default mappings
Default: 'all'
*g:wiki_mappings_global*
*g:wiki_mappings_local*
These options allow one to customize global and buffer local mappings
through dictionaries where the keys are the right-hand sides and the values
are the desired mappings, e.g.: >
let g:wiki_mappings_global = {
\ '<plug>(wiki-reload)' : ',wx',
\}
<
This example maps `,wx` to |<plug>(wiki-reload)|. The other maps are kept at
their default (unless |g:wiki_mappings_use_default| specifies otherwise).
Some mappings are defined in other modes than normal mode. In this
case, one can use the following syntax: >
let g:wiki_mappings_local = {
\ '<plug>(wiki-export)' : '<c-p>',
\ 'x_<plug>(wiki-export)' : '<c-p>',
\}
<
Here `<c-p>` is mapped to |<plug>(wiki-export)| in normal mode and
visual mode, respectively. The available `<plug>` mappings are listed in
|wiki-mappings|.
Default: Undefined
*g:wiki_month_names*
A list of the names for each month. Used for interpolating month names in
the month template, |g:wiki_template_title_month|.
Default: `['January', 'February', ..., 'December']`
*g:wiki_resolver*
The name of the function to resolve wiki-schemed links, i.e., the standard
link scheme. The default should work well for most people, but this option
allows to adjust the resolver to ones own liking.
The function takes two arguments:
fname~
The unresolved filename. This may be empty, which is typically the case
for inter-page links (e.g. `[[#SomeSection]]`).
origin~
The path of the origin file, i.e. the file from which the link was
activated. This may be empty if a link is followed programmatically from
an empty buffer.
The function must return an absolute path to the destination file.
Note: The function `wiki#get_root()` can be useful to get the path to the
wiki root.
Default: `'wiki#url#wiki#resolver'`
*g:wiki_root*
Option to specify the wiki root path, i.e. the wiki that is opened with the
`<leader>ww` mapping. The option value must be a string that is either
i) a specific path, or
ii) the name of a function that returns a path.
The latter method allows more flexible determination of the root path, e.g.
project specific root paths. An example: >
function! WikiRoot()
let l:local = finddir('wiki', ';./')
return !empty(l:local) ? l:local : '~/wiki'
endfunction
let g:wiki_root = 'WikiRoot'
<
This setting would first search for a `wiki` directory in the current
relative directory, and fallback to a global `wiki` if the local wiki is not
found.
Note: The (returned) path must be either a relative or absolute path to an
existing directory.
Default: ''
*g:wiki_toc_title*
The title of TOC listings.
Default: `'Contents'`
*g:wiki_tag_list*
A dictionary that specifies the default options for |WikiTagList|.
Default: >
let g:wiki_tag_list = {
\ 'output' : 'loclist',
}
*g:wiki_tag_search*
A dictionary that specifies the default options for |WikiTagSearch|.
Default: >
let g:wiki_tag_search = {
\ 'output' : 'loclist',
}
*g:wiki_tag_parsers*
A list of parsers used to source the tags. The parsers are tried in the
order they're specified. If a parser matches, then it is selected and used.
A tag parser is a dictionary object with the following keys:
match~
A function (|FuncRef|) that takes a single argument, the current line.
It should return |v:true| or 1 if the line contains any tags.
parse~
A function (|FuncRef|) that takes a single argument, the current line.
It should return a list of the tags in the given line.
make~
A function (|FuncRef|) that takes two arguments: a list of tags, and the
current line. It should return a new line with the list of tags
formatted appropriately. This new line will replace the current line.
This function is used by |WikiTagRename|.
re_findstart~
`OPTIONAL`
A regular expression (|String|) that should match the start of the
current tag for tag completion (|wiki-completion|). See
|g:wiki#tags#default_parser| for an example.
As an example, one can use the following to parse tags in lines that match
`tags: keyword1, keyword2` in addition to the default parser: >
let g:wiki_tag_parsers = [
\ g:wiki#tags#default_parser,
\ { 'match': {x -> x =~# '^tags: '},
\ 'parse': {x -> split(matchstr(x, '^tags:\zs.*'), '[ ,]\+')},
\ 'make': {t, x -> 'tags: ' . empty(t) ? '' : join(t, ', ')}}
\]
<
See |g:wiki#tags#default_parser| for details on the default tag parser.
Default: >
let g:wiki_tag_parsers = [g:wiki#tags#default_parser]
<
*g:wiki_tag_scan_num_lines*
A number of lines to read from the top of a page when scanning tags. To scan
lines from the bottom, use a negative number, e.g. >
let g:wiki_tag_scan_num_lines = -10
<
To scan the entire files, use: >
let g:wiki_tag_scan_num_lines = 'all'
<
Default: >
let g:wiki_tag_scan_num_lines = 15
*g:wiki_templates*
A list of templates for prefilling new pages. Each template should be
specified as a dictionary with a matcher and a source. Matching may be done
with regular expressions or with user functions. Similarly, sources can be
specified as a file source as specified in |wiki-templates-format|, or as
a user function with a single argument `context` as specified in
|wiki-templates-context|.
The possible dictionary keys of a template are:
match_re~
|String|
A regular expression that will be matched against the new page name.
Note: The name is not the same as the path and it does not include the
file name extension. For more advanced matching, you need a custom
matcher function, i.e. the next key.
match_func~
|Funcref|
A function that should return |v:true| if the template should be applied
or |v:false| if it should not apply.
source_filename~
|String|
The path to a template file. If this is a relative path, then it will be
relative to whichever path Vim or neovim is currently at when the
template is executed. If the template file is not found, then the
template will not be applied and the next template in the list will be
tried.
source_func~
|Funcref|
A user function that can use e.g. |append()| to add lines to the file.
For example: >
function! TemplateFallback(context)
call append(0, '# ' . a:context.name)
call append(1, '')
call append(2, 'Foobar')
endfunction
let g:wiki_templates = [
\ { 'match_re': 'index',
\ 'source_filename': '/home/user/templates/index.md'},
\ { 'match_re': 'foo',
\ 'source_filename': '.footemplate.md'},
\ { 'match_func': {x -> v:true},
\ 'source_func': function('TemplateFallback')},
\]
<
Notice that in the second template, the `;` is appended to the source
filename. This means the template file is first searched for in the current
directory of the new page, then in the parent directory, and so on. If the
template file is not found, then the next template will be tried.
Default: `[]`
*g:wiki_template_title_month*
A string that specifies the title of the month template. The following keys
are interpolated:
`%(month)` Month number
`%(month-name)` Name of month (see |g:wiki_month_names|)
`%(year)` Year (4 digits)
See |wiki-templates-journal-summaries| for more info.
Default: `'# Summary, %(year) %(month-name)'`
*g:wiki_template_title_week*
A string that specifies the title of the week template. The following keys
are interpolated:
`%(week)` Week number
`%(year)` Year (4 digits)
See |wiki-templates-journal-summaries| for more info.
Default: `'# Summary, %(year) week %(week)'`
*g:wiki_viewer*
A dictionary that specifies which viewer to use for a given filetype. The
entry `_` specifies the fallback or generic viewer. This option thus allows
one to setup different viewers for different file types that are used by the
generic link scheme handler (|wiki-link-url|) and by |WikiExport|.
Default: >
let g:wiki_viewer = {
\ '_' : OS Dependent: 'xdg-open' (Linux) | 'open' (OSX),
\}
*g:wiki_write_on_nav*
Option to specify whether or not to save the current file automatically
before navigating (forward or backward) between wiki links.
Default: 0
*g:wiki_zotero_root*
A string that specifies the Zotero root folder used for the zotero URL
scheme, see |wiki-link-url|.
Default: `'~/.local/zotero'`
------------------------------------------------------------------------------
EVENTS *wiki-config-events*
The following |User| events are available. The following shows an example for
how to use this: >
augroup MyWikiAutocmds
autocmd!
autocmd User WikiLinkFollowed normal! zz
autocmd User WikiBufferInitialized
\ nmap <buffer> gf <plug>(wiki-link-follow)
augroup END
*WikiBufferInitialized*
Event is triggered after the buffer features are initialized. This event
allows one to apply custom mappings and similar.
*WikiLinkFollowed*
Event is triggered after a link has been followed.
*WikiReloadPost*
Event is triggered after wiki.vim has been reloaded with |WikiReload|.
==============================================================================
COMMANDS *wiki-commands*
The following is a list of commands that are available in the wiki. Most of
the commands are also available as mappings of the form `<plug>(wiki-[name])`.
*WikiEnable*
Load |wiki.vim| for the current file. If the current file type is not in
|g:wiki_filetypes|, then it will be added, so that interwiki links will be
possible.
*<plug>(wiki-index)*
*WikiIndex*
Go to wiki index. When not inside a wiki page, the index is specified by the
options |g:wiki_root| and |g:wiki_index_name|.
*<plug>(wiki-open)*
*WikiOpen*
Open (or create) a page. Asks for user input to specify the page name. When
not already inside a wiki, the wiki root is given by |g:wiki_root|. If
|g:wiki_map_create_page| is specified, it will be used to transform the
input name before opening/creating the page.
*<plug>(wiki-journal)*
*WikiJournal*
Go to todays journal entry.
*<plug>(wiki-reload)*
*WikiReload*
Reload the wiki plugin. Mostly useful for plugin development.
*<plug>(wiki-graph-find-backlinks)*
*WikiGraphFindBacklinks*
Find backlinks to current page.
*<plug>(wiki-graph-check-links)*
*WikiGraphCheckLinks*
Check the wiki for broken links. If any broken links are found, they are
added to the location list (|location-list|) and the location list is
opened. The process of checking for broken links can take a while if you
have a large wiki.
*<plug>(wiki-graph-in)*
*<plug>(wiki-graph-out)*
*WikiGraphIn*
*WikiGraphOut*
Show link graph in to or out of the current page. A count may be given to
limit the depth of the graph.
*<plug>(wiki-link-next)*
*WikiLinkNext*
Go to next link.
*<plug>(wiki-link-prev)*
*WikiLinkPrev*
Go to previous link.
*<plug>(wiki-link-follow)*
*WikiLinkFollow*
Follow link. Will create a new link if the text under the cursor is not
already a link. If |g:wiki_map_link_create| is specified, it will be used to
transform the link when creating it.
*#User#WikiLinkFollowed*
The user autocommand `WikiLinkFollowed` is triggered after a wiki link has
been followed. This allows the user to add custom functionality after
following wiki links. For example, to center the cursor inside the window
after following a link: >
augroup MyWikiAutocmds
autocmd!
autocmd User WikiLinkFollowed normal! zz
augroup END
*<plug>(wiki-link-follow-split)*
*WikiLinkFollowSplit*
Similar to |WikiLinkfollow|, except wiki links are followed in a |vsplit|.
*<plug>(wiki-link-follow-tab)*
*WikiLinkFollowTab*
Similar to |WikiLinkfollow|, except wiki links are followed in a |tabedit|.
*<plug>(wiki-link-return)*
*WikiLinkReturn*
Go back to previous page, i.e. undo the last follow operation.
*<plug>(wiki-link-toggle)*
*<plug>(wiki-link-toggle-visual)* |xmap|
*<plug>(wiki-link-toggle-operator)* |map-operator|
*WikiLinkToggle*
Toggle wiki link. If |g:wiki_map_link_create| is specified, it will be used
to transform the link when creating it.
*<plug>(wiki-link-show)*
*WikiLinkShow*
Show some info on link under cursor.
*<plug>(wiki-link-extract-header)*
*WikiLinkExtractHeader*
Set link title from the first header of the target file.
*<plug>(wiki-page-delete)*
*WikiPageDelete*
Delete wiki page.
*<plug>(wiki-page-rename)*
*WikiPageRename*
Rename wiki page (will update all links to the page).
*<plug>(wiki-page-toc)*
*WikiPageToc*
Create/Update table of contents.
*<plug>(wiki-page-toc-local)*
*WikiPageTocLocal*
Create/Update table of contents (section local variant).
*<plug>(wiki-journal-index)*
*WikiJournalIndex*
Insert a sorted list of links to all journal pages below the cursor. It uses
the link style specified by |g:wiki_link_target_type|.