Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Navigate wikilinks#463

armaninux started this conversation inIdeas
Mar 3, 2024· 2 comments· 1 reply
Discussion options

I wrote a function to navigate between wikilinks with the Tab key. If only one link is present in the files, it will also open it.

I think it would be cool to have something like this as a new feature.

" first, don't move the cursor/don't alter the viewcommand! -nargs=1 -complete=command Nomove    \   try    \ |     let s:svpos = winsaveview()    \ |     execute <q-mods> <q-args>    \ | finally    \ |     call winrestview(s:svpos)    \ |     unlet s:svpos    \ | endtry" checks how many linksfunction! WikiCountLinks()    let l:count = 0    Nomove g/\[\[/let l:count += 1    Nomove g/\[\[.*\[\[/let l:count += 1    if l:count == 1        " one link then open it        WikiOnlyLink    else        WikiGotoLink    endifendfunctioncommand! WikiOnlyLink execute 'norm! /\[\[<cr>:ObsidianFollowLink<cr>'command! WikiGotoLink execute 'norm! /\[\[<cr>'" mappings for md files onlyaugroup obsidian    autocmd!    autocmd Filetype markdown nnoremap <silent> <Tab> :call WikiCountLinks()<cr>    autocmd Filetype markdown nnoremap <silent> <S-Tab> ?]]<cr>augroup END
You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

that would be really nice! where do I need to put this for it to work?

You must be logged in to vote
1 reply
@armaninux
Comment options

If you're using an init.vim as your neovim config file, just paste everything in there, it's all written in vimscript.
If you're using an init.lua, you need to translate it to lua script and I honestly don't know how it's done. You need to check a guide about that, for examplehttps://github.com/nanotee/nvim-lua-guide.

Comment options

Claude came up with a nice Lua version that seems to work for both Wiki style[[link]] and markdown style[text](link) links:

vim.api.nvim_create_autocmd("FileType", {pattern="markdown",callback=function()vim.keymap.set('n','<Tab>','/\\(\\[\\[\\|\\[.\\{-}\\](\\)<CR>:nohlsearch<CR>', {buffer=true })vim.keymap.set('n','<S-Tab>','?\\(\\[\\[\\|\\[.\\{-}\\](\\)<CR>:nohlsearch<CR>', {buffer=true })end})
You must be logged in to vote
0 replies
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
3 participants
@armaninux@firecat53@simonlearnscoding

[8]ページ先頭

©2009-2025 Movatter.jp