nvim: Switch to lua-based setup
nvim: Restructure lua config directory
Restructured lua setting files, so that plugin settings are in clearly
labelled as such files, and the base files are just there --- the base
directory.
This should also lay the ground work for modularizing plugins, so that
we can enable/disable plugin groups as we need them.
----------
nvim: Remove ale linter and formatter
Removed ale from plugins.
Linting is being taken care of by lsp and treesitter plugins and
formatting by formatter.nvim.
Added all filetypes ale took care of to formatting on save.
----------
nvim: Replace wiki.vim with zettelkasten.nvim
Removed lerlvag's `wiki.vim` from plugin list.
Though I love it and loved using it, by now it clutters up the list and
the basic functionality I need it provided by zettelkasten.nvim.
(That being linking, following links, and quickly opening a central file).
I may still come back to it at some point, but for now I am happy with
the new setup.
----------
nvim: Add toggleterm and lazygit integration
Added toggleterm plugin, integrating a very quick access to the neovim
terminal (`<leader>=` mapping).
Additionally, added a command to quickly call up a lazygit floating
windows with the same plugin. `<leader>G` will open a git management
window in which you can stage, remove, commit, push, pull and more.
----------
nvim: Replace surround, sneak; Add treesitter, dial
Replaced vim-sneak with lightspeed lua plugin, which accomplishes
similar to the same goal, with a little more flexibility (can also be
used to replicate other vim plugins like e.g. easymotion).
For now I am using it as a straight replacement, with the same fF/tT
functionality stretching over multiple lines, and quick sS 2-letter
jumps to any location ahead/back.
The highlighting is noticeably more stable and faster. For now it is set
to always highlight the next 5 occurences of a letter, wherever they
are. Lastly, it does not -- so the lightspeed author -- change the
buffer in any way which is what happened with sneak (due to vimscript
limitations) and which can and did confuse things like treesitter and
the lsp integration.
Replaced vim-surround with a lua-equivalent surround.nvim. This one I am
less sure about, the lua pluging, while working, still carries some bugs
and does not seem as thoroughly tested. It still has problems with
surrounding stuff with e.g. `*` and does not deal well with some
quotation situations. I will try to keep using it and perhaps find the
time to contribute to some of the issues instead of going back at first
however, purely since I am a much bigger fan of the plugin existing in
luascript.
Replaced vim-peekaboo with registers, another switch to a lua plugin,
which also functions slightly differently however. I much prefer the lua
plugins display of register contents which simply appear as a dropdown,
compe-like, and I can either paste with the correct symbol choice as
always, or by scrolling through it as if it is an autocomplete choice.
Added dial.nvim which slightly extends the functionality of ^a and ^x
number in-/decreases. It should barely be noticeable in normal operation
but now the combination can be used to change dates, alphabet
characters, hex codes and some more. Most prominently, I am using it for
date manipulation.
Added a couple of treesitter related plugins:
treesitter-context shows the context the cursor is currently in if the
beginning of this context goes off-screen, e.g. the function beginning
or current class being edited. Works for nested contexts.
treesitter-textsubjects allows selecting units of codes by going up the
tree branches. So, first you select an argument, then the whole argument
chain, then the function definition, then the whole function, then the
containing class, and so on. It is quite natural, however, I have so far
only made it work for visual selection, so not as a motion target.
Still, very useful - works with `v.` and can be repeated with `.`.
Lastly, ts-context-commentstring improves the correct selection of
commenting type for commenting plugins (i.e. my `gcc` mapping), by
making use of treesitter where available. Can even do multi-language
files like vue, react, or tsx modules with html, css and javascript
interweaved.
----------
nvim: Add code formatter
Added code formatter in lua, right now supporting python, cpp,
javascript, lua, rust.
More can very easily be added.
I am not sure if this plugin supports the formatting of code within
snippets in another file format (lukas-reineke/format.nvim does support
this, but seems not-maintained).
----------
nvim: Add tmux, snippet completion
Added (for real this time) tmux adjacent buffer completion.
Added vsnip completion through compe: Invoke a completion (shown in
compe with snippet preview) through <cr> or <space-cr> and then use
<tab> and <s-tab> to go back and forth through the completable positions
for the respective snippet.
Many default snippets included through the community repository of
friendly-snippets.
----------
nvim: Improve compe completion, Add outline view
Added outline view to neovim, similar to the well-known vista.vim
plugin. Can be opened (and closed again) with <leader>o mapping, simply
mnemonic for 'outline'.
Added unicode symbols (invoked with '\') and tmux adjacent buffers
to compe completion sources.
----------
nvim: Add zen writing mode in lua
Switched from goyo to TrueZen.nvim in looking for a lua replacement of
zen writing modes. The F11 shortcut remains the same, additionally using
F10 shortcut to enter a less drastic minimal mode.
----------
nvim: Switch keymaps to lua format
Using cartographer to make setting keymaps easy.
----------
nvim: Add tmux Navigator lua replacement
----------
nvim: Add autopairs, zen writing lua plugins
Switch goyo and autopairs to make use of lua plugins.
Moved most of the plugin setup code from a custom and manually updated
array being called from init.lua, to their respective plugin
installations in plugins.lua (so, wherever the plugin is installed also
contains the call of the configuration code).
This should hopefully reduce duplication a little and may prepare for
the lua plugin setups to end up in plugins directory of neovim.
----------
nvim: Add lua statusline, base16, async grep
Added galaxyline in an initial iteration which is probably overloaded
but integrates well with the also moved over to lua base16 colorschemes.
For now, it is possible to, at any point, simply call the `:lua
B16theme('themename')` command to change the colorscheme of both neovim
itself and the galaxyline with it.
The statusline, as of now, includes the activated mode (of course), the
filename being edited, the edit state (whether changed from last save,
or read-only), the current git branch if any, as well as the amount of
added, modified, and deleted lines from current git commit. On the right
hand side it contains the lsp status (if connected), the amount of
errors and warnings in current file, the filetype currently recognized
for the file, as well as the usual cursor position in the window.
Added some small other things, including an asynchronous fuzzy-backed
full-text search through telescope, which should hopefully make
full-text searching much more responsive than before; updated the
version of indentline to the correct one; and disabled some unused vim
built-in plugins.
This commit is contained in:
parent
8d399ed872
commit
bc046d02df
47 changed files with 1043 additions and 992 deletions
|
|
@ -1,7 +0,0 @@
|
|||
" Design
|
||||
" PLUGIN: AIRLINE
|
||||
let g:airline_powerline_fonts=1
|
||||
" disable automatically refreshing the mux statusbar since it breaks tmux
|
||||
" prefix highlighting. Instead, when changing vim statusbar just create
|
||||
" snapshot with :TmuxlineSnapshot file and stick it into tmux config manually
|
||||
let g:airline#extensions#tmuxline#enabled = 1
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
" PLUGIN: ALE
|
||||
:scriptencoding utf-8
|
||||
" clearer Error and warning signs for the gutter
|
||||
let g:ale_sign_error = ''
|
||||
let g:ale_sign_warning = ''
|
||||
|
||||
let g:ale_fix_on_save = 1
|
||||
let g:ale_fixers = {
|
||||
\ 'javascript': ['prettier'],
|
||||
\ 'html': ['prettier'],
|
||||
\ 'typescript': ['prettier','tslint'],
|
||||
\ '*': ['remove_trailing_lines', 'trim_whitespace'],
|
||||
\ 'go': ['gofmt'],
|
||||
\ 'sh': ['shfmt'],
|
||||
\ 'zsh': ['shfmt'],
|
||||
\ 'python': ['black', 'isort'],
|
||||
\}
|
||||
let g:ale_linters = {
|
||||
\ 'go': ['gopls'],
|
||||
\ 'sh': ['language_server','shellcheck'],
|
||||
\ 'zsh': ['language_server','shellcheck'],
|
||||
\ 'html': ['prettier'],
|
||||
\ 'python': ['pylint'],
|
||||
\}
|
||||
|
||||
let g:ale_javascript_prettier_use_local_config = 1
|
||||
|
||||
" Enable integration with airline.
|
||||
if exists('g:airline_theme')
|
||||
let g:airline#extensions#ale#enabled = 1
|
||||
endif
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
" Enable italics for colorschemes that support them
|
||||
let g:gruvbox_italic=1
|
||||
let g:one_allow_italics=1
|
||||
let g:pencil_terminal_italics=1
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
" PLUGIN: fzf.vim
|
||||
" set some fzf defaults
|
||||
" any Fzf command is prefixed with Fzf
|
||||
" this groups them nicely together, and avoids confusion when suddenly :Buffer
|
||||
" or :Files would appear as a command otherwise
|
||||
let g:fzf_command_prefix = 'Fzf'
|
||||
" let the colors come from our colorscheme
|
||||
let g:fzf_colors =
|
||||
\ { 'fg': ['fg', 'Normal'],
|
||||
\ 'bg': ['bg', 'Normal'],
|
||||
\ 'gutter': ['bg', 'Normal'],
|
||||
\ 'hl': ['fg', 'Comment'],
|
||||
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
|
||||
\ 'bg+': ['bg', 'Normal', 'CursorColumn'],
|
||||
\ 'hl+': ['fg', 'Statement'],
|
||||
\ 'info': ['fg', 'PreProc'],
|
||||
\ 'border': ['fg', 'Ignore'],
|
||||
\ 'prompt': ['fg', 'Conditional'],
|
||||
\ 'pointer': ['fg', 'Exception'],
|
||||
\ 'marker': ['fg', 'Keyword'],
|
||||
\ 'spinner': ['fg', 'Label'],
|
||||
\ 'header': ['fg', 'Comment'] }
|
||||
|
||||
let g:fzf_action = {
|
||||
\ 'ctrl-t': 'tab split',
|
||||
\ 'ctrl-s': 'split',
|
||||
\ 'ctrl-v': 'vsplit' }
|
||||
|
||||
" FzfRg but also search through hidden files
|
||||
command! -bang -nargs=* FzfRgHidden
|
||||
\ call fzf#vim#grep(
|
||||
\ "rg --column --line-number --no-heading --color=always --smart-case --hidden --glob '!.git' ".shellescape(<q-args>), 1,
|
||||
\ fzf#vim#with_preview(), <bang>0)
|
||||
|
||||
" make fzf use the nvim floating window globally. (weee, technology!)
|
||||
"
|
||||
let $FZF_DEFAULT_OPTS="--layout=reverse --ansi"
|
||||
let $FZF_DEFAULT_COMMAND="fd --type f --hidden --color=always -E '.git/'"
|
||||
" to use fzf in a floating window only conditionally, the best approach would
|
||||
" every command we want to floatize
|
||||
if has('nvim-0.4.0') || has("patch-8.2.0191")
|
||||
let g:fzf_layout = { 'window': {
|
||||
\ 'width': 0.7,
|
||||
\ 'height': 0.7,
|
||||
\ 'highlight': 'PreProc',
|
||||
\ 'border': 'rounded' } }
|
||||
else " Fallback to a split window
|
||||
let g:fzf_layout = { "window": "silent botright 16split enew" }
|
||||
endif
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
" PLUGIN: goyo.vim
|
||||
" set up functions for entering/exiting distraction free mode, or leaving it
|
||||
function! s:goyo_enter()
|
||||
" remove the tmux status bar for actual distraction free environment
|
||||
silent !tmux set status off
|
||||
" maximize the tmux pane that vim is in if any (usually I have vim open as the only pane)
|
||||
silent !tmux list-panes -F '\#F' | grep -q Z || tmux resize-pane -Z
|
||||
" disable line highlighting, we really don't need it for prose
|
||||
set nocursorline
|
||||
" enable limelight which highlights whatever paragraph you are in and lowlights the rest
|
||||
Limelight
|
||||
endfunction
|
||||
function! s:goyo_leave()
|
||||
silent !tmux set status on
|
||||
silent !tmux list-panes -F '\#F' | grep -q Z && tmux resize-pane -Z
|
||||
set cursorline
|
||||
Limelight!
|
||||
endfunction
|
||||
" actually call the functions on entering/leaving goyo
|
||||
autocmd! User GoyoEnter nested call <SID>goyo_enter()
|
||||
autocmd! User GoyoLeave nested call <SID>goyo_leave()
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
command! LspHover lua vim.lsp.buf.hover()<CR>
|
||||
command! LspDisable lua vim.lsp.stop_client(vim.lsp.get_active_clients())<CR>
|
||||
|
||||
" actual LSP config takes place in lua ('lua/lsp')
|
||||
setlocal omnifunc=v:lua.vim.lsp.omnifunc
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
function s:setupGitLens()
|
||||
" -- disable gitlens unconditionally, and remove virtual text
|
||||
lua require('gitlens').clearBlameVirtText()
|
||||
augroup GitLens
|
||||
autocmd!
|
||||
augroup END
|
||||
|
||||
" -- if it is wanted enable gitlens on holding the cursor
|
||||
if g:gitlens_enable
|
||||
augroup GitLens
|
||||
autocmd! CursorHold * lua require('gitlens').blameVirtText()
|
||||
autocmd! CursorMoved * lua require('gitlens').clearBlameVirtText()
|
||||
autocmd! CursorMovedI * lua require('gitlens').clearBlameVirtText()
|
||||
augroup END
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function s:toggleGitLens()
|
||||
let g:gitlens_enable = !get(g:, 'gitlens_enable', 1)
|
||||
call s:setupGitLens()
|
||||
endfunction
|
||||
|
||||
command! GitLensToggle call s:toggleGitLens()
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
" will highlight any text which has been yanked
|
||||
augroup LuaHighlightYank
|
||||
autocmd!
|
||||
autocmd TextYankPost * silent! lua require'vim.highlight'.on_yank{timeout=500}
|
||||
augroup END
|
||||
|
|
@ -12,4 +12,4 @@
|
|||
" variable to the intended filetype.
|
||||
" ]]--
|
||||
|
||||
command! -nargs=? -bang ScratchPad :lua require("scratchpad").create("<bang>","<args>")
|
||||
command! -nargs=? -bang ScratchPad :lua require("personal.scratchpad").create("<bang>","<args>")
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
" Show all mapped keys in a list - from https://stackoverflow.com/questions/13990136/display-a-ordered-vim-keyboard-mapping
|
||||
function! s:ShowMaps()
|
||||
let old_reg = getreg("a") " save the current content of register a
|
||||
let old_reg_type = getregtype("a") " save the type of the register as well
|
||||
try
|
||||
redir @a " redirect output to register a
|
||||
" Get the list of all key mappings silently, satisfy "Press ENTER to continue"
|
||||
silent map | call feedkeys("\<CR>")
|
||||
redir END " end output redirection
|
||||
vnew " new buffer in vertical window
|
||||
put a " put content of register
|
||||
" Sort on 4th character column which is the key(s)
|
||||
%!sort -k1.4,1.4
|
||||
finally " Execute even if exception is raised
|
||||
call setreg("a", old_reg, old_reg_type) " restore register a
|
||||
endtry
|
||||
endfunction
|
||||
" use :ShowMaps to call the function
|
||||
command! ShowMappings call s:ShowMaps() " Enable :ShowMaps to call the function
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
function! s:fzfSpellSink(word)
|
||||
exe 'normal! "_ciw'.a:word
|
||||
endfunction
|
||||
function! FzfSpell()
|
||||
let l:spellstatus = &spell
|
||||
setlocal spell
|
||||
let suggestions = spellsuggest(expand("<cword>"))
|
||||
if l:spellstatus
|
||||
return fzf#run({'source': suggestions, 'sink': function("s:fzfSpellSink"), 'right': "20%" })
|
||||
|
||||
endfunction
|
||||
|
||||
command FzfSpellSuggest :call FzfSpell()<CR>
|
||||
|
|
@ -1,10 +0,0 @@
|
|||
" custom preset with left-justified window list
|
||||
" PLUGIN: TMUXLINE
|
||||
let g:tmuxline_preset = {
|
||||
\'a' : '#S',
|
||||
\'b' : '#I:#P',
|
||||
\'win' : '#I #W',
|
||||
\'cwin' : [' ', '#I #W'],
|
||||
\'y' : '#{?client_prefix,#[fg=colour232]#[bg=brightblue],} #(whoami)',
|
||||
\'z' : '#H',
|
||||
\'options' : {}}
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
" PLUGIN: vim-go
|
||||
" change the tabstops for go to use tabs and a width of 4
|
||||
" this conforms with the gofmt expectations
|
||||
au FileType go set noexpandtab
|
||||
au FileType go set shiftwidth=4
|
||||
au FileType go set softtabstop=4
|
||||
au FileType go set tabstop=4
|
||||
" enable all sorts of highlighting options for
|
||||
" variables/functions/arguments...
|
||||
let g:go_highlight_build_constraints = 1
|
||||
let g:go_highlight_extra_types = 1
|
||||
let g:go_highlight_fields = 1
|
||||
let g:go_highlight_functions = 1
|
||||
let g:go_highlight_methods = 1
|
||||
let g:go_highlight_operators = 1
|
||||
let g:go_highlight_structs = 1
|
||||
let g:go_highlight_types = 1
|
||||
" enable highlighting of other uses of the same variable
|
||||
let g:go_auto_sameids = 0
|
||||
" automatically import needed dependencies
|
||||
let g:go_fmt_command = "goimports"
|
||||
" show type information for variables in the status line
|
||||
let g:go_auto_type_info = 1
|
||||
" disable go info in status window, since it overlaps ALE linter information
|
||||
let g:go_echo_go_info = 0
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
" PLUGIN: vim-pandoc-syntax
|
||||
let g:pandoc#syntax#conceal#use = 1
|
||||
let g:pandoc#syntax#conceal#urls = 1
|
||||
|
|
@ -28,3 +28,7 @@ let g:pandoc#folding#fastfolds=1
|
|||
let g:pandoc#spell#default_langs=["en_us", "de_de"]
|
||||
let g:pandoc#hypertext#ausosave_on_edit_open_link=1
|
||||
let g:pandoc#hypertext#create_if_no_alternates_exists=1
|
||||
|
||||
" PLUGIN: vim-pandoc-syntax
|
||||
let g:pandoc#syntax#conceal#use = 1
|
||||
let g:pandoc#syntax#conceal#urls = 1
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
" PLUGIN: vim-peekaboo
|
||||
let g:peekaboo_delay=500
|
||||
|
||||
function! CreateCenteredFloatingWindow()
|
||||
let width = float2nr(&columns * 0.6)
|
||||
let height = float2nr(&lines * 0.6)
|
||||
let top = ((&lines - height) / 2) - 1
|
||||
let left = (&columns - width) / 2
|
||||
let opts = {'relative': 'editor', 'row': top, 'col': left, 'width': width, 'height': height, 'style': 'minimal'}
|
||||
|
||||
let top = "╭" . repeat("─", width - 2) . "╮"
|
||||
let mid = "│" . repeat(" ", width - 2) . "│"
|
||||
let bot = "╰" . repeat("─", width - 2) . "╯"
|
||||
let lines = [top] + repeat([mid], height - 2) + [bot]
|
||||
let s:buf = nvim_create_buf(v:false, v:true)
|
||||
call nvim_buf_set_lines(s:buf, 0, -1, v:true, lines)
|
||||
call nvim_open_win(s:buf, v:true, opts)
|
||||
set winhl=Normal:Floating
|
||||
let opts.row += 1
|
||||
let opts.height -= 2
|
||||
let opts.col += 2
|
||||
let opts.width -= 4
|
||||
call nvim_open_win(nvim_create_buf(v:false, v:true), v:true, opts)
|
||||
au BufWipeout <buffer> exe 'bw '.s:buf
|
||||
endfunction
|
||||
|
||||
if has('nvim-0.4.0') || has("patch-8.2.0191")
|
||||
let g:peekaboo_window = "call CreateCenteredFloatingWindow()"
|
||||
else " Fallback to a split window
|
||||
let g:peekaboo_window={"window": "vert bo 30new"}
|
||||
endif
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
" PLUGIN: vim-polyglot
|
||||
"
|
||||
" we disable markdown so that every markdown file can be given pandoc type
|
||||
" let g:polyglot_disabled = ['markdown']
|
||||
|
||||
au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn} set ft=pandoc
|
||||
au BufNewFile,BufRead *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set ft=pandoc
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
" PLUGIN: vim-sneak
|
||||
" sneak around your files using
|
||||
" repeatedly pressing fFtTsS will advance the search instead of starting a new
|
||||
" one. To start a new one, press any other key, then fFtTsS
|
||||
let g:sneak#s_next = 1
|
||||
" use ignorecase/smartcase, depending on vim setting
|
||||
let g:sneak#use_ic_scs = 1
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
let g:terminator_clear_default_mappings = "foo bar"
|
||||
let g:terminator_split_location = "vertical botright"
|
||||
|
||||
nnoremap <silent> <leader>rr :TerminatorStartREPL <CR>
|
||||
nnoremap <silent> <leader>rs :TerminatorStopRun <CR>
|
||||
|
||||
nnoremap <silent> <leader>rt :TerminatorRunFileInTerminal <CR>
|
||||
vnoremap <silent> <leader>rt :TerminatorRunPartOfFileInTerminal<CR>
|
||||
|
||||
nnoremap <silent> <leader>rd :TerminatorSendDelimiterToTerminal<CR>
|
||||
vnoremap <silent> <leader>rd :TerminatorSendSelectionToTerminal<CR>
|
||||
|
||||
nnoremap <silent> <leader>ra :norm O# In[ ]:hh
|
||||
|
||||
" lets you send fragments from jupyter-style blocks and markdown fences
|
||||
let g:terminator_repl_delimiter_regex = '\(In\[.*\]:\|^```\)'
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
" PLUGIN: tmux-navigator
|
||||
" add seamless movement between vim and tmux, switch windows with C-hjkl
|
||||
" automatically save the current buffer when navigating away from vim
|
||||
let g:tmux_navigator_save_on_switch = 1
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
" PLUGIN: wiki.vim
|
||||
if $WIKIROOT ==? ''
|
||||
let g:wiki_root = expand('~/documents/notes')
|
||||
else
|
||||
let g:wiki_root = $WIKIROOT
|
||||
endif
|
||||
" filetypes to automatically enable the plugin for, seems to take file endings
|
||||
" rather than vim ft
|
||||
let g:wiki_filetypes = ['md', 'mkd', 'markdown', 'wiki']
|
||||
let g:wiki_mappings_use_defaults = 'global'
|
||||
let g:wiki_list_todos = ['[ ]', '[x]']
|
||||
|
||||
" wiki automatic link creation
|
||||
" add .md to the end of links by default
|
||||
let g:wiki_link_extension = '.md'
|
||||
" add a link in the format [descr](target) by default
|
||||
" not in wiki format [[link|descr]]
|
||||
let g:wiki_link_target_type = 'md'
|
||||
|
||||
" change file opening scheme of external wiki links
|
||||
function! WikiFileOpen(...) abort dict
|
||||
" use xdg-open for now -- can still customize if need be, see
|
||||
" :help wiki-config -> g:wiki_file_open for an example
|
||||
silent execute '!xdg-open' fnameescape(self.path) '&'
|
||||
return 1
|
||||
endfunction
|
||||
let g:wiki_file_handler = 'WikiFileOpen'
|
||||
|
||||
" Zettelkasten functionality
|
||||
|
||||
" Appends Zettelkasten timestamp to beginning of links
|
||||
function! ZettelLinkCreate(text) abort
|
||||
" lowercase and replace spaces with dashes (-) to make links uniform
|
||||
let l:text=substitute(tolower(a:text), '\s\+', '-', 'g')
|
||||
" prepend datestamp
|
||||
let l:text=substitute(l:text, '^', s:Datestamp() . ' '. '\0', 'g')
|
||||
return l:text
|
||||
endfunction
|
||||
" sets wiki.vim to automatically apply datestamp function to created links
|
||||
let g:wiki_map_link_create = 'ZettelLinkCreate'
|
||||
|
||||
let g:zettel_anchor_separator = ' '
|
||||
let g:zettel_anchor_pattern = '[:/]\d\{10,14}'
|
||||
" Returns the full path to the Zettel owning the anchor id passed in
|
||||
function! s:GetZettelPath(anchor) abort
|
||||
" match first 10-digit-beggining file ending with .md
|
||||
" e.g. 1906061330 My example-Zettel.md
|
||||
let l:tomatch='/' . trim(a:anchor) . g:zettel_anchor_separator . '.*\.md'
|
||||
let l:allnotes=split(globpath(g:wiki_root, '**'), '\n')
|
||||
|
||||
" get absolute path
|
||||
let l:matched = matchstr(l:allnotes, l:tomatch)
|
||||
" make path relative to root to pass back to wiki.vim
|
||||
let l:curfpath = expand('%:p:h')
|
||||
let l:matched = substitute(l:matched, l:curfpath, '', '')
|
||||
|
||||
return l:matched
|
||||
endfunction
|
||||
command! -nargs=1 ZettelOpen execute ":e " . s:GetZettelPath(<q-args>)
|
||||
|
||||
" Uses the Zettel Anchor ID instead of the whole link structure to traverse
|
||||
" the whole Wiki directory from its root and opens first fitting Zettel
|
||||
function! ZettelOpenAtCursor(...) abort
|
||||
let l:link = wiki#link#get()
|
||||
try
|
||||
let l:zettel = s:GetZettelPath( s:ExtractZettelAnchor(l:link.url) )
|
||||
|
||||
" fall back to normal link opening otherwise
|
||||
if l:zettel ==? ''
|
||||
call wiki#link#follow()
|
||||
else
|
||||
call wiki#page#follow(l:zettel)
|
||||
endif
|
||||
catch /E716:/
|
||||
call wiki#link#toggle(l:link)
|
||||
catch /E37:/
|
||||
echoerr 'E37: Can''t open link before you''ve saved the current buffer.'
|
||||
endtry
|
||||
endfunction
|
||||
command! ZettelOpenAtCursor :call ZettelOpenAtCursor()
|
||||
|
||||
" Returns only the anchor id in a file name
|
||||
" - returns empty string if nothing was found
|
||||
function! s:ExtractZettelAnchor(file) abort
|
||||
return trim(matchstr(a:file, g:zettel_anchor_pattern), ' \t\r:/')
|
||||
endfunction
|
||||
|
||||
" Creates a Zettelkasten compatible unique datestamp
|
||||
function s:Datestamp()
|
||||
if !exists('*strftime')
|
||||
:echoerr 'Date Stamp creation needs strftime available on system!'
|
||||
endif
|
||||
return strftime('%y%m%d%H%M')
|
||||
endfunction
|
||||
command! Datestamp :echom s:Datestamp()
|
||||
Loading…
Add table
Add a link
Reference in a new issue