From 0b416c28343fad8fad3729dad8722c6b4547a1a5 Mon Sep 17 00:00:00 2001 From: Maxim Kim Date: Mon, 5 May 2008 00:00:00 +0000 Subject: [PATCH] Version 0.2 * (+) Add part of Google's Wiki syntax. * (+) Add auto insert # with ENTER. * (+) On/Off auto insert bullet with ENTER. * (+) Strip `[[complex wiki name]]` from symbols that cannot be used in file names. * (+) Links to non-wiki files. Non wiki files are files with extensions ie `[[hello world.txt]]` or `[[my homesite.html]]` --- ftplugin/vimwiki.vim | 83 +++++++++++++++++++++++++++++++------------- syntax/vimwiki.vim | 66 ++++++++++++----------------------- 2 files changed, 82 insertions(+), 67 deletions(-) diff --git a/ftplugin/vimwiki.vim b/ftplugin/vimwiki.vim index bebfaea..8f2b517 100644 --- a/ftplugin/vimwiki.vim +++ b/ftplugin/vimwiki.vim @@ -4,8 +4,8 @@ " Home: http://code.google.com/p/vimwiki/ " Author: Maxim Kim " Filenames: *.wiki -" Last Change: (04.05.2008 17:45) -" Version: 0.1 +" Last Change: (05.05.2008 19:30) +" Version: 0.2 if exists("b:did_ftplugin") finish @@ -35,12 +35,16 @@ function! s:default(varname,value) endif endfunction +"" Could be redefined by users call s:default('index',"") call s:default('home',"") call s:default('upper','A-ZА-Я') call s:default('lower','a-zа-я') call s:default('other','0-9_') call s:default('ext','.wiki') +call s:default('smartCR',1) +call s:default('stripsym','_') + call s:default('history',[]) let upp = g:vimwiki_upper @@ -74,6 +78,7 @@ function! s:SearchWord(wikiRx,cmd) let &hls = hl endfunction + function! s:WikiNextWord() call s:SearchWord(s:wiki_word, 'n') endfunction @@ -104,27 +109,44 @@ function! s:WikiGetWordAtCursor(wikiRX) endif endf -function! s:WikiStripWord(word) +function! s:WikiStripWord(word, sym) + function! s:WikiStripWordHelper(word, sym) + return substitute(a:word, '[<>|?*/\:"]', a:sym, 'g') + endfunction + let result = a:word if strpart(a:word, 0, 2) == "[[" - let result = strpart(a:word, 2, strlen(a:word)-4) + let result = s:WikiStripWordHelper(strpart(a:word, 2, strlen(a:word)-4), a:sym) endif return result endfunction +" Check if word is link to a non-wiki file. +" The easiest way is to check if it has extension like .txt or .html +function! s:WikiLinkToNonWikiFile(word) + if a:word =~ '\..\{1,4}$' + return 1 + endif + return 0 +endfunction + if !exists('*s:WikiFollowWord') function! s:WikiFollowWord() - let word = s:WikiStripWord(s:WikiGetWordAtCursor(s:wiki_word)) + let word = s:WikiStripWord(s:WikiGetWordAtCursor(s:wiki_word), g:vimwiki_stripsym) " insert doesn't work properly inside :if. Check :help :if. if word == "" execute "normal! \n" return endif - " history is [['WikiWord.wiki', 11], ['AnotherWikiWord', 3] ... etc] - " where numbers are column positions we should return when coming back. - call insert(g:vimwiki_history, [expand('%:p'), col('.')]) - execute ":e ".g:vimwiki_home.word.g:vimwiki_ext + if s:WikiLinkToNonWikiFile(word) + execute ":e ".word + else + " history is [['WikiWord.wiki', 11], ['AnotherWikiWord', 3] ... etc] + " where numbers are column positions we should return when coming back. + call insert(g:vimwiki_history, [expand('%:p'), col('.')]) + execute ":e ".g:vimwiki_home.word.g:vimwiki_ext + endif endfunction function! s:WikiGoBackWord() @@ -138,30 +160,40 @@ if !exists('*s:WikiFollowWord') endif function! s:WikiNewLine() - let prevline = getline(line('.')-1) - - if prevline =~ '^\s*\*' - let curline = substitute(getline('.'),'^\s\+',"","g") - if prevline =~ '^\s*\*\s*$' - " there should be easier way ... - execute 'normal kA '."\".'"_dF*JX' - return + function! WikiAutoListItemInsert(listSym) + let sym = escape(a:listSym, '*') + let prevline = getline(line('.')-1) + if prevline =~ '^\s*'.sym + let curline = substitute(getline('.'),'^\s\+',"","g") + if prevline =~ '^\s*'.sym.'\s*$' + " there should be easier way ... + execute 'normal kA '."\".'"_dF'.a:listSym.'JX' + return 1 + endif + let ind = indent(line('.')-1) + call setline(line('.'), strpart(prevline, 0, ind).a:listSym.' '.curline) + call cursor(line('.'), ind+3) + return 1 endif - call setline(line('.'), '* '.curline) - execute "normal ==" - let ind = indent(line('.')) + 3 - call cursor(line('.'), ind) + return 0 + endfunction + + if WikiAutoListItemInsert('*') + return + endif + + if WikiAutoListItemInsert('#') return endif " delete - execute 'normal X' + execute 'normal x' endfunction " Functions }}} -"" Keybindings +"" Keybindings {{{ """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" nmap gk nmap k gk @@ -182,4 +214,7 @@ nmap :call WikiGoBackWord() nmap :call WikiNextWord() nmap :call WikiPrevWord() -inoremap :call WikiNewLine() +if g:vimwiki_smartCR + inoremap :call WikiNewLine() +endif +" Keybindings }}} diff --git a/syntax/vimwiki.vim b/syntax/vimwiki.vim index 5783681..15ce51f 100644 --- a/syntax/vimwiki.vim +++ b/syntax/vimwiki.vim @@ -4,8 +4,8 @@ " Home: http://code.google.com/p/vimwiki/ " Author: Maxim Kim " Filenames: *.wiki -" Last Change: (04.05.2008 17:45) -" Version: 0.1 +" Last Change: (05.05.2008 19:30) +" Version: 0.2 " Based on FlexWiki " Quit if syntax file is already loaded @@ -26,70 +26,51 @@ syntax match wikiLink `\("[^"(]\+\((\([^)]\+\))\)\?":\)\?\(https\?\|ft " text: *strong* syntax match wikiBold /\(^\|\W\)\zs\*\([^ ].\{-}\)\*/ -" '''bold''' -syntax match wikiBold /'''\([^'].\{-}\)'''/ " text: _emphasis_ -syntax match wikiItalic /\(^\|\W\)\zs_\([^ ].\{-}\)_/ -" ''italic'' -syntax match wikiItalic /''\([^'].\{-}\)''/ +syntax match wikiItalic /_.\{-}_/ -" ``deemphasis`` -syntax match wikiDeEmphasis /``\([^`].\{-}\)``/ +" text: `code` +syntax match wikiCode /`.\{-}`/ -" text: @code@ -syntax match wikiCode /\(^\|\s\|(\|\[\)\zs@\([^@]\+\)@/ - -" text: -deleted text- -syntax match wikiDelText /\(^\|\s\+\)\zs-\([^ , horizontal rule syntax match wikiHR /^----.*$/ -" Formatting can be turned off by ""enclosing it in pairs of double quotes"" -syntax match wikiEscape /"".\{-}""/ - " Tables. Each line starts and ends with '||'; each cell is separated by '||' syntax match wikiTable /||/ -" Treat all other lines that start with spaces as PRE-formatted text. -syntax match wikiPre /^[ \t]\+.*$/ - " Bulleted list items start with whitespace(s), then '*' " syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\).*$/ contains=@wikiText " highlight only bullets and digits. -syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\)/ +syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\|#\)/ @@ -102,11 +83,11 @@ hi def link wikiH4 wikiH3 hi def link wikiH5 wikiH4 hi def link wikiH6 wikiH5 hi def link wikiHR wikiH6 - + hi def wikiBold term=bold cterm=bold gui=bold hi def wikiItalic term=italic cterm=italic gui=italic -hi def link wikiCode Statement +hi def link wikiCode PreProc hi def link wikiWord Underlined hi def link wikiEscape Todo @@ -116,7 +97,6 @@ hi def link wikiList Type hi def link wikiTable Type hi def link wikiEmoticons Constant hi def link wikiDelText Comment -hi def link wikiDeEmphasis Comment hi def link wikiInsText Constant hi def link wikiSuperScript Constant hi def link wikiSubScript Constant