├── Makefile ├── README ├── README.md ├── autoload └── zim │ └── plugins │ └── arithmetic.vim ├── doc ├── tags └── zim.txt ├── ftdetect └── zim.vim ├── ftplugin └── zim.vim ├── plugin ├── zim.vim └── zim │ ├── editor.vim │ ├── explorer.vim │ ├── note.vim │ ├── plugins.vim │ └── util.vim └── syntax ├── getsourcesfiletype.py ├── zim.vim └── zimindex.vim /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | vim -u NONE -c "helptags doc/ | qa!" 3 | 4 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | Beta version : please look in README.md file instead. 2 | 3 | Zim Desktop Wiki plugin for Vim 4 | ================================ 5 | Author: Jack Mudge 6 | URL: https://github.com/jakykong/vim-zim 7 | Version: 0.1 8 | License: Public Domain 9 | 10 | This Zim plugin provides the following additions to Vim for use with Zim wiki files: 11 | * Syntax highlighting and filetype detection for Zim files 12 | * Commands to bold, italicize, strike, or mark text. 13 | * A command to add a header to new Zim files. 14 | 15 | A typical workflow for use with this is one of: 16 | * Create files in Zim, and use Tools->Edit Source to access Vim. 17 | * Create files in Vim, and (re)start Zim to read them. 18 | 19 | Known issues: 20 | * Zim header command uses strftime, but due to working around Microsoft issues, 21 | it presently only supports Pacific Time Zone, and does not support Linux. 22 | Adding time zones is easy (look at the plugin file), so is adding Linux support 23 | (place and method marked in the same file), I just haven't needed to. 24 | * Not an issue with the plugin, but with Zim: There is no way to refresh the index 25 | in Zim without restarting Zim. This implies that new files added from Vim will 26 | not be visible there until it's restarted. 27 | * No helpfile written yet. 28 | 29 | Commands: 30 | wh - Header (accepts count 1-5): ====HEADER==== syntax in file (Normal mode) 31 | wh - Highlight __Highlighted Text__ syntax (Visual mode) 32 | wb - Bold text (in normal mode, bolds entire line, not including bullets or checkboxes if present) 33 | wi - Italic text (in normal mode, bolds entire line, not including bullets or checkboxes if present) 34 | ws - Strike text (in normal mode, bolds entire line, not including bullets or checkboxes if present) 35 | :CreateZimHeader() - Creates a Zim header in the current document. Required for Zim to correctly render new files. 36 | 37 | 38 | 39 | Changelog: 40 | ========== 41 | 2016-09-13 - Jack Mudge 42 | * Initial commit and upload to Github. 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Zim Desktop Wiki plugin for Vim 2 | ================================ 3 | ``` 4 | ___ / / 5 | |_ _| / / _________ _ 6 | ___ |_ / / |_______ | | | 7 | |_ _| .-' // ,' ,' _ _ ____ ____ 8 | \ ' / ' ___ ,' ,' | | \/ __ \ / __ \ 9 | | | -|_ _| ,' ,' | | | | | | | | 10 | '. .' ,' ,'_____ | | | | | | | | 11 | ___/ '- __ -' __|_________|__ _|_|_ __|_| |_| |_|__ 12 | |_ _| _|_ 13 | |_ _| Zim - A Desktop Wiki (for Vim 7.0 or newer) 14 | ``` 15 | 16 | How to install 17 | ================================ 18 | [Download the zip](https://github.com/luffah/vim-zim/archive/master.zip) and unzip it to `~/vim/pack/org/start/zim`. 19 | 20 | 21 | In **Vim 8+**, you shall just verify this line present in `.vimrc` : 22 | ```vim 23 | syntax on 24 | packloadall 25 | ``` 26 | 27 | If you use **Vim 7+** , the `runtimepath` shall be updated in `.vimrc` : 28 | ```vim 29 | syntax on 30 | set rtp+=~/vim/pack/org/start/zim 31 | ``` 32 | 33 | Verify the plugin is installed : 34 | 35 | * To get every commands and parameters -> `:h Zim` 36 | * To get a list of your notes -> `:ZimList` 37 | 38 | 39 | Usage 40 | ===== 41 | 42 | ##### When you want to use Vim to edit your Zim note 43 | Just open the `.txt` file. 44 | 45 | ##### When you want to fetch informations stored in your NoteBooks 46 | `:ZimGrep ga` -> show all notes mentioning 'ga'
47 | `:ZimList bu` -> show all notes named 'something-bu' 48 | 49 | ##### When you want more 50 | `:ZimNewNote Notes/Bu/Zo Meu` -> create new note(s) `Bu/Zo Meu.txt` titled 'Zo Meu' (subnote of 'Bu')
51 | `:ZimList meu` `m`(select for move) `m`(move here) -> reorganize notes
52 | `:ZimList zo` `d`(detect double) `D`(delete)-> remove a double
53 | `:ZimCmd title` -> format the current line as a title (it shows the keybinding before)
54 | `:ZimNewNote `, `:ZimList `, `:ZimCmd ` …
55 | 56 | About zim-vim 57 | ============= 58 | This section give some details about the development of this plugin. 59 | 60 | Authors : [Jack Mudge](https://github.com/jakykong/vim-zim), [Luffah](https://github.com/luffah/vim-zim) 61 | ``` 62 | License : Public Domain 63 | CC-BY-SA for documentation and logo 64 | 65 | ## Known issues 66 | * When adding note, you shall refresh manually (restart) the index in Zim. 67 | In GNU linux see `:h g:zim_update_index_key`. 68 | * No real Windows Support. 69 | * Windows :Zim header command uses strftime, but due to working around Microsoft issues, 70 | it presently only supports Pacific Time Zone . 71 | 72 | ## Changelog 73 | #### version 0.1 2016-09-13 - Jack Mudge 74 | * Initial commit and upload to Github. 75 | * This Zim plugin provides the following additions to Vim for use with Zim wiki files: 76 | * Syntax highlighting and filetype detection for Zim files 77 | * Commands to bold, italicize, strike, or mark text. 78 | * A command to add a header to new Zim files. 79 | 80 | #### version 1.0 2017-06-13 - Luffah 81 | * Add documentation and logo 82 | * Provide customisation, helpfile, and navigation features 83 | * (change) Header accept user dialog instead of count 84 | * (change) Syntax color reviewed in order to look more like Zim 85 | * Mod. CreateZimHeader + minimal support of Linux strftime() + automatic title 86 | * Customazible keymappings limited to zim buffers stored in g:zim_keymapping 87 | * Filetype detection based on a path 88 | * In insert mode : add bullet, numbering, or checkbox on with the result of ZimNextBullet 89 | * Multilingual : English, French // translations can be added in file plugin/zim.vim 90 | * You can now Search and jump to another note 91 | 92 | #### version 1.1 2017-07-18 - Luffah 93 | * Allow to open files listed in a note with an external editor 94 | * Add some tricks in help 95 | 96 | #### version 1.2 2018-06-16 - Luffah 97 | * Add codeblock support 98 | * Add [>] "moving" checkbox 99 | * Now conceal url link (to only see the title) 100 | * Can fill a note with the content of a web page. 101 | ``` 102 | -------------------------------------------------------------------------------- /autoload/zim/plugins/arithmetic.vim: -------------------------------------------------------------------------------- 1 | " Copyright (C) 2018 luffah 2 | " Author: luffah 3 | " 4 | " This program is free software: you can redistribute it and/or modify 5 | " it under the terms of the GNU General Public License as published by 6 | " the Free Software Foundation, either version 3 of the License, or 7 | " (at your option) any later version. 8 | " 9 | " This program is distributed in the hope that it will be useful, 10 | " but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | " GNU General Public License for more details. 13 | " 14 | " You should have received a copy of the GNU General Public License 15 | " along with this program. If not, see . 16 | 17 | " Wrapper for Zim plugin Arithmetic 18 | fu! zim#plugins#arithmetic#processfile(...) 19 | let l:curbuf=bufnr('%') 20 | if len(a:000) > 0 21 | if a:000[0] ~= '^\d\+$' 22 | let l:buf == str2nr(a:000[0]) 23 | if !bufexists(l:buf) 24 | throw "the buffer doesn't extist" 25 | endif 26 | endif 27 | else 28 | let l:buf=l:curbuf 29 | endif 30 | let l:pyfile=zim#plugins#get_zim_src_dir().'/inc/arithmetic.py' 31 | if filereadable(l:pyfile) 32 | if l:curbuf != l:buf 33 | call execute('buffer '.l:buf) 34 | endif 35 | let l:file=shellescape(expand('%')) 36 | if len(l:file) 37 | let l:file=shellescape(expand('%:p')) 38 | 39 | silent! let l:lines = systemlist('echo << EOF | python '. 40 | \ l:pyfile.' -f '.l:file." 2> /dev/null") 41 | while len(l:lines) != 0 && l:lines[0] =~ '^eval error:' 42 | cal remove(l:lines,0) 43 | endwhile 44 | 45 | %delete 46 | call setline(1,l:lines) 47 | else 48 | echo "Buffer shall be linked to an existing file to use Zim plugins." 49 | endif 50 | if l:curbuf != l:buf 51 | call execute('buffer '.l:curbuf) 52 | endif 53 | else 54 | echomsg l:pyfile." not found" 55 | endif 56 | endfu 57 | -------------------------------------------------------------------------------- /doc/tags: -------------------------------------------------------------------------------- 1 | :ZimCD zim.txt /*:ZimCD* 2 | :ZimCopy zim.txt /*:ZimCopy* 3 | :ZimGrep zim.txt /*:ZimGrep* 4 | :ZimGrepThis zim.txt /*:ZimGrepThis* 5 | :ZimImgCapture zim.txt /*:ZimImgCapture* 6 | :ZimImgInsert zim.txt /*:ZimImgInsert* 7 | :ZimInjectHtml zim.txt /*:ZimInjectHtml* 8 | :ZimCleanNote zim.txt /*:ZimCleanNote* 9 | :ZimList zim.txt /*:ZimList* 10 | :ZimListThis zim.txt /*:ZimListThis* 11 | :ZimMatchNext... zim.txt /*:ZimMatchNext...* 12 | :ZimMatchPrev... zim.txt /*:ZimMatchPrev...* 13 | :ZimMove zim.txt /*:ZimMove* 14 | :ZimNewNote zim.txt /*:ZimNewNote* 15 | :ZimNewNoteFromWeb zim.txt /*:ZimNewNoteFromWeb* 16 | :ZimSelectNotebook zim.txt /*:ZimSelectNotebook* 17 | Zim zim.txt /*Zim* 18 | g:zim_brutal_update_allowed zim.txt /*g:zim_brutal_update_allowed* 19 | g:zim_dev zim.txt /*g:zim_dev* 20 | g:zim_dev_keys zim.txt /*g:zim_dev_keys* 21 | g:zim_edit_actions zim.txt /*g:zim_edit_actions* 22 | g:zim_ext_editor zim.txt /*g:zim_ext_editor* 23 | g:zim_ext_viewer zim.txt /*g:zim_ext_viewer* 24 | g:zim_img_capture zim.txt /*g:zim_img_capture* 25 | g:zim_img_editor zim.txt /*g:zim_img_editor* 26 | g:zim_img_viewer zim.txt /*g:zim_img_viewer* 27 | g:zim_keymapping zim.txt /*g:zim_keymapping* 28 | g:zim_matchable zim.txt /*g:zim_matchable* 29 | g:zim_notebook zim.txt /*g:zim_notebook* 30 | g:zim_notebooks_dir zim.txt /*g:zim_notebooks_dir* 31 | g:zim_open_jump_to zim.txt /*g:zim_open_jump_to* 32 | g:zim_update_index_key zim.txt /*g:zim_update_index_key* 33 | regexp zim.txt /*regexp* 34 | regular-expression zim.txt /*regular-expression* 35 | zim-api zim.txt /*zim-api* 36 | zim-commands zim.txt /*zim-commands* 37 | zim-editing zim.txt /*zim-editing* 38 | zim-intro zim.txt /*zim-intro* 39 | zim-toc zim.txt /*zim-toc* 40 | zim-todolist zim.txt /*zim-todolist* 41 | zim-tricky zim.txt /*zim-tricky* 42 | zim-variables zim.txt /*zim-variables* 43 | zim.txt zim.txt /*zim.txt* 44 | zim.vim zim.txt /*zim.vim* 45 | zim_keymapping zim.txt /*zim_keymapping* 46 | -------------------------------------------------------------------------------- /doc/zim.txt: -------------------------------------------------------------------------------- 1 | *zim.txt* *Zim* Note wrapper for Vim 2 | 3 | *zim.vim* 4 | ___ / / ~ 5 | |_ _| / / _________ _ ~ 6 | ___ |_ / / |_______ | | | ~ 7 | |_ _| .-' // ,' ,' _ _ ____ ____ ~ 8 | \ ' / ' ___ ,' ,' | | \/ __ \ / __ \ ~ 9 | | | -|_ _| ,' ,' | | | | | | | | ~ 10 | '. .' ,' ,'_____ | | | | | | | | ~ 11 | ___/ '- __ -' __|_________|__ _|_|_ __|_| |_| |_|__~ 12 | |_ _| _|_ ~ 13 | |_ _| Zim - A Desktop Wiki (for Vim 7.0 or newer) ~ 14 | 15 | *zim-toc* 16 | 17 | DESCRIPTION = = = = = = = = = = = = = = = = = = |zim-intro| 18 | VARIABLES = = = = = = = = = = = = = = = = = = = |zim-variables| 19 | COMMANDS = = = = = = = = = = = = = = = = = = = = |zim-commands| 20 | EDITOR ACTIONS AND KEYBINDINGS = = = = = = = = = |zim-editing| 21 | API = = = = = = = = = = = = = = = = = = = = = = |zim-api| 22 | TRICKY THINGS = = = = = = = = = = = = = = = = = |zim-tricky| 23 | 24 | ============================================================================== 25 | DESCRIPTION *zim-intro* 26 | |zim-toc| 27 | This Zim plugin provides additions to Vim for use with Zim wiki files. 28 | * Syntax highlighting and filetype detection for Zim files 29 | * Commands for navigating through Notes 30 | * Commands/keymapping to bold, italicize, strike, or mark text. 31 | 32 | The typical workflow is: 33 | * Create files in Zim, and use Tools->Edit Source to access Vim. 34 | * Create files in Vim, and (re)start Zim to read them. 35 | 36 | Authors: 37 | Jack Mudge Original code 38 | Luffah Bug correction, Navigation functionnalities, Help file 39 | 40 | See code for more details. 41 | 42 | Licenses: 43 | Public Domain 44 | CC 0 for the documentation 45 | GPL 46 | Same kind as vim -- we care to free softwares but we need to free peoples 47 | 48 | ============================================================================== 49 | VARIABLES *zim-variables* 50 | |zim-toc| 51 | 52 | *g:zim_notebook* 53 | Default : $HOME/Notesbooks 54 | You can modify easily with |:ZimCD| an |:ZimSelectNotebook| 55 | 56 | 57 | *g:zim_notebooks_dir* 58 | Default : $HOME/Notesbooks 59 | 60 | 61 | *g:zim_update_index_key* 62 | [Linux only; require XdoTools installed] 63 | Set the key to auto-update of a living Zim instance. 64 | =Configuration example= 65 | In vimrc : 66 | let g:zim_update_index_key="F5" 67 | 68 | In $HOME/.config/zim/accelmap : 69 | (gtk_accel_path "/GtkInterface/reload_index" "F5") 70 | 71 | 72 | *g:zim_keymapping* 73 | Set the keys associated to actions 74 | defined in *g:zim_edit_actions* (../plugin/zim.vim). 75 | Default : { 76 | \ '' : '', 77 | \ 'continue_list' : '', 78 | \ 'jump' : 'g', 79 | \ 'jump_back' : 'G', 80 | \ 'bold' : 'wb', 81 | \ 'italic' : 'wi', 82 | \ 'highlight' : 'wh', 83 | \ 'strike' : 'ws', 84 | \ 'title' : 'wt', 85 | \ 'header' : 'wH', 86 | \ 'all_checkbox_to_li' :'', 87 | \ 'li' :'wl', 88 | \ 'checkbox' :'wc', 89 | \ 'checkbox_yes' :'', 90 | \ 'checkbox_no' :'' 91 | \ } 92 | 93 | 94 | *g:zim_brutal_update_allowed* 95 | On sourcing, set to 1 to declare the command ZimBrutalUpdate, 96 | which kill Zim and relaunch it. 97 | 98 | 99 | *g:zim_open_jump_to* 100 | Set where the cursor is positionned on file openning. 101 | This is done by a succession of movements. 102 | 103 | This is implemented by the function zim#util#line({array}), 104 | which return the line number found and move the cursor only 105 | if it needs to do scrolling. 106 | 107 | The array can contain 3 types of variables (mouvements), 108 | with different meanings : 109 | string text pattern e.g. 'My Awesome Title' 110 | e.g. '^\(=\+\).*\1$' 111 | see *regular-expression* *regexp* 112 | 113 | integer line delta e.g. -1 to go back 1 line 114 | 115 | dict { 116 | 'init': '$' or '^' or any 'line' position 117 | 118 | 'sens' : (-1 or 1) line step for searching text 119 | 120 | 'get': a key for storing current line number 121 | 122 | 'set': an existing key to reinit line position 123 | 124 | 'scroll': a list of scroll commands 125 | Either 126 | 'top','center','bottom' to scroll until the 127 | cursor is at the nammed position 128 | Or 129 | an integer, indication how many line to 130 | scroll 131 | } 132 | 133 | Examples : 134 | " On note openning, go 2 lines after the first title 135 | let g:zim_open_jump_to=["==.*==", 2] 136 | " Or Go 2 lines after the last title 137 | let g:zim_open_jump_to=[{'init': '$', 'sens': -1}, "==.*==", 2]] 138 | 139 | *g:zim_matchable* 140 | Enable commands ZimMatchNext and 141 | ZimMatchPrev. 142 | 143 | dict { 144 | 'Title': text pattern e.g. '^\(=\+\).*\1$', 145 | see |regular-expression| |regexp| 146 | ... 147 | } 148 | 149 | Examples : 150 | " have a match for almost every zim standard element 151 | let g:zim_matchable={ 152 | \'Title': '^\(=\+\).*\1$', 153 | \'Checkbox': '^\(\s\{4}\)*\[[ ]\]\(\s\|$\)', 154 | \'Li': '^\(\s\{4}\|\t\)*\*\(\s\|$\)', 155 | \'NumberedItem': '^\(\s\{4}\|\t\)*\d\+\.\(\s\|$\)', 156 | \'Link': '\[\[.*\]\]', 157 | \'Img': '{{.*}}', 158 | \'File': '\(\~\|\.\|^\| \|{\|\[\)/[.a-zA-Z0-9]\+', 159 | \'Url': 'http[s]\?://[.a-zA-Z0-9]\+', 160 | \ } 161 | 162 | 163 | *g:zim_img_capture* 164 | Define a shell command to capture screenshots. 165 | Default : 'sleep 2; scrot -s' 166 | "wait 2 second to avoid scrot capturing keys 167 | This default only work for linux. 168 | 169 | *g:zim_img_viewer* 170 | *g:zim_img_editor* 171 | *g:zim_ext_viewer* 172 | *g:zim_ext_editor* 173 | Define viewer and editor commands based of the file type. 174 | 175 | |g:zim_img_viewer| and |g:zim_ext_editor| 176 | are specific to Zim images ( between {{ }} ). 177 | 178 | array [ 179 | array [ 180 | (filetype) text-pattern, 181 | see |regular-expression| |regexp| 182 | (shell command) text, 183 | (optionnal) number 184 | 0 to open all matched files in one instance 185 | 1 to open one file per instance 186 | n to open n files per instance 187 | Default is 0. 188 | ] 189 | array ... 190 | ] 191 | Example : 192 | " Open in images in feh 193 | let g:zim_img_viewer=[ 194 | \[ 195 | \ '\.\(png\|jp[e]\?g\|svg\|gif\)$', 196 | \ 'feh --magick-timeout 1' 197 | \], 198 | \] 199 | 200 | If no overide is done, default openner is 'xdg-open', 201 | which shall not work on Windows. 202 | 203 | To use this functionnality, you need to add to 204 | the actions 'show_img','edit_img','show_file','edit_file' 205 | in *g:zim_keymapping*. 206 | 207 | *g:zim_dev* 208 | For developers. 209 | Set to 1 to reload function on plugin/zim.vim sourcing. 210 | 211 | ============================================================================== 212 | COMMANDS *zim-commands* 213 | |zim-toc| 214 | 215 | :ZimCD *:ZimCD* 216 | Arguments are completed in wild menu. 217 | 218 | Set |g:zim_notebook| = 219 | 220 | :ZimListThis *:ZimListThis* 221 | :ZimList with word under cursor. 222 | 223 | :ZimList *:ZimList* 224 | Arguments are completed in wild menu. 225 | 226 | Open a temporary window to choose notes to open. 227 | Following keys are avaible in this window : 228 | 229 | -> Open note in current window 230 | 231 | -> Open note in an aside window (preview) 232 | 233 | u -> Update the list 234 | 235 | f -> Modify filter 236 | 237 | d -> Detect doubles names. 238 | Toggle an indicator '|' to show notes that 239 | have the same name. 240 | 241 | Once it's toggled, you can jump to doubles by 242 | pressing 'n' (Next). 243 | 244 | D -> Delete permanetly the note file 245 | (does not trash; not recursive) 246 | 247 | N -> Create a new note in the path under cursor. 248 | A prompt will appear. 249 | The new note can be a subpath. 250 | (note creation move to another 251 | window; list is not updated) 252 | 253 | m -> Move the note (under cursor) 254 | This act in 3 steps : 255 | 1. select the current note by pressing 'm' 256 | 2. when you see '| MOVING' aside the note, 257 | move cursor to another note 258 | 3. press 'm' again in order to 259 | move the note in the same path than 260 | 261 | R -> Rename the note (under cursor) 262 | A prompt will appear... 263 | 264 | q -> Quit 265 | 266 | Note : Display appear to be broken when using 'm' operation 267 | in terminal (text-mode) version of vim. Switch tab 268 | if you need to redraw. 269 | 270 | Note : openning is defined in zim/explorer.vim and 271 | is performed using the function |zim#util#open()| 272 | 273 | 274 | :ZimNewNote *:ZimNewNote* 275 | Arguments are completed in wild menu. 276 | 277 | Recursively create the note specified in 278 | . If any parent note is missing, 279 | then it is automatically created. 280 | 281 | [ Linux only ] 282 | If |g:zim_update_index_key| is set and `xdotool` is found, 283 | then it tries to locate Zim window and to send the key. 284 | 285 | :ZimNewNoteFromWeb *:ZimNewNoteFromWeb* 286 | Idem. It adds a prompt to enter the URL of the remote 287 | content to inject. 288 | 289 | :ZimCopy *:ZimCopy* 290 | :ZimMove *:ZimMove* 291 | Arguments are completed in wild menu. 292 | 293 | Copy or Move the note to another note path. 294 | 295 | If needed : Recursively create the note specified in 296 | . 297 | 298 | [ Linux only ] 299 | If |g:zim_update_index_key| is set and `xdotool` is found, 300 | then it tries to locate Zim window and to send the key. 301 | 302 | :ZimGrepThis *:ZimGrepThis* 303 | :ZimGrep with word under cursor. 304 | 305 | :ZimGrep *:ZimGrep* 306 | Open a location list for 307 | the matches of in g:zim_notebook. 308 | 309 | :ZimSelectNotebook *:ZimSelectNotebook* 310 | Open a temporary window to choose the current notebook. 311 | 312 | Set |g:zim_notebook| 313 | 314 | :ZimImgInsert *:ZimImgInsert* 315 | Insert image pointed by filepath at cursor position. 316 | 317 | :ZimImgCapture *:ZimImgCapture* 318 | Make a screenshot and save it in filepath, 319 | next, the image is inserted at cursor position. 320 | 321 | 322 | :ZimMatchPrev... *:ZimMatchPrev...* 323 | :ZimMatchNext... *:ZimMatchNext...* 324 | Go to the previous / next position of the element type. 325 | See |g:zim_matchable| 326 | 327 | :ZimInjectHtml *:ZimInjectHtml* 328 | [require pandoc installed] 329 | 330 | Convert the content of the (local or remote) HTML file, 331 | to ZimWiki format and add the result at the current 332 | position. 333 | 334 | :ZimCleanNote *:ZimCleanNote* 335 | Clean all things are supported in Vim-Zim, 336 | but not in the current version of Zim. 337 | This includes for now: 338 | - markdown codeblock 339 | 340 | ============================================================================== 341 | EDITOR ACTIONS AND KEYBINDINGS *zim-editing* 342 | |zim-toc| 343 | 344 | In a zim buffer, you can use keybindings defined in |g:zim_keymapping| 345 | to call special actions defined in |g:zim_edit_actions|. 346 | If you wish to modify keys just re-defined |g:zim_keymapping|. 347 | If you wish to modify the mode in which the keys are used , then you need to 348 | redefine |g:zim_edit_actions|. (see the code ../plugins/zim.vim to have a basis). 349 | 350 | *zim_keymapping* 351 | Here is a summary of the default settings. 352 | ┌──────────────────┬────┬────────────┬─────────────┬─────────────────────────────┐ 353 | │Actions │Mode│Default Keys│Dev Keys │ Description │ 354 | │──────────────────┼────┼────────────┼─────────────┼─────────────────────────────┤ 355 | │-Style------------│----│------------│-------------│-----------------------------│ 356 | │bold │n,v │wb │b │ Bold style. │ 357 | │italic │n,v │wi │i │ Italic style. │ 358 | │highlight │n,v │wh │h │ Highlight. │ 359 | │strike │n,v │ws │s │ Strike through. │ 360 | │title │n │wt │t │ Title style ( 1 to 5 ). │ 361 | │li │n,v │wl │l │ List item. │ 362 | │checkbox │n,v │wc │c │ Empty checkbox │ 363 | │checkbox_yes │n,v │y │ → check "Yes/Correct" │ 364 | │checkbox_no │n,v │n │ → check "No/Incorrect" │ 365 | │checkbox_moved │n,v │w> │> │ → check "Moved" │ 366 | │ │ │ │ │ │ 367 | │-Facilities-------│----│------------│-------------│-----------------------------│ 368 | │ │i │ continue the list. │ 369 | │continue_list │n │ │ Continue a list │ 370 | │ │ │ │ │ (dot, numbered or checkbox).│ 371 | │all_checkbox_to_li│n │ │ │ Remove every checkbox. │ 372 | │header │n │wH │H │ Add a Zim header. │ 373 | │date │n │d │d │ Insert today date. │ 374 | |datehour │n │D │D │ Insert today date and hour. │ 375 | │showimg │n │ │ Open image in viewer. │ 376 | │editimg │n │ │ Open image in editor. │ 377 | │showfile │n ││ Open file in viewer. │ 378 | │editfile │n │ │ Open file in editor. │ 379 | │ │ │ │ │ │ 380 | │-Navigation-------│----│------------│-------------│-----------------------------│ 381 | │jump │n │g │gf │ Jump to another note. │ 382 | │jump_back │n │G │G │ Jump back. │ 383 | │explore │n │ │ Open parent folder. │ 384 | │nextKeyElement │n │ │ │ Go/Focus the next element │ 385 | │ │ │ │ │ (title, link, checkbox). │ 386 | │prevKeyElement │n │ │ │ Go/Focus previous element. │ 387 | │nextTitle │n │ │ │ Go/Focus the next title. │ 388 | │prevTitle │n │ │ │ Go/Focus previous title. │ 389 | └──────────────────┴────┴────────────┴─────────────┴─────────────────────────────┘ 390 | 391 | If you do nothing, then the "Default Keys" will be used. 392 | *g:zim_dev_keys* 393 | You can use the keys used by the 2nd developer "Dev Keys" by adding 394 | the following line to your configuration file : > 395 | let g:zim_dev_keys=1 396 | < 397 | Note: This setting will override every definition of g:zim_keymapping, 398 | because it is the best keymap definition. 399 | 400 | The "dev" keys are defined like this: > 401 | let g:zim_keymapping={ 402 | \ '':'', 403 | \ 'continue_list':'', 404 | \ 'jump':'gf', 405 | \ 'jump_back':'G', 406 | \ 'bold':'b', 407 | \ 'italic':'i', 408 | \ 'highlight':'h', 409 | \ 'strike':'s', 410 | \ 'title':'t', 411 | \ 'header':'H', 412 | \ 'li':'l', 413 | \ 'checkbox':'c', 414 | \ 'checkbox_yes':'y', 415 | \ 'checkbox_no':'n', 416 | \ 'checkbox_moved':'>', 417 | \ 'date':'d', 418 | \ 'datehour':'D', 419 | \ 'showimg': '', 420 | \ 'editimg': '', 421 | \ 'showfile':'', 422 | \ 'editfile':'', 423 | \ 'nextKeyElement':'', 424 | \ 'prevKeyElement':'', 425 | \ 'nextTitle':'', 426 | \ 'prevTitle':'', 427 | \} 428 | < 429 | ============================================================================== 430 | API *zim-api* 431 | 432 | Functions you can use : 433 | 434 | zim#util#line({array}) 435 | A complex function to find a line number. 436 | see |g:zim_open_jump_to| |zim#util#line()| 437 | 438 | zim#util#open({openning-window},{edit-opt},{focus},{file}) 439 | A function for file in a split or in current window. 440 | {openning-window} contains commands to create split 441 | {edit-opt} contains the commands like 'noswapfile' 442 | {focus} is a 0 or 1 value to say to focus on new buffer 443 | {file} is the file full path 444 | 445 | 446 | ============================================================================== 447 | TRICKY THINGS *zim-tricky* 448 | 449 | Setup a TODOLIST *zim-todolist* 450 | ---------------- 451 | In your vimrc file, add > 452 | 453 | function! s:todolist(whereopen) 454 | call zim#util#open( 455 | \ a:whereopen, 456 | \ 'noswapfile', 457 | \ 1, 458 | \ g:zim_notebooks_dir.'/Notes/TODO.txt') 459 | 460 | " find to first empty checkbox; find the title of the section it belong 461 | " and make this title to be the second line of the window 462 | exe zim#util#line([ 463 | \ '==.*==', 464 | \ '\[ \].*', 465 | \ {'get': 1, 'sens':-1}, 466 | \ '==.*==', 467 | \ {'scroll': ['top',1], 'set':1} 468 | \ ]) 469 | 470 | " put highlight on current line 471 | hi CursorLine gui=bold guibg=white guifg=black 472 | setlocal cul 473 | 474 | endfunction 475 | command! Todo :silent call s:todolist('vertical leftabove split') 476 | 477 | function! s:autostart() 478 | if !exists('g:loaded_todo') && empty(bufname('%')) 479 | call s:todolist('') 480 | let g:loaded_todo=1 481 | endif 482 | endfunction 483 | 484 | augroup _zim_autostart | autocmd! 485 | autocmd VimEnter silent call s:autostart() 486 | augroup END 487 | < 488 | 489 | ============================================================================== 490 | vim:tw=78:fo=tcq2:isk=!-~,^*,^\|,^\":ts=8:ft=help:norl: 491 | -------------------------------------------------------------------------------- /ftdetect/zim.vim: -------------------------------------------------------------------------------- 1 | function! Ftdetect_zim() 2 | " No change if we didn't start with a txt file 3 | if &ft != '' && &ft != 'text' 4 | return 5 | endif 6 | if getline(1) =~ "Content-Type: text/x-zim-wiki" 7 | \ || expand('%') =~ g:zim_notebooks_dir 8 | set ft=zim 9 | endif 10 | endfunction 11 | 12 | 13 | augroup Zim 14 | for s:ext in get(g:, 'zim_note_extensions', ['txt']) 15 | exe 'au BufNewFile,BufRead *.'.s:ext.' call Ftdetect_zim()' 16 | endfor 17 | augroup END 18 | -------------------------------------------------------------------------------- /ftplugin/zim.vim: -------------------------------------------------------------------------------- 1 | " c style comments 2 | setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,:// 3 | -------------------------------------------------------------------------------- /plugin/zim.vim: -------------------------------------------------------------------------------- 1 | " Zim Utilities Plugin 2 | " Author: Jack Mudge 3 | " * I declare this file to be in the public domain. 4 | " 5 | " Last Change: 2017 July 18 6 | " Maintainer: Luffah 7 | " Version: 1.1 8 | " 9 | " Changelog: 10 | " 2016-09-12 - Jack Mudge - v0.1 11 | " * Initial creation. 12 | " 2017-05-25 - luffah - v0.2 13 | " * Mod. CreateZimHeader to zim#editor#CreateHeader 14 | " + minimal support of Linux strftime() + automatic title 15 | " * Keymappings 16 | " + limited to zim buffers + stored in g:zim_keymapping 17 | " * Add a gettext like function 18 | " * In insert mode : add bullet, numbering, or checkbox 19 | " on with the result of ZimNextBullet 20 | " 2017-06-07 - luffah - v0.3 21 | " * Add note and notebook creation commands 22 | " * Add workarounds to force Zim re-indexing 23 | " 2017-06-13 - luffah - v1 24 | " * Add notebook navigation features 25 | " 2017-06-07 - luffah - v1.1 26 | " * Interaction with others files types 27 | " * Add images insertion 28 | " 2018-06-15 - luffah - v1.2 29 | " * Add codeblock support 30 | " * Add [>] moved checkbox 31 | " * Now conceal url link (to only see the title) 32 | " * Can fill a note from a web page. 33 | " 2020-07-21 - luffah - v1.3 34 | " * Add variable g:zim_note_extensions to define additionnal extensions 35 | " 36 | " What This Plugin Does: 37 | " * Provides shortcuts and helpful mappings to work with Zim wiki formatting. 38 | " This is primarily intended for using the 'Edit Source' functionality in 39 | " Zim, but may be useful to create new files in a Zim folder. 40 | " * Add bullet, incremental, numbering, checkboxes on in insert mode 41 | " * Note navigation and creation 42 | " 43 | " What This Plugin Does Not: 44 | " * Doesn't add bullets, numbering, or checkboxes on in visual mode 45 | " * Doesn't reindex Zim (see Bugs) nor reorganize notes 46 | " /** IF YOU WANT TO UPDATE ZIM INDEX FROM VIM ** 47 | " On Linux you can choose to use the deprecated ZimBrutalUpdate command. 48 | " To use this command you need to enable it 49 | " in vimrc : let g:zim_brutal_update_allowed=1 50 | " OR 51 | " to setup shortcut key (F5) in $HOME/.config/zim/accelmap 52 | " and define it in your configuration allowing 53 | " the plugin to update index when a note is created (ZimNewNote command) 54 | " in vimrc : let g:zim_update_index_key="F5" 55 | " in accelmap : (gtk_accel_path "/GtkInterface/reload_index" "F5") 56 | " **/ 57 | " Known Bugs: 58 | " * Zim issue: New files aren't shown in Zim index until restart of zim. 59 | " This can be forced with the command `zim --index`, but indexing 60 | " while zim is running will corrupt index. 61 | " If you encounter problems with index, stop zim, remove zim index 62 | " from your cache. (Linux: rm -rf $HOME/.cache/zim) 63 | " If you want to reindex living Zim Notebook, click on Zim menu : 64 | " 'Tools' > 'Update Index' 65 | " 66 | """""""""""""""""""""""""""""""" 67 | " Plugin init 68 | " (for developpers who wants to test ':let g:zim_dev=1 | source %') 69 | if (!get(g:,'zim_dev',0) && get(g:,'loaded_zim',0)) || &cp | finish | endif 70 | 71 | "'"'""'"'"'"'"'"'"'"'"'"'"'"'"'" 72 | "" 73 | " Globally avaible commands (other commands are defined in zim/note.vim) 74 | " 75 | command! ZimSelectNotebook :call zim#explorer#SelectNotebook('split') 76 | command! ZimCreateHeader :call zim#editor#CreateHeader() 77 | command! -nargs=* ZimGrep :silent! call zim#explorer#SearchTermInNotebook() 78 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes ZimNewNote :call zim#note#Create('rightbelow vertical split',g:zim_notebook,) 79 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes ZimOpen :call zim#util#open('rightbelow vertical split',g:zim_notebook,) 80 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes ZimList :call zim#explorer#List('tabnew',g:zim_notebook,) 81 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes ZimCopy :call zim#note#Move(1, ) 82 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes ZimMove :call zim#note#Move(0, ) 83 | command! -nargs=1 -complete=customlist,zim#util#_CompleteBook ZimCD :exe "let g:zim_notebook='".g:zim_notebooks_dir.'/'.."'" 84 | command! -nargs=1 ZimCreateNoteBook :call zim#note#CreateNoteBook() 85 | 86 | command! -nargs=1 -complete=customlist,zim#util#_CompleteEditCmdI ZimCmd :call zim#util#cmd('n',,1) 87 | command! -nargs=1 -complete=customlist,zim#util#_CompleteEditCmdV -range ZimCmdV :call zim#util#cmd('v',,1) 88 | command! ZimServer :call system('zim --server --gui '.g:zim_notebook .' '.get(g:,'zim_server_options','').' &') 89 | command! -nargs=1 ZimInjectHtml call s:injecthtml() 90 | 91 | command! -nargs=* -complete=customlist,zim#util#_CompleteNotes 92 | \ ZimNewNoteFromWeb call zim#note#Create('tabnew',g:zim_notebook,) 93 | \ | call s:injecthtml(input('Url ? ')) 94 | 95 | fu! s:injecthtml(url) 96 | if(a:url =~ '^https\?:' ) 97 | exe 'silent read !curl '.a:url.' 2> /dev/null | pandoc -f html -t zimwiki' 98 | elseif ( a:url =~ '.[px]\?html$' ) 99 | exe 'silent read !cat '.a:url.' | pandoc -f html -t zimwiki' 100 | else 101 | echo zim#util#gettext('Invalid url') 102 | endif 103 | endfu 104 | 105 | 106 | " Clean all formats that Zim doesn't currently support 107 | " For now : 108 | " - markdown codeblocks 109 | command! ZimCleanNote call s:clean_zim_note() 110 | fu! s:clean_zim_note() 111 | let l:li = 1 112 | let l:md_codeblock_start = 0 113 | while l:li <= line('$') 114 | let l:l=getline(l:li) 115 | if l:l =~ '^\s*```\s*\w\+.*$' 116 | let l:md_codeblock_start = l:li 117 | elseif l:md_codeblock_start && l:l =~ '^\s*```\s*$' 118 | call setline(l:li, 119 | \ substitute(l:l, '```','}}}','')) 120 | call setline(l:md_codeblock_start, 121 | \ substitute(getline(l:md_codeblock_start), '```\s*\(\w\+\)','{{{code lang="\1"', '')) 122 | let l:md_codeblock_start = 0 123 | endif 124 | 125 | let l:li = l:li + 1 126 | endwhile 127 | endfu 128 | 129 | 130 | " The matchable dict activate commands ZimMatchNext.. and ZimMatchPrev... 131 | let g:zim_matchable=get(g:,'zim_matchable',{ 132 | \'KeyElement': '\(' . 133 | \ '==' . 134 | \ '\|{{' . 135 | \ '\|\*'. 136 | \ '\|\[\(\[\| \)' . 137 | \ '\|\d\+\.\s' . 138 | \ '\|/[.a-zA-Z0-9]\+' . 139 | \ '\)', 140 | \'Title': '^\(=\+\).*\1$', 141 | \'Checkbox': '^\(\s\{4}\)*\[[ ]\]\(\s\|$\)', 142 | \'Li': '^\(\s\{4}\|\t\)*\*\(\s\|$\)', 143 | \'NumberedItem': '^\(\s\{4}\|\t\)*\d\+\.\(\s\|$\)', 144 | \'Link': '\[\[.*\]\]', 145 | \'Img': '{{.*}}', 146 | \'File': '\(\~\|\.\|^\| \|{\|\[\)/[.a-zA-Z0-9]\+', 147 | \'Url': 'http[s]\?://[.a-zA-Z0-9]\+', 148 | \ }) 149 | 150 | if !has("win32") 151 | if get(g:,'zim_brutal_update_allowed', 0) 152 | command! ZimBrutalUpdate :silent !pkill -9 zim; zim & 153 | elseif exists(':ZimBrutalUpdate') 154 | delcommand ZimBrutalUpdate 155 | endif 156 | endif 157 | 158 | let g:zim_notebooks_dir=get(g:,'zim_notebooks_dir',expand("~/Notebooks")) 159 | let g:zim_notebook=get(g:,'zim_notebook',g:zim_notebooks_dir) 160 | 161 | "'"'""'"'"'"'"'"'"'"'"'"'"'"'"'" 162 | "" 163 | " PARAMETRIC PART 164 | " 165 | " Read this file if you want to customize zim.vim 166 | " 167 | "" External programs 168 | "if !has("win32") 169 | "else 170 | let g:zim_img_capture=get(g:,'zim_img_capture','sleep 2; scrot -s') 171 | " Note : in '\..*$','xdg-open', 1 172 | " '\..*$' is a vim regular expression for any file extension 173 | " 'xdg-open' is the program 174 | " 1 express cardinality, it says to open one file per program 175 | " if is not present, 176 | " then all files in a file list matching the .ext 177 | " will be openned within the same command 178 | " Example of cardinality for a selection of 3 filenames 179 | " 1 -> 'program file1.ext; program file2.ext; program file3.ext' 180 | " none or 0 -> 'program file1.ext file2.ext file3.ext' 181 | let g:zim_img_viewer=get(g:,'zim_img_viewer',['\..*$','xdg-open',1]) 182 | let g:zim_img_editor=get(g:,'zim_img_editor',['\..*$','xdg-open',1]) 183 | let g:zim_ext_viewer=get(g:,'zim_ext_viewer',['\..*$','xdg-open',1]) 184 | let g:zim_ext_editor=get(g:,'zim_ext_editor',['\..*$','xdg-open',1]) 185 | "endif 186 | "" 187 | " Actions and keymapping : how it works ? 188 | " 189 | " Actions in the editor pane are defined by reference 190 | " idem for the keys. 191 | " 192 | " The commands for the commands (protocol) are defined in g:zim_edit_actions, 193 | " and the keys are defined in g:zim_keymapping. 194 | " 195 | " Default configuration provide a good example 196 | " 197 | "" Actions 198 | let s:ed=":call zim#editor#" 199 | let g:zim_edit_actions=get(g:,'zim_edit_actions', { 200 | \ '': { 'i' : ':silent call zim#editor#CR("")i' }, 201 | \ 'explore':{ 'n' : ':silent call zim#explorer#List("vertical leftabove split", g:zim_notebook, strpart(expand("%:p:h"),len(g:zim_notebooks_dir) +1))' }, 202 | \ 'jump':{ 'n' : s:ed.'JumpToLinkUnderCursor()' }, 203 | \ 'jump_back':{ 'n' : ':exe "buffer ".b:zim_last_backlink ' }, 204 | \ 'continue_list':{ 'n' : ':put=zim#editor#NextBullet(getline(''.''))$a' }, 205 | \ 'title': { 'n': s:ed.'Title()' }, 206 | \ 'header': { 'n': s:ed.'CreateHeader()' }, 207 | \ 'showimg': { 208 | \ 'v': s:ed.'ShowImageBulk(g:zim_img_viewer)', 209 | \ 'n': s:ed.'ShowImage(g:zim_img_viewer)' 210 | \}, 211 | \ 'editimg': { 212 | \ 'v': s:ed.'ShowImageBulk(g:zim_img_editor)', 213 | \ 'n': s:ed.'ShowImage(g:zim_img_editor)' 214 | \}, 215 | \ 'showfile': { 216 | \ 'v': s:ed.'ShowFileBulk(g:zim_ext_viewer)', 217 | \ 'n': s:ed.'ShowFile(g:zim_ext_viewer)' 218 | \}, 219 | \ 'editfile': { 220 | \ 'v': s:ed.'ShowFileBulk(g:zim_ext_editor)', 221 | \ 'n': s:ed.'ShowFile(g:zim_ext_editor)' 222 | \}, 223 | \ 'all_checkbox_to_li': { 'n': ':%s/^\(\s*\)\[ \]/\1*/' }, 224 | \ 'li': { 'n': s:ed."Bullet('*')", 'v': s:ed."BulletBulk('*')" }, 225 | \ 'checkbox': { 'n': s:ed."Bullet('[ ]')", 'v': s:ed."BulletBulk('[ ]')"}, 226 | \ 'checkbox_yes': { 'n': s:ed."Bullet('[*]')", 'v': s:ed."BulletBulk('[*]')"}, 227 | \ 'checkbox_no': { 'n': s:ed."Bullet('[x]')", 'v': s:ed."BulletBulk('[x]')"}, 228 | \ 'checkbox_moved': { 'n': s:ed."Bullet('[>]')", 'v': s:ed."BulletBulk('[>]')"}, 229 | \ 'date': { 'n': ':exe "norm a".strftime(zim#util#gettext("dateformat"))'}, 230 | \ 'datehour': { 'n': ':exe "norm a".strftime(zim#util#gettext("datehourformat"))'}, 231 | \ 'bold':{ 232 | \ 'v': s:ed.'ToggleStyleBlock("**")', 233 | \ 'n': s:ed.'ToggleStyle("**")' 234 | \ }, 235 | \ 'highlight':{ 236 | \ 'v': s:ed.'ToggleStyleBlock("__")', 237 | \ 'n': s:ed.'ToggleStyle("__")' 238 | \ }, 239 | \ 'strike': { 240 | \ 'v': s:ed.'ToggleStyleBlock("~~")', 241 | \ 'n': s:ed.'ToggleStyle("~~")' 242 | \ }, 243 | \ 'italic': { 244 | \ 'v' : s:ed.'ToggleStyleBlock("//")', 245 | \ 'n' : s:ed.'ToggleStyle("//")' 246 | \ } 247 | \}) 248 | 249 | "" Default keymapping 250 | if get(g:,'zim_dev_keys',0) 251 | let g:zim_keymapping={ 252 | \ '':'', 253 | \ 'continue_list':'', 254 | \ 'jump':'gf', 255 | \ 'jump_back':'g', 256 | \ 'bold':'b', 257 | \ 'italic':'i', 258 | \ 'highlight':'h', 259 | \ 'strike':'s', 260 | \ 'title':'t', 261 | \ 'header':'h', 262 | \ 'li':'l', 263 | \ 'checkbox':'c', 264 | \ 'checkbox_yes':'y', 265 | \ 'checkbox_no':'n', 266 | \ 'checkbox_moved':'>', 267 | \ 'date':'d', 268 | \ 'datehour':'d', 269 | \ 'explore':'', 270 | \ 'showimg': '', 271 | \ 'editimg': '', 272 | \ 'showfile':'', 273 | \ 'editfile':'', 274 | \ 'nextkeyelement':'', 275 | \ 'prevkeyelement':'', 276 | \ 'nexttitle':'', 277 | \ 'prevtitle':'', 278 | \} 279 | else 280 | let g:zim_keymapping=get(g:,'zim_keymapping', { 281 | \ '':'', 282 | \ 'continue_list':'', 283 | \ 'jump':'g', 284 | \ 'jump_back':'g', 285 | \ 'bold':'wb', 286 | \ 'italic':'wi', 287 | \ 'highlight':'wh', 288 | \ 'strike':'ws', 289 | \ 'title':'wt', 290 | \ 'header':'wh', 291 | \ 'all_checkbox_to_li':'', 292 | \ 'li':'wl', 293 | \ 'checkbox':'wc', 294 | \ 'checkbox_yes':'', 295 | \ 'checkbox_no':'', 296 | \ 'date':'wd', 297 | \ 'datehour':'wd', 298 | \ 'explore':'', 299 | \ 'showimg':'', 300 | \ 'editimg':'', 301 | \ 'showfile':'', 302 | \ 'editfile':'', 303 | \ }) 304 | endif 305 | 306 | 307 | "" Zim Wiki format : to be change if wiki format change... 308 | let g:zim_wiki_version=get(g:,'zim_wiki_version','0.4') 309 | 310 | """ Files extensions for a Zim note 311 | let g:zim_note_extensions=get(g:,'zim_note_extensions', ['txt']) 312 | let g:zim_note_extension=get(g:,'zim_note_extension', g:zim_note_extensions[0]) 313 | 314 | """ Configuration dir of Zim 315 | let g:zim_config_dir=get(g:,'zim_config_dir','') 316 | if (!len(g:zim_config_dir)) 317 | if has('win32') 318 | let g:zim_config_dir='' 319 | else 320 | let g:zim_config_dir=$XDG_CONFIG_HOME 321 | if (!len(g:zim_config_dir)) 322 | let g:zim_config_dir=expand('$HOME/.config') 323 | endif 324 | let g:zim_config_dir.='/zim' 325 | endif 326 | endif 327 | "" When g:zim_open_skip_header is set to true (1), 328 | "" the note is openned on the first line after the header. 329 | let g:zim_open_skip_header=get(g:,'zim_open_skip_header',1) 330 | 331 | "" The array g:zim_open_jump_to allow you to begin note editing where you want. 332 | "" This is done by a succession of movements determining the cursor position. 333 | 334 | "" The array can contain 3 types of variables, with different meanings 335 | "" dict { 'init': 'a line position', 'sens' : (-1 or 1) line step for searching text } 336 | "" string text pattern e.g. Creation 337 | "" integer line delta e.g. -1 to go back 1 line 338 | "" 339 | "" Go to the last title and jump 2 line 340 | let g:zim_open_jump_to=get(g:,'zim_open_jump_to', 341 | \ [{'init': '$', 'sens': -1}, "==.*==", 2]) 342 | 343 | 344 | "" 345 | " Messages 346 | let g:zim_wiki_lang=get(g:,'zim_wiki_lang','fr') 347 | let g:zim_wiki_prompt={ 348 | \ 'en' : { 'note_name' : 'Name of the new note', 349 | \ 'dateformat': "%d/%m/%Y", 350 | \ 'datehourformat': "%d/%m/%Y %H:%M", 351 | \ 'title_level': "Title level (between 1 and 5 , else remove style)", 352 | \ 'note_out_of_notebook': "Notes shall be created in a notebook... Aborting", 353 | \ 'input_text': 'Text', 354 | \ '?continue_list': 'Create a new bullet under current', 355 | \ '?jump': 'Jump to File or Note', 356 | \ '?jump_back': 'Jump back...', 357 | \ '?bold': 'Format **bold**', 358 | \ '?italic': 'Format //italic//', 359 | \ '?highlight': 'Format __hightlighted__', 360 | \ '?strike': 'Format ~~striked through~~', 361 | \ '?title': 'Format = Title =', 362 | \ '?header': 'Add Zim file header', 363 | \ '?all_checkbox_to_li': 'Convert checkboxes to list', 364 | \ '?li': 'Make current line a list item', 365 | \ '?checkbox': 'Make an empty checkbox', 366 | \ '?checkbox_yes': 'Validate checkbox', 367 | \ '?checkbox_no': 'Invalidate checkbox', 368 | \ '?date': 'Insert date', 369 | \ '?datehour': 'Insert date with hour', 370 | \ '?explore': 'View the note explorer', 371 | \ '?showimg': 'Open image in an external tool', 372 | \ '?editimg': 'Edit image in an external tool', 373 | \ '?showfile': 'Open file in an external tool', 374 | \ '?editfile': 'Edit file in an external tool', 375 | \ }, 376 | \ 'fr' : { 'note_name' : 'Nom de la nouvelle note', 377 | \ 'dateformat': "%d/%m/%Y", 378 | \ 'datehourformat': "%d/%m/%Y %H:%M", 379 | \ 'title_level': "Niveau de titre (de 1 à 5 , sinon retire le style)", 380 | \ "'%s' created": "La note %s a été créée", 381 | \ "NoteBook '%s' created": "Le bloc-note %s a été créée", 382 | \ 'note_out_of_notebook': "Impossible de créer une note en dehors d'un bloc-note !", 383 | \ "Note '%s' already exists" : "La note '%s' existe déjà", 384 | \ "Directory '%s' already exists" : "Le Répertoire des sous-notes '%s' est existe déjà", 385 | \ "NoteBook '%s' not exists" : "Le bloc-note '%s' n'existe pas. Il faut d'abord le créer dans Zim...", 386 | \ "NoteBook '%s' already exists" : "Le bloc-note '%s' existe déjà.", 387 | \ "Zim Header already exists" : "Le fichier présente déja une entète Zim", 388 | \ 'Close this window' : 'Quitter', 389 | \ 'Preview' : 'Visualiser sans bouger', 390 | \ 'Open note' : 'Ouvrir la note sous le curseur', 391 | \ 'Update view' : 'Rafraichir', 392 | \ 'Modify filter' : 'Modifier le filtre', 393 | \ 'Detect doubles names' : 'Détecter les notes qui porte le même nom', 394 | \ 'Disable doubles detection (%d founds)' : 'Ne plus détecter les doublons (%d restant)', 395 | \ 'input_text': 'Texte', 396 | \ 'Cannot move a note into itself !': 'Impossible de déplacer une note dans elle-même !', 397 | \ 'Find Next double': 'Atteindre le doublon suivant', 398 | \ 'Delete note': 'Supprimer la note (irreversible)', 399 | \ 'Create note': 'Créer un nouvelle note à coté de la note sous le curseur', 400 | \ 'Rename note under cursor': 'Renommer la note sous le curseur', 401 | \ 'Move note under cursor': 'Sélectionner la note pour déplacement', 402 | \ 'Place the note under cursor (moving %s)': 'Déplacer la note (%s) sélectionnée à coté de la note sous le curseur', 403 | \ } 404 | \} 405 | for s:i in keys(g:zim_matchable) 406 | let g:zim_wiki_prompt['en']['?next'.s:i]='Move cursor to next '.s:i 407 | endfor 408 | for s:i in keys(g:zim_matchable) 409 | let g:zim_wiki_prompt['en']['?prev'.s:i]='Move cursor to previous '.s:i 410 | endfor 411 | let g:loaded_zim=1 412 | -------------------------------------------------------------------------------- /plugin/zim/editor.vim: -------------------------------------------------------------------------------- 1 | "" Create Zim header in a buffer, i.e., for a new file 2 | "" If files are created within Zim, this is already completed 3 | function! zim#editor#CreateHeader(...) 4 | if ( getline(1) =~ "Content-Type: text/x-zim-wiki" 5 | \ && getline(2) =~ "Wiki-Format:" ) 6 | echomsg zim#util#gettext("Zim Header already exists") 7 | return 8 | endif 9 | let l:timest1 = strftime("%Y-%m-%dT%H:%M:%S") 10 | if has("win32") 11 | " Microsoft screwed with strftime() sot that %z returns a description of the time zone. BOOOO Microsoft. 12 | " This calculation converts that to the appropriate numeric representation. (Only for PST/PDT.) 13 | if strftime("%z") == "Pacific Standard Time" 14 | let l:timest2 = "-08:00" 15 | elseif strftime("%z") == "Pacific Daylight Time" 16 | let l:timest2 = "-07:00" 17 | else 18 | throw "Unknown Time Zone: " . strftime("%z") 19 | endif 20 | else 21 | let l:timest2 = substitute(strftime("%z"),'\(+\d\d\)\(\d\d\)','\1:\2','') 22 | endif 23 | "" FIXME txt to multiple ext 24 | let l:note_name=substitute(expand('%:t:s?.txt??'),'_',' ','g') 25 | if empty(l:note_name) 26 | let l:note_name=input( zim#util#gettext('note_name').' ? ') 27 | endif 28 | let l:header=[ 29 | \ "Content-Type: text/x-zim-wiki", 30 | \ "Wiki-Format: zim " . g:zim_wiki_version , 31 | \ "Creation-Date: " . l:timest1 . l:timest2, 32 | \ "", 33 | \ "====== ".l:note_name." ======" 34 | \] 35 | call append(0,l:header) 36 | endfunction 37 | 38 | "" Make a title with the current line 39 | function! zim#editor#Title() 40 | let l:i=line('.') 41 | let l:l=getline(l:i) 42 | let l:rec=0 " 0 -> nothing ; 1 -> do update and rec; 2 -> only do update 43 | let l:spaces=substitute(l:l, '\S.*$','','') 44 | if l:l =~ '^\s*\(=\)\+ ' 45 | let l:pos=match(l:l,'=') 46 | let l:end=match(l:l,' ',l:pos) 47 | let l:lvl=7-(l:end-l:pos) 48 | else 49 | let l:lvl=1 50 | endif 51 | 52 | let l:anystyle_before='^\s*\(===*\)\?\(\*\*\?\)\?\(\[.\]\)\?\s*' 53 | let l:anystyle_after='\s*\(===*\)\?\(\*\*\)\?\s*$' 54 | let l:l=substitute(l:l, l:anystyle_before,'','') 55 | let l:l=substitute(l:l, l:anystyle_after,'','') 56 | let l:titlemark=repeat("=",(7-l:lvl)) 57 | let l:l=l:spaces.l:titlemark.' '.l:l.' '.l:titlemark 58 | call setline(l:i,l:l) 59 | redraw 60 | echomsg zim#util#gettext("title_level")." ? " 61 | let l:chr=getchar() 62 | redraw 63 | if l:chr == "\" 64 | let l:lvl=min([5,1+l:lvl]) 65 | let l:rec=1 66 | elseif l:chr == "\" 67 | let l:lvl=max([1,l:lvl-1]) 68 | let l:rec=1 69 | elseif l:chr == "\" 70 | norm O 71 | elseif l:chr == "\" 72 | norm o 73 | else 74 | let l:lvl=nr2char(l:chr) 75 | if l:lvl == 't' || l:chr == "\" 76 | let l:l=substitute(l:l, l:anystyle_before,'','') 77 | let l:l=substitute(l:l, l:anystyle_after,'','') 78 | call setline(l:i,l:l) 79 | else 80 | let l:rec=2 81 | endif 82 | endif 83 | if (l:lvl =~ '\d') && l:rec 84 | let l:l=substitute(l:l, l:anystyle_before,'','') 85 | let l:l=substitute(l:l, l:anystyle_after,'','') 86 | let l:titlemark=repeat("=",(7-l:lvl)) 87 | let l:l=l:spaces.l:titlemark.' '.l:l.' '.l:titlemark 88 | call setline(l:i,l:l) 89 | redraw 90 | endif 91 | if l:rec == 1 92 | call zim#editor#Title() 93 | endif 94 | endfu 95 | 96 | "" Set the bullet (list or checkbox) for the current line 97 | " @param string bul The bullet : **; [ ]... 98 | function! zim#editor#Bullet(bul) 99 | call setline('.', 100 | \ substitute(getline('.'),'^\(\s*\)\(\[.\]\)\?\(*\)\?\s*','\1'.a:bul.' ','')) 101 | endfu 102 | 103 | function! zim#editor#BulletBulk(bul) 104 | norm gv 105 | let [ l:l1, l:l2]=[line('.'), line('v')] 106 | let [ l:l1, l:l2 ] = l:l1>l:l2 ? [l:l2,l:l1] : [l:l1,l:l2] 107 | let l:i=l:l1 108 | for l:l in getline(l:l1,l:l2) 109 | call setline(l:i, 110 | \ substitute(l:l,'^\(\s*\)\(\[.\]\)\?\(*\)\?\s*','\1'.a:bul.' ','')) 111 | let l:i+=1 112 | endfor 113 | exe ':'.l:l1 114 | exe 'norm '.(l:l2-l:l1).'V' 115 | norm gv 116 | endfu 117 | 118 | "" Get the bullet (list, numbered list, checkbox) for the next line 119 | "" given the current line 120 | function! zim#editor#NextBullet(l) 121 | let l:l=a:l 122 | let l:pos=match(l:l,'\h') 123 | if l:pos > -1 124 | let l:l=strpart(l:l,0,l:pos) 125 | let l:pos=match(l:l,'\S') 126 | let l:ret=strpart(l:l,0,l:pos) 127 | let l:l=strpart(l:l,l:pos) 128 | if l:pos > -1 129 | if l:l =~ '\d\+\.' 130 | let l:ret.=substitute(l:l,'\(\d\+\)\(.\D\)','\=(submatch(1)+1).submatch(2)','') 131 | else 132 | let l:ret.=l:l 133 | endif 134 | endif 135 | else 136 | let l:ret="" 137 | endif 138 | return l:ret 139 | endfu 140 | 141 | "" Insert bullet if we are at the end of the string, else split line 142 | "" the cr substitute char is needed in order to mark the line return 143 | "" before calling this function 144 | function! zim#editor#CR(cr) 145 | let l:pos=col('.') 146 | let l:l=getline('.') 147 | if a:cr 148 | let l:pos=match(l:l,a:cr,l:pos-2) 149 | endif 150 | let l:b=strpart(l:l, 0, l:pos-1) 151 | let l:e=substitute(strpart(l:l, l:pos),'\s*$','','') 152 | call setline('.',l:b) 153 | if len(l:e) 154 | put=l:e 155 | else 156 | if l:b =~ '=' 157 | put=' ' 158 | else 159 | put=zim#editor#NextBullet(l:b).' ' 160 | endif 161 | normal $ 162 | endif 163 | endfu 164 | 165 | "" Add format elements around a string 166 | " @param string bstyle The opening element 167 | " @param string estyle The ending element 168 | " @param int begin The start position of the string to format in the line 169 | " @param int end The end position of the string to format in the line 170 | " @param int lnum Line number 171 | function! s:doZimSetStyle(bstyle,estyle,begin,end,lnum) 172 | let l:l=getline(a:lnum) 173 | let l:l=strpart(l:l, 0, a:begin). 174 | \ a:bstyle. strpart(l:l, a:begin, a:end - a:begin). 175 | \ a:estyle. strpart(l:l, a:end) 176 | call setline(a:lnum,l:l) 177 | endfu 178 | 179 | "" Toogle format elements on a line 180 | " @param string bstyle The opening element 181 | " @param string estyle The ending element 182 | " @param int lnum Line number 183 | function! s:doZimToggleStyle(bstyle,estyle,lnum,lcontent,beginpos) 184 | let l:l=a:lcontent 185 | let l:bstyle=substitute(a:bstyle,'[*~/]','\\\0','g') 186 | let l:estyle=substitute(a:estyle,'[*~/]','\\\0','g') 187 | let l:end=match(l:l,'\%(\s\s\+\|[;,.)}>]\|\]\|\s*$\)',a:beginpos-1) 188 | let l:begin=match(l:l,l:bstyle.'.*'.l:estyle,a:beginpos-1-len(a:bstyle)) 189 | if l:begin>-1 && l:begin < l:end 190 | let l:end=match(l:l,l:estyle,l:begin+len(a:bstyle)) 191 | let l:l=strpart(l:l, 0, l:begin). 192 | \ strpart(l:l, l:begin+len(a:bstyle), l:end - l:begin - len(a:bstyle)). 193 | \ strpart(l:l, l:end+len(a:estyle)) 194 | silent call setline(a:lnum, l:l) 195 | else 196 | let l:begin=match(l:l,'[0-9A-Za-z_éèêëàâäàôöóòíìïîüûúù]',a:beginpos-1) 197 | if l:begin>-1 198 | let l:end=match(l:l,'\%(\s\s\+\|[;,.)}>]\|\]\|\s*$\)',l:begin) 199 | silent call s:doZimSetStyle(a:bstyle, a:estyle , l:begin, l:end, a:lnum) 200 | endif 201 | endif 202 | endfu 203 | 204 | "" Tooggle style on the current line 205 | " @param string style The opening & ending element (used for bold, italic...) 206 | function! zim#editor#ToggleStyle(style) 207 | let l:col=col('.') 208 | let l:i=line('.') 209 | let l:l=getline(l:i) 210 | if l:l[l:col-1]==' ' && index([' ','(',')','<','>','[',']','{','}','.',',',';'],l:l[l:col-2]) 211 | \ && l:l[l:col] !~ '[^[:punct:]]' 212 | " \ && l:l[l:col] !~ '[^();,.{}]\|\[\]' 213 | exe 'norm a'.a:style.' '.a:style 214 | exe 'norm F xi'.input(zim#util#gettext('input_text').' : ') 215 | exe 'norm '.len(a:style).' ' 216 | return 1 217 | endif 218 | let l:mark=' ' 219 | while l:col >1 && l:l[l:col-1] != l:mark 220 | let l:col-=1 221 | endwhile 222 | call s:doZimToggleStyle(a:style,a:style,l:i,l:l,l:col) 223 | endfu 224 | 225 | "" Tooggle style on the selected words 226 | "" if selection is on 1 line toggle from cursor start to end, 227 | "" else toggle style line by line 228 | " @param string style The opening & ending element (used for bold, italic...) 229 | function! zim#editor#ToggleStyleBlock(style) 230 | norm gv 231 | let [ l:l1, l:l2, l:c1, l:c2]=[line('.'), line('v'),col('.'), col('v')] 232 | let [ l:l1, l:l2 ] = l:l1>l:l2 ? [l:l2,l:l1] : [l:l1,l:l2] 233 | let [ l:c1, l:c2 ] = l:c1>l:c2 ? [l:c2,l:c1] : [l:c1,l:c2] 234 | let l:style=substitute(a:style,'[*~/]','\\\0','g') 235 | if l:l1 == l:l2 236 | let l:l = getline(l:l1) 237 | let l:part1=strpart(l:l,0,l:c1-1) 238 | let l:part2=strpart(l:l,l:c1-1,1+l:c2-l:c1) 239 | let l:part3=strpart(l:l,l:c2) 240 | call setpos('.',[0,l:l1,l:c1,0]) 241 | if match(l:l,l:style.'.*'.l:style)>-1 242 | let l:part2=substitute(l:part2, l:style,'','g') 243 | let l:c2-=(2*len(a:style)) 244 | else 245 | let l:part2= a:style.l:part2.a:style 246 | let l:c2+=(2*len(a:style)) 247 | endif 248 | call setline(l:l1,l:part1.l:part2.l:part3) 249 | call setpos('.',[0,l:l1,l:c1,0]) 250 | norm o 251 | call setpos('.',[0,l:l1,l:c2,0]) 252 | else 253 | let l:i=line('.') 254 | for l:l in getline(l:l1,l:l2) 255 | call s:doZimToggleStyle(a:style,a:style,l:i,l:l,1) 256 | let l:i+=1 257 | endfor 258 | endif 259 | endfu 260 | 261 | "" functions to manage links 262 | function! s:get_visual_selection() 263 | let [lnum1, col1] = getpos("'<")[1:2] 264 | let [lnum2, col2] = getpos("'>")[1:2] 265 | let lines = getline(lnum1, lnum2) 266 | let lines[-1] = lines[-1][: col2 - (&selection == 'inclusive' ? 1 : 2)] 267 | let lines[0] = lines[0][col1 - 1:] 268 | return join(lines, "\n") 269 | endfunction 270 | 271 | function! s:getLinkPath(tgt) 272 | let l:tgt='' 273 | if len(a:tgt) 274 | " ignore if it is not in notebook 275 | if match(a:tgt,'^\(\~/\|http[s]\?://\|/\)')> -1 276 | return a:tgt 277 | endif 278 | if match(a:tgt,'^\(href=\)')> -1 279 | return strpart(a:tgt,5) 280 | endif 281 | let l:notebook=expand('%:p:s?'.g:zim_notebooks_dir.'[/]*??:s?/.*$??') 282 | "" FIXME txt to multiple exts 283 | let l:inner_path=expand('%:p:s?'.g:zim_notebooks_dir.'[/]*??:s?^[^/]*[/]*??:s?.txt$?/?') 284 | let l:tgt=substitute( 285 | \ substitute( 286 | \ substitute( 287 | \ substitute(a:tgt,':','/','g'), 288 | \ ' ','_','g'), 289 | \ '\.txt$','','').'.txt', 290 | \ '^\./', l:inner_path,'') 291 | let l:tgt=g:zim_notebooks_dir.'/'.l:notebook.'/'.l:tgt 292 | endif 293 | return l:tgt 294 | endfunction 295 | 296 | function! s:getLinkComponentsUnderCursor(begin,end,sep,...) 297 | let l:keepstart=len(a:000)>0?a:000[0]:0 298 | let l:pos=col('.') 299 | let l:l=getline('.') 300 | let l:pat=a:begin.'.*'.a:end 301 | let [l:b, l:e]=[0,0] 302 | while ((l:e>=0) && (l:b>=0) && (l:pos > l:b + l:e)) 303 | let l:b=match(l:l, l:pat, l:b + l:e) 304 | if (l:b>=0) 305 | let l:bmatch=matchstr(l:l, a:begin, l:b + l:e) 306 | let l:e=match(l:l, a:end, l:b) 307 | endif 308 | endwhile 309 | if (l:b < 0) 310 | return [] 311 | endif 312 | if !l:keepstart 313 | let l:b=l:b+len(l:bmatch) 314 | endif 315 | let l:tgt=strpart(l:l, l:b, l:e-l:b) 316 | return split(l:tgt,a:sep) 317 | endfunction 318 | 319 | function! s:getAllLinkComponentsInStr(str,begin,end,sep,idx) 320 | let l:pat=a:begin.'[a-zA-Z/.0-9éà_-]\+\('.a:end.'\|'.a:sep.'\)' 321 | let l:links=[] 322 | let [l:b, l:e]=[0,0] 323 | while (l:b >= 0 && l:e >=0) 324 | let l:b=match(a:str, l:pat, l:e) 325 | if (l:b>=0) 326 | let l:bmatch=matchstr(a:str, a:begin, l:e) 327 | let l:e=match(a:str, a:end, l:b+len(l:bmatch)) 328 | if (l:e>=0) 329 | let l:b=l:b+len(l:bmatch) 330 | let l:tgt=strpart(a:str, l:b, l:e-l:b) 331 | call add(l:links,split(l:tgt,a:sep)[a:idx]) 332 | endif 333 | endif 334 | endwhile 335 | return l:links 336 | endfunction 337 | 338 | function! zim#editor#JumpToLinkUnderCursor() 339 | let l:components=s:getLinkComponentsUnderCursor('\[\[','\]\]','|') 340 | if empty(l:components) 341 | norm! gF 342 | return 0 343 | endif 344 | let l:path=s:getLinkPath(l:components[0]) 345 | let l:self=expand('%:p') 346 | if len(l:path) 347 | if bufexists(l:path) 348 | exe 'buffer '.l:path 349 | else 350 | exe 'e '.l:path 351 | endif 352 | endif 353 | let b:zim_last_backlink=l:self 354 | endfunction 355 | 356 | """ functions to manage images and external files 357 | function! s:showFiles(imgs, openners) 358 | let l:opens={} 359 | let l:idx=1 360 | let l:cnt=0 361 | for l:i in a:imgs 362 | let l:cnt+=1 363 | let l:path=s:getLinkPath(l:i) 364 | if len(l:path) 365 | for l:j in a:openners 366 | let l:p=l:j[0] 367 | let l:i=str2nr(get(l:j,2,0)) 368 | if (l:i && l:cnt > l:i) 369 | let l:idx+=1 370 | let l:cnt=0 371 | endif 372 | if (match(l:path, l:p) > -1) 373 | let l:k=l:p.'@'.l:idx 374 | if has_key(l:opens, l:k) 375 | let l:opens[l:k].=' '.l:path 376 | else 377 | let l:opens[l:k]=l:j[1].' '.l:path 378 | endif 379 | break 380 | endif 381 | endfor 382 | endif 383 | endfor 384 | echo l:opens 385 | for l:i in keys(l:opens) 386 | " silent exe '!'.l:opens[i].'&' 387 | silent! call system(l:opens[i].' &') 388 | endfor 389 | endfunction 390 | 391 | function! zim#editor#InsertImage(imgfname,captureprg) 392 | let l:imgfname=a:imgfname 393 | if (match(l:imgfname,'^/') < 0) 394 | let l:imgfname='~/'.l:imgfname 395 | endif 396 | if (len(a:captureprg)) 397 | " silent! exe '!'.a:captureprg.' '.l:imgfname.'&' 398 | call system(a:captureprg.' '.l:imgfname) 399 | endif 400 | exe 'norm i{{'.l:imgfname.'?href=#}}' 401 | endfunction 402 | 403 | function! zim#editor#ShowFile(openners) 404 | let l:components=s:getLinkComponentsUnderCursor('\(https://\|http://\|\~/\)','\( \|$\| \|}\|\]\)','\(|\|?\)',1) 405 | if !len(l:components) 406 | let l:components=s:getLinkComponentsUnderCursor('\(^\|{\|\[\|\)/','\(\\ \|$\| \|}\|?\|\]\)','\(|\|?\)') 407 | if len(l:components) 408 | let l:components[0]='/'.l:components[0] 409 | else 410 | return 0 411 | endif 412 | endif 413 | call s:showFiles([l:components[0]],a:openners) 414 | endfunction 415 | 416 | function! zim#editor#ShowFileBulk(openners) range 417 | norm gv 418 | let l:str=substitute(s:get_visual_selection(),'\n',' ','g') 419 | let l:files=map( 420 | \s:getAllLinkComponentsInStr(l:str,'https://','\( \|$\| \|}\|?\|\]\)','\(|\|?\)',0), 421 | \'"https://".v:val') 422 | if empty(l:files) 423 | let l:files=map( 424 | \s:getAllLinkComponentsInStr(l:str,'http://','\( \|$\| \|}\|?\|\]\)','\(|\|?\)',0), 425 | \'"http://".v:val') 426 | endif 427 | if empty(l:files) 428 | let l:files=map( 429 | \s:getAllLinkComponentsInStr(l:str,'\( \|{\|\|\[\|^\)/','\( \|$\| \|}\|?\|\]\)','\(|\|?\)',0), 430 | \'"/".v:val') 431 | endif 432 | 433 | call s:showFiles(l:files, a:openners) 434 | endfunction 435 | 436 | function! zim#editor#ShowImage(openners) 437 | let l:components=s:getLinkComponentsUnderCursor('{{','}}','?') 438 | if empty(l:components) 439 | return 0 440 | endif 441 | call s:showFiles([l:components[0]],a:openners) 442 | endfunction 443 | 444 | function! zim#editor#ShowImageBulk(openners) range 445 | norm gv 446 | call s:showFiles( 447 | \ s:getAllLinkComponentsInStr(s:get_visual_selection(),'{{','}}','?',0), 448 | \ a:openners 449 | \) 450 | endfunction 451 | 452 | function! zim#editor#ShowImageLink() 453 | let l:components=s:getLinkComponentsUnderCursor('{{','}}','?') 454 | if len(l:components) < 2 455 | return 0 456 | endif 457 | let l:path=s:getLinkPath(l:components[1]) 458 | if len(l:path) 459 | echo l:path 460 | endif 461 | endfunction 462 | 463 | -------------------------------------------------------------------------------- /plugin/zim/explorer.vim: -------------------------------------------------------------------------------- 1 | 2 | """""""""""""""""""""""""""""""""""""""""""""""""" 3 | """ The next functions are for notebook navigation 4 | "" 5 | 6 | " Easily change g:zim_notebook 7 | function! zim#explorer#SelectNotebook(whereopen) 8 | if len(a:whereopen) 9 | exe a:whereopen 10 | endif 11 | enew | set buftype=nowrite ft=zimindex | setlocal nowrap cursorline 12 | call setline(1, [ g:zim_notebooks_dir ]+ 13 | \ filter( 14 | \ split(globpath(g:zim_notebooks_dir,'*'),"\n"), 15 | \ 'isdirectory(v:val)') 16 | \) 17 | nnoremap :exe "let g:zim_notebook='".getline('.')."'":q 18 | nnoremap q :q 19 | endfunction 20 | 21 | function! zim#explorer#getLine() 22 | let l:l=b:dir.'/'.substitute(substitute(getline('.'),' : ','/','g'),' |.*$','','') 23 | if l:l =~ '>' || l:l =~ ':' 24 | let l:l='' 25 | endif 26 | let b:current_id=substitute(l:l,g:zim_notebook.'/*','','') 27 | return l:l 28 | endfunction 29 | 30 | function! zim#explorer#interactiveMove() 31 | let l:moving_tgt=zim#explorer#getLine() 32 | if len(b:current_id) 33 | if b:moving_id == '' 34 | if b:current_id =~ '.*\.txt$' 35 | let b:moving_id=b:current_id 36 | endif 37 | else 38 | let l:moving_tgt=substitute(l:moving_tgt,'/[^/]*\.\(txt\|zim\)$','','') 39 | let l:src_file=g:zim_notebook.'/'.b:moving_id 40 | let l:src_dir=substitute(l:src_file,'\.txt$','','') 41 | let l:src_name=substitute(l:src_dir,'.*/\([^/]\)','\1','') 42 | let l:tgt_dir=l:moving_tgt.'/'.l:src_name 43 | let l:tgt_file=l:tgt_dir.'.txt' 44 | if l:src_dir == l:moving_tgt || l:src_file == l:tgt_file 45 | echo zim#util#gettext('Cannot move a note into itself !') 46 | else 47 | echo l:src_file.' -> '.l:tgt_file 48 | if isdirectory(l:src_dir) 49 | silent call zim#util#move(l:src_dir,l:tgt_dir,0,1) 50 | endif 51 | silent call zim#util#move(l:src_file,l:tgt_file,0,0) 52 | endif 53 | let b:moving_id='' 54 | endif 55 | endif 56 | call zim#explorer#ListUpdate() 57 | redraw! 58 | endfunction 59 | 60 | function! zim#explorer#interactiveRename() 61 | call zim#explorer#getLine() 62 | if len(b:current_id) 63 | let l:tgt=substitute(b:current_id,'/[^/]*\.\(txt\|zim\)$','','') 64 | let l:note_name=zim#note#getFilenameFromName( 65 | \input( zim#util#gettext('note_name').' ? ') ) 66 | call zim#note#Move(0,b:current_id,l:tgt.'/'.l:note_name) 67 | endif 68 | silent call zim#explorer#ListUpdate() 69 | endfunction 70 | 71 | function! zim#explorer#interactiveNewNote(whereopen) 72 | let l:curwin=win_getid() 73 | call zim#explorer#getLine() 74 | if len(b:current_id) 75 | let l:tgt=substitute(b:current_id,'\.\(txt\|zim\)$','','') 76 | let l:tgttab=split(l:tgt, '/') 77 | let l:sug=l:tgttab[-1] 78 | let l:tgt=join(l:tgttab[0:-2],'/') 79 | " let l:tgt=substitute(b:current_id,'/[^/]*\.\(txt\|zim\)$','','') 80 | let l:note_name=input( zim#util#gettext('note_name').' ? ',l:sug, 'customlist,zim#util#_CompleteNotes' ) 81 | call zim#note#Create(a:whereopen,g:zim_notebook,l:tgt.'/'.l:note_name) 82 | let l:newwin=win_getid() 83 | endif 84 | call win_gotoid(l:curwin) 85 | call zim#explorer#ListUpdate() 86 | call win_gotoid(l:newwin) 87 | endfunction 88 | 89 | function! zim#explorer#List(whereopen,dir,...) 90 | let l:filter="" 91 | if len(a:000) && len(a:1) 92 | let l:filter=a:1 93 | endif 94 | if len(a:whereopen) 95 | exe a:whereopen 96 | endif 97 | enew | set buftype=nowrite ft=zimindex | setlocal nowrap cursorline 98 | let b:dir=a:dir | let b:filter=l:filter | let b:detect_doubles=0 99 | let b:current_id='' | let b:moving_id='' 100 | "" Openning the file in a vertical new split (vnew) on Return: 101 | nnoremap :call zim#util#open('','', 1, zim#explorer#getLine()) 102 | nnoremap :call zim#util#open((len(tabpagebuflist())>1?'wincmd w':'vertical rightbelow split'),'', 0,zim#explorer#getLine()) 103 | nnoremap u :call zim#explorer#getLine()call zim#explorer#ListUpdate() 104 | nnoremap d :call zim#explorer#getLine()let b:detect_doubles=!b:detect_doublescall zim#explorer#ListUpdate() 105 | nnoremap m :call zim#explorer#interactiveMove() 106 | nnoremap N :call zim#explorer#interactiveNewNote('rightbelow vertical split') 107 | nnoremap R :call zim#explorer#interactiveRename() 108 | nnoremap D :if(input(zim#util#gettext('Delete note').'[Y/n]') !~ "^[Nn]") call system('rm '.zim#explorer#getLine()) endif call zim#explorer#ListUpdate() 109 | exe "nnoremap f :silent call zim#explorer#getLine()let b:filter=input('".zim#util#gettext('Change filter :')."') call zim#explorer#ListUpdate()" 110 | nnoremap q :q 111 | call zim#explorer#ListUpdate() 112 | endfunction 113 | 114 | "" Do a reccursive grep on Notebook 115 | "@param string arg The word to search 116 | function! zim#explorer#SearchTermInNotebook(arg) 117 | if has("win32") 118 | "assuming findstr 119 | let l:grep_opt='/s' 120 | else 121 | "assuming grep 122 | let l:grep_opt='-r' 123 | endif 124 | exe 'silent lgrep! '.l:grep_opt.' '.a:arg.' '.g:zim_notebook 125 | tabnew | ll | lopen 126 | nnoremap q :lclose 127 | nnoremap n :lnext 128 | nnoremap N :lprevious 129 | endfunction 130 | 131 | "" List all notes / if a filter (or a regex) is provided 132 | "" only list the notes corresponding to the filter 133 | "@param string dir The directory to list 134 | "@param string filter A word contained in the file name 135 | function! zim#explorer#getNotesList(dir,filter,detect_doubles) 136 | let l:ret=[] 137 | for l:i in split(globpath(a:dir,'*'),"\n") 138 | if isdirectory(l:i) 139 | " if !(empty(b:moving_id)) 140 | " call add(l:ret, substitute(substitute(l:i,g:zim_notebook.'/*','','') 141 | " \, '/', ' : ', 'g')) 142 | " let b:line_count+=1 143 | " endif 144 | call extend(l:ret ,zim#explorer#getNotesList(l:i,a:filter,0)) 145 | else 146 | let l:i=substitute(l:i,g:zim_notebook.'/*','','') 147 | if b:current_id == l:i 148 | let b:selected_idx_in_list=b:line_count 149 | endif 150 | if b:moving_id == l:i 151 | call add(l:ret, substitute(l:i.' | MOVING ', '/', ' : ', 'g')) 152 | let b:line_count+=1 153 | elseif l:i =~ a:filter 154 | call add(l:ret, substitute(l:i, '/', ' : ', 'g')) 155 | let b:line_count+=1 156 | endif 157 | endif 158 | endfor 159 | if a:detect_doubles 160 | let l:fnames={} 161 | for l:i in range(len(l:ret)) 162 | let l:fname=substitute(l:ret[l:i],'.* : \([^:]*\.txt\)','\1','') 163 | if has_key(l:fnames, l:fname) 164 | let l:ret[l:i].=' |' 165 | let l:ret[l:fnames[l:fname][0]].=' |' 166 | let l:fnames[l:fname]+=[l:i] 167 | let b:nb_doubles+=1 168 | else 169 | let l:fnames[l:fname]=[l:i] 170 | endif 171 | endfor 172 | let l:fnames=filter(l:fnames,'len(v:val)>1') 173 | let b:doubles=[[0,0],values(l:fnames)] 174 | endif 175 | return l:ret 176 | endfunction 177 | 178 | 179 | "" List all notes / if a filter (or a regex) is provided 180 | "" only list the notes corresponding to the filter 181 | "@param string dir The directory to list 182 | "@param string [opt] A word contained in the file name 183 | function! zim#explorer#ListUpdate() 184 | if exists('b:dir') && exists('b:filter') 185 | let b:i=line('.') 186 | setlocal modifiable 187 | let b:selected_idx_in_list=-1 188 | let b:nb_doubles=0 189 | let b:line_count=0 190 | let l:note_list=zim#explorer#getNotesList(b:dir, b:filter, b:detect_doubles) 191 | let l:head=[ 192 | \ '<-- Zim --> '.b:dir.' % '.b:filter, 193 | \ ' -> '.zim#util#gettext('Open note'), 194 | \ ' -> '.zim#util#gettext('Preview'), 195 | \ 'u -> '.zim#util#gettext('Update view'), 196 | \ 'f -> '.zim#util#gettext('Modify filter'), 197 | \ 'd -> '.(b:detect_doubles ? printf(zim#util#gettext('Disable doubles detection (%d founds)'), b:nb_doubles) : zim#util#gettext('Detect doubles names')) ] + 198 | \ ( b:nb_doubles ? [ 'n -> '.zim#util#gettext('Find next double') ] : [] ) 199 | \ + [ 200 | \ 'D -> '.zim#util#gettext('Delete note') , 201 | \ 'N -> '.zim#util#gettext('Create note') , 202 | \ 'm -> '.(empty(b:moving_id) ? zim#util#gettext('Move note under cursor') : printf(zim#util#gettext('Place the note under cursor (moving %s)'),b:moving_id)), 203 | \ 'R -> '.zim#util#gettext('Rename note under cursor') , 204 | \ 'q -> '.zim#util#gettext('Close this window'), 205 | \ '-------- -> -------------------------------'] 206 | %delete 207 | call setline(1, 208 | \ l:head + 209 | \ l:note_list 210 | \ ) 211 | let b:first_line=(len(l:head)+1) 212 | if (b:selected_idx_in_list > -1) 213 | let b:i = b:first_line + b:selected_idx_in_list 214 | endif 215 | let b:i = (b:i < b:first_line ? b:first_line : b:i ) 216 | 217 | exe b:i 218 | setlocal nomodifiable 219 | if (b:nb_doubles) 220 | nnoremap n :call zim#explorer#NextDouble() 221 | else 222 | silent! nunmap n 223 | endif 224 | endif 225 | endfunction 226 | """ 227 | 228 | function! zim#explorer#NextDouble() 229 | exe b:doubles[1][b:doubles[0][0]][b:doubles[0][1]] + b:first_line 230 | let b:doubles[0][1]+=1 231 | if (b:doubles[0][1]+1>len(b:doubles[1][b:doubles[0][0]])) 232 | let b:doubles[0][0]=(b:doubles[0][0]+1)%len(b:doubles[1]) 233 | let b:doubles[0][1]=0 234 | endif 235 | endfunction 236 | 237 | 238 | 239 | 240 | -------------------------------------------------------------------------------- /plugin/zim/note.vim: -------------------------------------------------------------------------------- 1 | function! zim#note#getFilenameFromName(name) 2 | let l:fname=substitute(a:name,'\([ !?:\*]\)\+','_','g') 3 | let l:fname=substitute(l:fname,"'",'_','g') 4 | "" FIXME .txt to multiple ext 5 | let l:fname=substitute(l:fname,'\(\.txt\)\?$','.txt','g') 6 | return l:fname 7 | endfu 8 | 9 | "" Create Zim Note in a buffer, i.e., for a new file 10 | " @param string dir Notebook dir 11 | " @param string name Path to the note 12 | function! zim#note#Create(whereopen,dir,name) 13 | if !len(a:name) 14 | echomsg zim#util#gettext('note_out_of_notebook') 15 | return 16 | endif 17 | let l:nsplit=split(a:name.'/','/') 18 | let l:note_name=l:nsplit[-1] 19 | let l:note_dir=join(l:nsplit[0:-2],'/') 20 | if empty(l:note_name) 21 | let l:note_name=input( zim#util#gettext('note_name').' ? ') 22 | endif 23 | 24 | let l:note=a:dir.'/'.l:note_dir.'/'.zim#note#getFilenameFromName(l:note_name) 25 | "" FIXME .txt to multiple ext 26 | if l:note !~ g:zim_notebooks_dir.'/.*/.*.txt' 27 | echomsg zim#util#gettext('note_out_of_notebook') 28 | else 29 | let l:dirs=split(substitute( 30 | \substitute(l:note,'/[^/]*$','',''),g:zim_notebooks_dir,'',''),'/') 31 | if isdirectory(g:zim_notebooks_dir.'/'.l:dirs[0]) 32 | if len(a:whereopen) 33 | exe a:whereopen 34 | endif 35 | if !filereadable(l:note) 36 | " path begin with Notebook name 37 | let l:notebook=l:dirs[0] 38 | call remove(l:dirs,0) 39 | let l:path=l:notebook 40 | for l:i in l:dirs 41 | let l:path.='/'.l:i 42 | if !isdirectory(g:zim_notebooks_dir.'/'.l:path) 43 | call mkdir(g:zim_notebooks_dir.'/'.l:path,'p', 0700) 44 | endif 45 | "" FIXME .txt to multiple ext 46 | if !filereadable(g:zim_notebooks_dir.'/'.l:path.'.txt') 47 | call zim#note#Create(a:whereopen,g:zim_notebooks_dir,l:path) 48 | endif 49 | endfor 50 | exe 'e '.l:note 51 | call zim#editor#CreateHeader() 52 | silent exe 'silent w' 53 | if has('win32') 54 | echo "skip chmod" 55 | else 56 | silent exe '!chmod 0700 '.l:note 57 | endif 58 | silent exe 'silent e!' 59 | echomsg printf(zim#util#gettext("'%s' created"),l:note) 60 | if exists('g:zim_update_index_key') 61 | if len(exepath('xdotool')) 62 | exe "silent !xdotool search --name '".l:notebook." - Zim' key ".g:zim_update_index_key 63 | endif 64 | endif 65 | else 66 | echomsg printf(zim#util#gettext("Note '%s' already exists"),l:dirs[0]) 67 | exe 'e '.l:note 68 | endif 69 | else 70 | echomsg printf(zim#util#gettext("NoteBook '%s' not exists"),l:dirs[0]) 71 | endif 72 | endif 73 | endfunction 74 | 75 | 76 | "" Create a new notebook nammed name 77 | function! zim#note#CreateNoteBook(name) 78 | let l:dir=g:zim_notebooks_dir.'/'.substitute(a:name,'\([ :/\*]\)\+','_','g') 79 | let l:file=l:dir.'/notebook.zim' 80 | let l:lines=[ 81 | \ '[Notebook]', 82 | \ 'version='.g:zim_wiki_version, 83 | \ 'name='.a:name, 84 | \ 'interwiki=', 85 | \ 'home=Home', 86 | \ 'icon=', 87 | \ 'document_root=', 88 | \ 'shared=True', 89 | \ 'endofline='.(has('win32')? 'msdos' : 'unix'), 90 | \ 'disable_trash=False', 91 | \ 'profile=', 92 | \] 93 | if !isdirectory(l:dir) 94 | call mkdir(l:dir,'p', 0700) 95 | endif 96 | if !filereadable(l:file) 97 | call writefile(l:lines, l:file, "b") 98 | call zim#note#AppendToNotebooksList(l:dir) 99 | echomsg printf(zim#util#gettext("NoteBook '%s' created"),l:file) 100 | else 101 | echomsg printf(zim#util#gettext("NoteBook '%s' already exists"),l:dir) 102 | endif 103 | endfunction 104 | 105 | 106 | function! zim#note#AppendToNotebooksList(dir) 107 | if len(g:zim_config_dir) 108 | let l:update_zim=input(zim#util#gettext("Say Zim to acknowledge this NoteBook ? [Y/n]")) 109 | if !len(l:update_zim) || l:update_zim =~? '^y' 110 | let l:accounted=readfile(g:zim_config_dir.'/notebooks.list') 111 | if len(l:accounted) 112 | let l:ck=0 113 | for l:i in range(len(l:accounted)) 114 | let l:l=l:accounted[l:i] 115 | if l:ck 116 | if (l:l =~? '^\s*\($\|\[Notebook \)' ) 117 | call insert(l:accounted,(l:i-l:ck).'='.a:dir,l:i) 118 | break 119 | endif 120 | elseif l:l =~? "^\[NotebookList" 121 | " +1 to skip Default 122 | let l:ck=l:i+1 123 | endif 124 | endfor 125 | call writefile(l:accounted,g:zim_config_dir.'/notebooks.list') 126 | else 127 | echomsg printf(zim#util#gettext("Invalid Zim configuration : %s"), 'notebooks.list') 128 | endif 129 | endif 130 | else 131 | echomsg zim#util#gettext("(You shall setup g:zim_config_dir to easily update notebooks.list)") 132 | endif 133 | endfunction 134 | 135 | "" Move a note and its sub notes 136 | function! zim#note#Move(copy,src,tgt) 137 | "" FIXME txt to multiple ext 138 | let l:src_dir=g:zim_notebook.'/'.substitute(a:src,'\(/\|\.txt\)$','','') 139 | let l:src_name=substitute(l:src_dir,'.*/\([^/]\)','\1','') 140 | "" FIXME txt to multiple ext 141 | let l:src_file=l:src_dir.'.txt' 142 | let l:tgt=substitute(a:tgt,'\([ :\*]\)\+','_','g').( a:tgt =~ '/$' ? l:src_name : '') 143 | let l:tgt_dir=g:zim_notebook.'/'.substitute(l:tgt,'\(/\|\.txt\)$','','') 144 | let l:tgt_name=substitute(l:tgt_dir,'.*/\([^/]\)','\1','') 145 | let l:tgt_file=l:tgt_dir.'.txt' 146 | if isdirectory(l:src_dir) && isdirectory(l:tgt_dir) 147 | echomsg printf(zim#util#gettext("Directory '%s' already exists"),l:tgt_dir) 148 | return 0 149 | endif 150 | if filereadable(l:tgt_file) 151 | echomsg printf(zim#util#gettext("Note '%s' already exists"),l:tgt_file) 152 | return 0 153 | endif 154 | let l:dirs=split(substitute( 155 | \substitute(l:tgt_dir,'/[^/]*$','',''),g:zim_notebooks_dir,'',''),'/') 156 | if isdirectory(g:zim_notebooks_dir.'/'.l:dirs[0]) 157 | " Prepare target 158 | " path begin with Notebook name 159 | let l:notebook=l:dirs[0] 160 | let l:tgt_notename=l:dirs[0] 161 | call remove(l:dirs,0) 162 | let l:path=l:notebook 163 | for l:i in l:dirs 164 | let l:path.='/'.l:i 165 | "" FIXME txt to multiple ext 166 | if !filereadable(g:zim_notebooks_dir.'/'.l:path.'.txt') 167 | call zim#explorer#CreateNote(g:zim_notebooks_dir,l:path) 168 | endif 169 | if !isdirectory(g:zim_notebooks_dir.'/'.l:path) 170 | call mkdir(g:zim_notebooks_dir.'/'.l:path,'p', 0700) 171 | endif 172 | endfor 173 | if isdirectory(l:src_dir) 174 | call zim#util#move(l:src_dir,l:tgt_dir,a:copy,1) 175 | endif 176 | call zim#util#move(l:src_file,l:tgt_file,a:copy,0) 177 | if exists('g:zim_update_index_key') 178 | if len(exepath('xdotool')) 179 | exe "silent !xdotool search --name '".l:notebook." - Zim' key ".g:zim_update_index_key 180 | endif 181 | endif 182 | else 183 | echomsg printf(zim#util#gettext("NoteBook '%s' not exists"),l:dirs[0]) 184 | endif 185 | endfunction 186 | 187 | 188 | "" The things that happen on note openning 189 | function! s:setBufferSpecific() 190 | " set buffer properties 191 | setlocal tabstop=4 192 | setlocal softtabstop=4 193 | setlocal shiftwidth=4 194 | 195 | " add commamds avaible for the note 196 | command! -buffer -nargs=* ZimGrepThis :call zim#explorer#SearchInNotebook(expand('')) 197 | command! -buffer -nargs=* ZimListThis :call zim#explorer#List(g:zim_notebook,expand('')) 198 | 199 | command! -buffer -nargs=1 -complete=file ZimImgInsert :call zim#editor#InsertImage(,'') 200 | command! -buffer -nargs=1 -complete=file ZimImgCapture :call zim#editor#InsertImage(,g:zim_img_capture) 201 | 202 | for s:el in keys(g:zim_matchable) 203 | exe 'command! -range -buffer ZimMatchNext'.s:el 204 | \." call setpos(mode()=='n'?'.':\"'>\",[0,zim#util#line([{'default': line('.')},'".g:zim_matchable[s:el]."'],line('.')+1,1),1,0])" 205 | exe 'command! -range -buffer ZimMatchPrev'.s:el 206 | \." call setpos(mode()=='n'?'.':\"'>\",[0,zim#util#line([{'default': line('.')},'".g:zim_matchable[s:el]."'],line('.')-1,-1),1,0])" 207 | 208 | " Add next and prev matchable items to mappable actions (to use it as shortcut) 209 | let g:zim_edit_actions[tolower('next'.s:el)]={ 210 | \'n': ":ZimMatchNext".s:el."", 211 | \'v': ":=execute('norm gv')ZimMatchNext".s:el."gv" 212 | \} 213 | let g:zim_edit_actions[tolower('prev'.s:el)]={ 214 | \'n': ":ZimMatchPrev".s:el."", 215 | \'v': ":=execute('norm gv')ZimMatchPrev".s:el."gv" 216 | \} 217 | endfor 218 | 219 | " add key mappings 220 | for l:k in keys(g:zim_edit_actions) 221 | if has_key(g:zim_keymapping,l:k) 222 | for l:m in keys(g:zim_edit_actions[l:k]) 223 | if len(g:zim_keymapping[l:k]) 224 | exe l:m.'noremap '.g:zim_keymapping[l:k].' '.g:zim_edit_actions[tolower(l:k)][l:m] 225 | endif 226 | endfor 227 | endif 228 | endfor 229 | let l:i=line('.') 230 | if l:i == 1 231 | let l:i=zim#util#line(g:zim_open_jump_to, 1, 1) 232 | endif 233 | if l:i == 1 && g:zim_open_skip_header 234 | while getline(l:i) =~ 235 | \ '^\(Content-Type\|Wiki-Format\|Creation-Date\):' 236 | let l:i+=1 237 | endwhile 238 | endif 239 | exe l:i 240 | endfu 241 | 242 | autocmd! Filetype zim call s:setBufferSpecific() 243 | -------------------------------------------------------------------------------- /plugin/zim/plugins.vim: -------------------------------------------------------------------------------- 1 | let s:zim_python_path='' 2 | let s:zim_not_found=0 3 | 4 | function! zim#plugins#get_zim_src_dir() 5 | if s:zim_python_path == '' && ! s:zim_not_found 6 | let s:zim_python_path=substitute( 7 | \ system("find /usr/lib/python* -name 'zim' -type d"), 8 | \"\n.*",'','') 9 | let s:zim_not_found = (s:zim_python_path == '') 10 | endif 11 | return s:zim_python_path 12 | endfu 13 | command! ZimArithmetic call zim#plugins#arithmetic#processfile() 14 | -------------------------------------------------------------------------------- /plugin/zim/util.vim: -------------------------------------------------------------------------------- 1 | 2 | "" Get the translation of string 3 | function! zim#util#gettext(k) 4 | " let l:lang_prompt=get(g:zim_wiki_prompt, g:zim_wiki_lang, g:zim_wiki_prompt['en']) 5 | if has_key(g:zim_wiki_prompt,g:zim_wiki_lang) 6 | if has_key(g:zim_wiki_prompt[g:zim_wiki_lang],a:k) 7 | let l:ret = g:zim_wiki_prompt[g:zim_wiki_lang][a:k] 8 | elseif has_key(g:zim_wiki_prompt['en'],a:k) 9 | let l:ret = g:zim_wiki_prompt['en'][a:k] 10 | else 11 | let l:ret = a:k 12 | endif 13 | else 14 | let l:ret=get(g:zim_wiki_prompt['en'],a:k,a:k) 15 | endif 16 | return l:ret 17 | endfu 18 | 19 | 20 | "" Completion function for commands 21 | function! zim#util#_CompleteNotes(A,L,P) 22 | if a:A =~ '^/' 23 | if a:A =~ '^'.g:zim_notebook 24 | if mode() == 'c' 25 | call feedkeys('e"'.substitute(a:L, g:zim_notebook.'/', '', '').'" ') 26 | endif 27 | let l:a=substitute(a:A,'^'.g:zim_notebook.'/','','') 28 | else 29 | if mode() == 'c' 30 | call feedkeys(repeat("\b",len(a:A))) 31 | endif 32 | let l:a='' 33 | endif 34 | else 35 | let l:a=a:A 36 | endif 37 | let l:dir=substitute(g:zim_notebook,'[/]*$','/','') 38 | return map( 39 | \globpath(l:dir, l:a.'*\c', 0, 1), 40 | \'strpart(v:val,len(l:dir)).(isdirectory(v:val)?"/":"")' 41 | \) 42 | endfunction 43 | 44 | " # s:CloseLayerPrint() -> a short string to indicate the current layer 45 | let s:compl_help_bufnr=0 46 | let s:compl_related=0 47 | fu! s:CloseCompletionHelp() 48 | if !empty(s:compl_help_bufnr) 49 | if s:is_compl_help_update 50 | " let s:is_compl_help_update=0 51 | else 52 | let l:winnr=bufwinnr(s:compl_help_bufnr) 53 | if l:winnr > 0 54 | exe l:winnr.'windo bd' 55 | let s:compl_help_bufnr=0 56 | redraw 57 | endif 58 | endif 59 | endif 60 | endfu 61 | 62 | 63 | " Layer Description 64 | fu! s:CompletionHelp(lines) 65 | let s:is_compl_help_update=1 66 | if !empty(a:lines) 67 | if s:compl_help_bufnr 68 | let l:winnr=bufwinnr(s:compl_help_bufnr) 69 | if l:winnr > 0 70 | exe l:winnr.'wincmd w' 71 | exe '%delete' 72 | endif 73 | else 74 | let s:compl_related=bufnr('%') 75 | au CmdwinLeave,BufEnter,CursorMoved call s:CloseCompletionHelp() 76 | rightbelow split 77 | enew 78 | " redraw 79 | let s:compl_help_bufnr=bufnr('%') 80 | set buftype=nofile 81 | setlocal nowrap 82 | set ft=zimindex 83 | au BufEnter call s:CloseCompletionHelp() 84 | endif 85 | let l:w=winwidth('%') 86 | let l:lines=[] 87 | let l:nline=printf("%-50s",a:lines[0]) 88 | for l:i in a:lines[1:] 89 | if (len(l:nline . l:i) + 4) > l:w 90 | call add(l:lines,l:nline) 91 | let l:nline = printf("%-50s",l:i) 92 | else 93 | let l:nline.= '||' . printf("%-50s",l:i) 94 | endif 95 | endfor 96 | call add(l:lines,l:nline) 97 | if s:is_compl_help_update 98 | exe 'resize '.len(l:lines) 99 | call setline(1,l:lines) 100 | exe winbufnr(s:compl_related).'wincmd w' 101 | endif 102 | endif 103 | redrawstatus 104 | let s:is_compl_help_update=0 105 | endfu 106 | 107 | function! zim#util#_CompleteEditCmdI(A,L,P) 108 | let l:r=keys(filter(g:zim_edit_actions,'has_key(v:val,"n")')) 109 | let l:ret = sort((len(a:A) ? filter(l:r, 'v:val =~ "'.a:A.'.*\\c"') : l:r)) 110 | if len(l:ret) == 1 111 | call s:CloseCompletionHelp() 112 | else 113 | silent! call s:CompletionHelp(map(copy(l:ret),'v:val." -> ".zim#util#gettext("?".v:val)')) 114 | endif 115 | return l:ret 116 | endfunction 117 | 118 | function! zim#util#_CompleteEditCmdV(A,L,P) 119 | let l:r=keys(filter(g:zim_edit_actions,'has_key(v:val,"v")')) 120 | return len(a:A) ? filter(l:r, 'v:val =~ "'.a:A.'*\\c"') : l:r 121 | endfunction 122 | 123 | function! zim#util#_CompleteBook(A,L,P) 124 | let l:a=substitute(a:A,'^'.g:zim_notebook,'','') 125 | let l:dir=substitute(g:zim_notebooks_dir,'[/]*$','/','') 126 | return map( 127 | \filter(globpath(l:dir, l:a.'*\c', 0, 1),'isdirectory(v:val)'), 128 | \'strpart(v:val,len(l:dir))."/"' 129 | \) 130 | endfunction 131 | 132 | "" Function to ease the placement of the windows from zimindex window 133 | "whereopen contains commands to create split 134 | "editopt contains the commands like 'noswapfile' 135 | "focused is a 0 or 1 value to say to focus on new buffer 136 | "file is the file full path 137 | function! zim#util#open(whereopen,editopt,focused,file) 138 | if a:file =~ '/' && a:file !~ '>' 139 | let l:current_win=winnr() 140 | let l:ope=(bufexists(a:file)? 'buffer ' : a:editopt.' e ') 141 | if len(a:whereopen) | exe a:whereopen | endif 142 | exe l:ope.a:file 143 | set ft=zim 144 | if !a:focused 145 | exe l:current_win.'wincmd w' 146 | endif 147 | endif 148 | endfunction 149 | 150 | " Get the line number for a goto instruction set 151 | " See: :help g:zim_open_jump_to 152 | function! zim#util#line(goto_instrs, ...) 153 | let l:i=get(a:000,0,1) 154 | let l:step=get(a:000,1,1) 155 | let l:default=0 156 | let l:e=line('$') 157 | let l:scroll = {'top':'zt', 'center': 'zz', 'bottom': 'zb'} 158 | let l:mem = {} 159 | for l:j in a:goto_instrs 160 | if type(l:j) == type(0) 161 | let l:i+=l:j 162 | elseif type(l:j) == type({}) 163 | if has_key(l:j, 'scroll') 164 | exe l:i 165 | let l:scr=l:j['scroll'] 166 | if type(l:scr) != type([]) | let l:scr=[l:scr] | endif 167 | for l:s in l:scr 168 | if type(l:s) == type(0) 169 | exe 'normal! '.abs(l:s).''.(l:s>0 ? '':'') 170 | elseif has_key(l:scroll,l:s) 171 | exe 'normal! '.l:scroll[l:s] 172 | endif 173 | endfor 174 | endif 175 | if has_key(l:j, 'checkpoint') | let l:default=l:i | endif 176 | if has_key(l:j, 'get') | let l:mem[l:j['get']]=l:i | endif 177 | if has_key(l:j, 'set') | let l:i=l:mem[l:j['set']] | endif 178 | if has_key(l:j, 'init') | let l:i=line(l:j['init']) | endif 179 | if has_key(l:j, 'sens') | let l:step=(l:j['sens']==0?1:l:j['sens']) | endif 180 | if has_key(l:j, 'default') | let l:default=l:j['default'] | endif 181 | else 182 | "find a line matching the pattern 183 | while l:i > 0 && l:i <= l:e && getline(l:i) !~ l:j 184 | let l:i+=l:step 185 | endwhile 186 | endif 187 | if l:i <= 0 | let l:i = l:default ? l:default : 1 | break | endif 188 | if l:i >= l:e | let l:i = l:default ? l:default : l:e | break | endif 189 | unlet l:j " E706 without this 190 | endfor 191 | return l:i 192 | endfunction 193 | 194 | "copy / move / rename files or directories interface 195 | "be caution at moving file to file 196 | " moving dir to dir 197 | function! zim#util#move(src,tgt,copy,dir) 198 | if has('win32') 199 | let l:copy_cmd= a:copy? '!xcopy %s %s /s /e' : '!move %s %s /s /e' 200 | else 201 | let l:copy_cmd= a:copy? '!cp -'.(a:dir?'r':'').'T %s %s' : '!mv %s %s' 202 | endif 203 | exe printf(l:copy_cmd,a:src,a:tgt) 204 | endfunction 205 | 206 | fu! s:prefeed(a) 207 | let l:ret=a:a 208 | let l:pf={ 'cr':"\n",'esc':"\e",'bs':"\b",'tab':"\t" } 209 | for l:i in keys(l:pf) 210 | let l:ret=substitute(l:ret, '<'.l:i.'>', l:pf[l:i],'g') 211 | endfor 212 | return l:ret 213 | endfu 214 | 215 | fu! zim#util#cmd(mode,cmd,show) 216 | if a:show && has_key(g:zim_keymapping, a:cmd) 217 | echo g:zim_keymapping[a:cmd] 218 | sleep 600ms 219 | endif 220 | if a:mode == 'n' 221 | silent! call feedkeys(s:prefeed(g:zim_edit_actions[a:cmd]['n'])) 222 | elseif a:mode == 'v' 223 | silent! call feedkeys('gv'.s:prefeed(g:zim_edit_actions[a:cmd]['v'])) 224 | elseif a:mode == 'i' 225 | silent! call feedkeys("".s:prefeed(g:zim_edit_actions[a:cmd]['n'])) 226 | endif 227 | endfu 228 | -------------------------------------------------------------------------------- /syntax/getsourcesfiletype.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python2.7 2 | 3 | from glob import glob 4 | try: 5 | import gtksourceview2 6 | except: 7 | gtksourceview2 = None 8 | 9 | 10 | if gtksourceview2: 11 | lm = gtksourceview2.LanguageManager() 12 | lang_ids = lm.get_language_ids() 13 | lang_names = [lm.get_language(i).get_name() for i in lang_ids] 14 | 15 | LANGUAGES = dict((lm.get_language(i).get_name(), i) for i in lang_ids) 16 | else: 17 | LANGUAGES = {} 18 | 19 | def langsubst(lzim): 20 | langsubsts=[ 21 | (0, ' ', '-'), 22 | (1,'gettext-translation', 'po'), 23 | (1,'dos-batch', 'dosbatch'), 24 | (1,'.ini', 'dosini'), 25 | (1,"c/c++/objc-header", "cpp"), 26 | (0, '#', 's'), 27 | (0, '++', 'pp'), 28 | (0, 'objective-', 'o'), 29 | (0,'literate-', ''), 30 | (0,'.','') 31 | ] 32 | lvim = lzim.lower() 33 | for b, z, v in langsubsts: 34 | if z in lvim: 35 | lvim = lvim.replace(z, v) 36 | if b: 37 | break 38 | return lzim, lvim 39 | 40 | ret = [] 41 | for (lzim, lvim) in [langsubst(l) for l in LANGUAGES]: 42 | if glob('/usr/share/vim/*/syntax/'+lvim+'.vim') : 43 | ret.append('"' + lzim + '" : "' + lvim + '"') 44 | print "let g:zim_codeblock_syntax = { %s }" % "\n \\ ".join(ret) 45 | -------------------------------------------------------------------------------- /syntax/zim.vim: -------------------------------------------------------------------------------- 1 | " Zim syntax highlighting 2 | " Authors: 3 | "" Jack Mudge 4 | "" * I declare this file to be public domain. 5 | "" Luffah 6 | "" * Thanks to vim-zimwiki-syntax authors 7 | "" (YaoPo Wang and joanrivera), i added some styles 8 | "" * Please enjoy the render of this syntax file, and feel free to customize 9 | "" it for the funniest usage 10 | " Changelog: 11 | " 2016-09-12 - Jack Mudge - v0.1 12 | " * Initial creation 13 | " 2017-05-30 - Luffah - v0.3 14 | " * More detailed syntax 15 | " 2018-05-14 - Luffah 16 | " * add inline verbatim and blocks 17 | " 18 | if version < 600 19 | syntax clear 20 | elseif exists("b:current_syntax") 21 | finish 22 | endif 23 | 24 | 25 | " Force Lang spelling for each note (to system if 1) 26 | if get(g:,'zim_wiki_spelllang',0) 27 | exe 'silent! setlocal spell spelllang='.(g:zim_wiki_spelllang==1?strpart(expand("$LANG"),0,2):g:zim_wiki_spelllang) 28 | endif 29 | 30 | " Zim Header 31 | syn match zimHeader /^[^:]*:/ contained contains=@NoSpell nextgroup=ZimHeaderParam 32 | syn match zimHeaderParam /.*/ contained contains=@NoSpell 33 | syn region zimHeaderRegion 34 | \ start=/\%1l^\(Content-Type\|Wiki-Format\|Creation-Date\):\%1l\c/ 35 | \ end=/\%4l\([A-Z]*:.*\)\?\c/ 36 | \ contains=zimHeader transparent fold keepend extend 37 | hi link vimModeline LineNr 38 | hi link zimHeader LineNr 39 | hi link zimHeaderParam TabLine 40 | 41 | " Titles (h1 to h5) 42 | try 43 | silent hi markdownH1 44 | syn match Title1 /^\s*\(=\{6}\)[^=].*\1\s*$/ contains=Todo 45 | syn match Title2 /^\s*\(=\{5}\)[^=].*\1\s*$/ contains=Todo 46 | syn match Title3 /^\s*\(=\{4}\)[^=].*\1\s*$/ contains=Todo 47 | syn match Title4 /^\s*\(=\{3}\)[^=].*\1\s*$/ contains=Todo 48 | syn match Title5 /^\s*\(=\{2}\)[^=].*\1\s*$/ contains=Todo 49 | syn match Title6 /^\s*\(=\{1}\)[^=].*\1\s*$/ contains=Todo 50 | hi link Title1 markdownH1 51 | hi link Title2 markdownH2 52 | hi link Title3 markdownH3 53 | hi link Title4 markdownH4 54 | hi link Title5 markdownH5 55 | hi link Title6 markdownH6 56 | catch 57 | syn match Title /^\s*\(=\{1,6}\)[^=].*\1\s*$/ contains=Todo 58 | endtry 59 | 60 | " Checkbox 61 | syn match zimEltCheckbox /^\( \{4}\|\t\)*\[[ ]\]\(\s\|$\)/me=e-1 contains=zimConcealEltCheckbox,zimTab 62 | syn match zimEltCheckboxYes /^\( \{4}\|\t\)*\[\*\]\(\s\|$\)/me=e-1 contains=zimConcealEltCheckboxYes,zimTab 63 | syn match zimEltCheckboxNo /^\( \{4}\|\t\)*\[x\]\(\s\|$\)/me=e-1 contains=zimConcealEltCheckboxNo,zimTab 64 | syn match zimEltCheckboxMoved /^\( \{4}\|\t\)*\[>\]\(\s\|$\)/me=e-1 contains=zimConcealEltCheckboxMoved,zimTab 65 | hi zimEltCheckbox gui=bold guifg=black guibg=#dcdcdc term=bold ctermfg=0 ctermbg=7 66 | hi zimEltCheckboxYes gui=bold guifg=#65B616 guibg=#dcdcdc term=standout ctermfg=2 ctermbg=15 67 | hi zimEltCheckboxNo gui=bold guifg=#AF0000 guibg=#dcdcdc term=standout ctermfg=1 ctermbg=15 68 | hi zimEltCheckboxMoved gui=bold guifg=#AFAF00 guibg=#dcdcdc term=standout ctermfg=3 ctermbg=15 69 | "syn match zimTab '^\( \)\+\( \[\)' 70 | "hi def link zimTab Ignore 71 | 72 | " Lists 73 | syn match ZimEltBulletItem /^\( \{4}\|\t\)*\*\(\s\|$\)/me=e-1 74 | syn match ZimEltNumberedItem /^\( \{4}\|\t\)*\d\+\.\(\s\|$\)/me=e-1 75 | "hi zimBulletItem gui=bold guifg=black guibg=#f4f4f4 term=bold ctermfg=0 76 | hi link ZimEltBulletItem Special 77 | hi link ZimEltNumberedItem Special 78 | 79 | " Style : bold 80 | syn match zimStyleBold /\*\*[^*]*\*\*/ contains=zimConcealStyleBold 81 | hi zimStyleBold gui=bold term=standout cterm=bold 82 | syn match zimConcealStyleBold /\*\*/ conceal contained transparent 83 | 84 | " Style : italic 85 | syn match zimStyleItalic +//[^/]*//+ contains=zimConcealStyleItalic 86 | hi zimStyleItalic gui=italic cterm=italic 87 | syn match zimConcealStyleItalic +//+ conceal contained transparent 88 | 89 | " Style : hightlighted 90 | syn match zimStyleHighlighted /__[^_]*__/ contains=zimConcealStyleHighlighted 91 | hi link zimStyleHighlighted DiffChange 92 | syn match zimConcealStyleHighlighted +__+ conceal contained transparent 93 | 94 | " Style : strikethrough 95 | syn match zimStyleStrikethrough /\~\~[^~]*\~\~/ 96 | hi link zimStyleStrikethrough NonText 97 | 98 | " url link 99 | syn match zimEltUrl '\(^\|\s\)\(www\.\|https\?:\/\/\)\S\+\c' contains=@NoSpell 100 | hi def link zimEltUrl Tag 101 | 102 | " tags 103 | syn match zimEltTag '\(^\|\s\)\(@[a-zA-Z-_0-9]\+\)\c' contains=@NoSpell 104 | hi def link zimEltTag Identifier 105 | 106 | syn match zimEltFile '\(^\|\s\)\([.~]*\)\(/[^ /&|^[\]]\+\)\+' contains=@NoSpell 107 | hi def link zimEltFile diffNewFile 108 | 109 | " Links 110 | syn match Identifier /\[\[[^[\]|]*\]\]/ 111 | syn match zimEltLinks /\[\[[^[\]|]*|[^[\]|]*\]\]/ contains=zimEltUrlHiddenA,zimEltUrlHiddenB keepend 112 | syn match zimEltUrlHiddenA /\[\[[^|]*|/ contained conceal cchar=› transparent 113 | syn match zimEltUrlHiddenB /\]\]/ contained conceal cchar=¸ transparent 114 | try 115 | silent hi htmlBoldUnderline 116 | hi def link zimEltLinks htmlBoldUnderline 117 | catch 118 | hi def link zimEltLinks Underlined 119 | endtry 120 | 121 | "" -------------------- 122 | " Style : block 123 | syn match zimBlock '{{{[^{}]*}}}' 124 | syn region zimBlock matchgroup=Comment start=/^{{{\a*/ end=/^}}}/ transparent 125 | 126 | " Style : Codeblock (zim add-on) 127 | fu! s:activate_codeblock() 128 | " generate by :read!%:p:h/getsourcesfiletype.py 129 | " the selection is reduced for optimisation and because some syntax files 130 | " break spell 131 | let l:languages = get(g:,'zim_codeblock_syntax', 132 | \{"python": "python","sh": "sh","sourcecode": "sh", "vim": "vim", 133 | \ "html": "html", "css": "css", "xml": "xml", 134 | \ "javascript": "javascript", "sql": "sql"} 135 | \) 136 | 137 | exe 'syn include @zimcodeblockundef syntax/'.get(g:,'zim_codeblock_default_syntax', 'abc').'.vim contained' 138 | syn region zimCodeBlockUndef start="\s*$"ms=e+1 139 | \ end="^\s*}}}\ze\s*$"me=e-3 contained contains=@zimcodeblockundef 140 | " syn region markdownCode matchgroup=Delimiter start="^\s*```.*$" end="^\s*```\ze\s*$" keepend 141 | for l:i in keys(l:languages) 142 | let l:l = l:languages[l:i] 143 | let b:current_syntax='' 144 | unlet b:current_syntax 145 | exe 'syn include @zimcodeblock'.l:l.' syntax/'.l:l.'.vim contained' 146 | exe 'syn region zimCodeBlock'.l:l.' start=|lang="'.l:i.'".*$|ms=e+1'. 147 | \' end=|^\s*}}}\ze\s*$|me=e-3 contained contains=@zimcodeblock'.l:l 148 | 149 | " markdown code support 150 | exe 'syn region markdownHighlight'.l:l.' matchgroup=Delimiter start="^\s*```\s*'.l:l.'\>.*$" end="^\s*```\ze\s*$" keepend contains=@zimcodeblock'.l:l 151 | 152 | endfor 153 | syn region zimCodeBlock start="^\s*{{{code" end="^\s*}}}\ze\s*$" matchgroup=Delimiter 154 | \ keepend contains=@NoSpell,ZimCodeBlock.* 155 | hi def link ZimCodeBlock Comment 156 | endfu 157 | call s:activate_codeblock() 158 | 159 | " Style : verbatim 160 | syn region zimStyleVerbatim start=/''/ end=/''/ contains=@NoSpell 161 | syn region zimStyleVerbatim start=/^\s*'''/ end=/\s*'''/ contains=@NoSpell 162 | hi def link zimStyleVerbatim SpecialComment 163 | 164 | " Style : sub and sup 165 | syn match zimStyleSub '_{.\{-1,}}' 166 | syn match zimStyleSup '\^{.\{-1,}}' 167 | hi def link zimStyleSub Number 168 | hi def link zimStyleSup Number 169 | 170 | " Image 171 | syn match zimEltImage '\(^\| \){{[^ {}][^{}]\{-1,}[^ {}]}}' contains=@NoSpell 172 | hi def link zimEltImage Float 173 | 174 | " Line 175 | syn match zimStyleHorizontalLine /^\(-\{20}\)$/ contains=@NoSpell 176 | hi link zimStyleHorizontalLine Underlined 177 | 178 | 179 | "" -------------------- 180 | " Bonus 181 | syn match vimModeline +\(/\*\s*vim\s*:.*\*/\|//\s*vim\s*:.*\)+ 182 | 183 | " IdentedDetails 184 | syn region zimwikiIndentedCheckboxDetails start=/^\z(\( \{4\}\|\t\)*\)\(\[[x*]\]\)[^:{}[\]]*\( :.*\|\\\s*$\)\n\(\s*\S\|^$\)/ end=/^\z1\?\( \{0,3\}\)\S/me=s-1 contains=zimElt.*,zimStyle.*,Title.*,zimwikiIndentedCheckboxDetails,zimwikiIndentedDetails fold transparent 185 | syn region zimwikiIndentedDetails start=/^\S[^:{}[\]]* [^:{}[\]]*\(:.*\|\\\s*$\)\n\s*\S/ end=/^\( \{0,3\}\)\S/me=s-1 contains=zimElt.*,zimStyle.*,Title.* fold transparent 186 | "syn region zimIndentedfold start=/^\( \{4,\}\|\t\)\S/ end=/^\s\{0,3\}\S/me=s-1 contained fold transparent contains=zimElt.*,zimStyle.* 187 | "syn region zimwikiIndentedDetails start=/^\( \{4\}|\t\)*\(\[.\]\)\?[_a-z 0-9]*:/ end=/^\s\{0,3\}\S/me=s-1 contains=zimIndentedFold,zimElt.*,zimStyle.* transparent 188 | 189 | "" -------------------- 190 | " Finalize 191 | let b:current_syntax = "zim" 192 | setlocal conceallevel=1 193 | setlocal foldmethod=syntax 194 | syn sync fromstart 195 | -------------------------------------------------------------------------------- /syntax/zimindex.vim: -------------------------------------------------------------------------------- 1 | " Zim Index syntax highlighting (for Zim.vim plugin) 2 | " Author: luffah 3 | " cc0 4 | if version < 600 5 | syntax clear 6 | elseif exists("b:current_syntax") 7 | finish 8 | endif 9 | 10 | syn case ignore 11 | 12 | " Zim Header 13 | "syn region zimIndexHeaderRegion start="^:\%1l" end="^\(---.*\|\)$" contains=zimIndexHeader keepend 14 | 15 | " Style : hightlighted 16 | syn match Title /<--.*-->/ 17 | syn match Conceal /%\(\s\?[A-Za-z0-9- ]\+\)\?/ 18 | syn match Ignore /||/ 19 | syn match MoreMsg /<\?[A-Za-z0-9-_ ]\+>\?\(\s* -> .*|\?\)\@=/ 20 | "syn match Directory /.* :/ 21 | "syn match Title /[^: ]*\.txt$/ 22 | syn match TODO /[^: ]*\.txt / 23 | " Style : strikethrough 24 | "syn match zimStrikethrough /\~\~.*\~\~/ 25 | "highlight link zimStrikethrough NonText 26 | 27 | 28 | let b:current_syntax = "zimindex" 29 | --------------------------------------------------------------------------------