Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renaming page with <leader>wr fails to update links in existing pages #1377

Open
4 tasks done
foldedstar opened this issue Oct 31, 2023 · 4 comments
Open
4 tasks done

Comments

@foldedstar
Copy link

foldedstar commented Oct 31, 2023

  • Include the VimWiki settings from your .vimrc
    neovim: vimwiki.lua
return {
  -- Configuration for vimwiki plugin
  {
    "vimwiki/vimwiki",
    -- defaults to the latest commit on the dev branch. If encountering stability issues try switching to a stable release per below
    version = "*", -- enable this to try installing the latest stable versions of plugins
    event = "BufEnter *.md", -- lazy load on event
    keys = { "<leader>ww", "<leader>wt" },

    -- Guidance for vimwiki is to set properties before the plugin is loaded - hence setting via 'init' rather than 'config'
    init = function()
      vim.g.vimwiki_list = {
        {
          -- Just one wiki for now. Add others here if required
          path = "~/Documents/notes/",
          syntax = "markdown",
          ext = ".md",
        },
      }
      vim.g.vimwiki_folding = "list"
      vim.g.vimwiki_hl_headers = 1 -- use alternating colours for different heading levels
      vim.g.vimwiki_global_ext = 0 --" don't treat all md files as vimwiki
      vim.g.vimwiki_markdown_link_ext = 1 -- add markdown file extension when generating links
      vim.g.taskwiki_markdown_syntax = "markdown"

      vim.g.vimwiki_ext2syntax =
        { -- the set of extensions registered with vimwiki. Setting this overrides the default (a wider set)
          [".md"] = "markdown",
          [".markdown"] = "markdown",
          [".mdown"] = "markdown",
        }

      -- Set your own key mappings
      vim.api.nvim_set_keymap(
        "n",
        "<leader>wb",
        ":VimwikiBacklinks<CR>",
        { noremap = true, silent = true, nowait = true }
      )
    end,
  },
  • Include the syntax you are using (default / Markdown / MediaWiki)
    Markdown

  • Provide a detailed description of the problem including steps to reproduce the issue.
    Create and open a new page via a link
    Save that page
    wr -> rename = [y]es -> enter a new filename
    No errors are shown. Messages correctly show 'Vimwiki: updating links in /.../.../eachPage.md'
    However when you navigate to the page from which the renamed file was originally linked, the link is unchanged.

    • Clicking the link here results in a new page being created (because the original is no longer there)
    • The newly renamed page is now orphened wrt the wiki index
    • All prior links to the renamed page need to be manually updated instead.
  • The output of :VimwikiShowVersion:
    │Version: 2022.12.02 │
    │Os: Mac │
    │Vim: 801 │
    │Branch: HEAD │
    │Revision: be45bd6
    │Date: 2023-04-04 20:13:34 -0600

@foldedstar
Copy link
Author

I've done a little debugging and I've determined that links in the form name are correctly renamed.
It is only when a file is created via a [[name]] link insertion, and then that file is subsequently renamed (wr) that those [[name]] links are not reflected.

Is this intended functionality (i.e. is renaming of [[ ]] links unsupported), or is this a bug?

@tinmarino
Copy link
Member

Markdown does not support the double "[[" links for now. This is a pending tasks, sorry for the inconvenience.

Meanwhile, you can perform custom changes in the file vars.vim to imitate the default (wiki) syntax.

Have a look at #892 (Pressing enter to create a [[double bracket]]).

There is another issue to support double square bracket in markdown but I lost track.

I leave this ticket open as this is a desired feature (the future change should support renaming as well).

Note that it is hard to support both type of links, which is why I have been procrastinating this feature for 2 years now

@ludenticus
Copy link

Wanted to open an issue, but found out @foldedstar already pointed this out... I guess it makes much sense: either to stick with vimwiki syntax, or stick with []() format in MD.

@pbhemphill
Copy link

I don't believe this is related to the type of link used. I have noticed that, in general, :VimwikiRenameFile properly renames relative links, but fails to update absolute links (that is, /-initial links relative to the wiki root, not filesystem-absolute paths). This appears to be the case for both the default and markdown syntaxes.

I have tested this on a clean vimwiki directory with a minimal vimrc. A minimal example follows:

Relevant part of vimrc:

let wiki = {}
let wiki.path = '~/test_vimwiki'
let wiki.syntax = 'default'
let wiki.index = 'home'
let wiki.ext = '.wiki'
let g:vimwiki_list = [wiki]

home.wiki contains:

Test page link: [[page_name]]

Test absolute page link: [[/page_name]]

page_name.wiki exists and is navigable from both links in home.wiki.

When I call :VimwikiRenameFile while in page_name.wiki and rename the file to new_page_name, home.wiki then contains:

Test page link: [[new_page_name]]

Test absolute page link: [[/page_name]]

Expected behavior is that both links would be updated, so home.wiki should contain:

Test page link: [[new_page_name]]

Test absolute page link: [[/new_page_name]]

A similar set of steps confirms that this happens with markdown syntax and markdown-style []() links as well.

This becomes an issue when I link to a top-level file from a diary file, which requires an absolute path - if I later rename that file, the link in the diary entry breaks.

My :VimwikiShowVersion:

Version: 2024.01.24
Os: Mac
Vim: 901
Branch: dev
Revision: 69318e7
Date: 2024-03-16 14:23:28 -0300

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants