epwalsh / epwalsh/obsidian.nvim
Completion wipes out unrelated text
- Dominant language
- Lua
- Stars
- 6.2k
- Forks
- 250
- PR merge metrics
- No merged PRs in 30d
Description
### 🐛 Describe the bug
If I write [[Note name this is now unrelated text, completing when my cursor is at the position will wipe out the end of the line, included unrelated text.
### Config
```{
'epwalsh/obsidian.nvim',
enabled = true,
lazy = true,
event = 'BufReadPre ' .. vim.fn.expand '~' .. '/Obsidian/**.md',
cmd = { 'ObsidianOpen', 'ObsidianQuickSwitch', 'ObsidianSearch' },
-- If you want to use the home shortcut '~' here you need to call 'vim.fn.expand':
-- event = { "BufReadPre " .. vim.fn.expand "~" .. "/my-vault/**.md" },
dependencies = {
-- Required.
'nvim-lua/plenary.nvim',
-- Optional, for completion.
'hrsh7th/nvim-cmp',
-- Optional, for search and quick-switch functionality.
'nvim-telescope/telescope.nvim',
-- Optional, alternative to nvim-treesitter for syntax highlighting.
'godlygeek/tabular',
-- "preservim/vim-markdown",
'ixru/nvim-markdown',
},
opts = {
dir = '~/Obsidian/myVault/', -- no need to call 'vim.fn.expand' here
-- Optional, if you keep notes in a specific subdirectory of your vault.
notes_subdir = 'Zettelkasten/',
daily_notes = {
-- Optional, if you keep daily notes in a separate directory.
folder = 'Temporal/Daily Notes/',
-- Optional, if you want to change the date format for daily notes.
date_format = '%Y-%m-%d',
},
-- Optional, completion.
completion = {
nvim_cmp = true, -- if using nvim-cmp, otherwise set to false
},
-- -- Optional, customize how names/IDs for new notes are created.
note_id_func = function(title)
return title
end,
--
-- Optional, set to true if you don't want Obsidian to manage frontmatter.
disable_frontmatter = true,
-- Optional, alternatively you can customize the frontmatter data.
note_frontmatter_func = function(note)
-- This is equivalent to the default frontmatter function.
-- local out = { id = note.id, aliases = note.aliases, tags = note.tags }
local out = {}
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and require('obsidian').util.table_length(note.metadata) > 0 then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
return out
end,
-- -- Optional, for templates (see below).
-- templates = {
-- subdir = "templates",
-- date_format = "%Y-%m-%d-%a",
-- time_format = "%H:%M",
-- },
--
-- Optional, by default when you use `:ObsidianFollowLink` on a link to an external
-- URL it will be ignored but you can customize this behavior here.
follow_url_func = function(url)
-- Open the URL in the default web browser.
vim.fn.jobstart { 'open', url } -- Mac OS
-- vim.fn.jobstart({"xdg-open", url}) -- linux
end,
-- Optional, set to true if you use the Obsidian Advanced URI plugin.
-- https://github.com/Vinzent03/obsidian-advanced-uri
use_advanced_uri = true,
-- Optional, set to true to force ':ObsidianOpen' to bring the app to the foreground.
open_app_foreground = true,
-- Optional, by default commands like `:ObsidianSearch` will attempt to use
-- telescope.nvim, fzf-lua, and fzf.nvim (in that order), and use the
-- first one they find. By setting this option to your preferred
-- finder you can attempt it first. Note that if the specified finder
-- is not installed, or if it the command does not support it, the
-- remaining finders will be attempted in the original order.
finder = 'telescope.nvim',
},
config = function(_, opts)
require 'setup.export_obsidian' -- load personal export function.
require('obsidian').setup(opts)
-- Optional, override the 'gf' keymap to utilize Obsidian's search functionality.
-- see also: 'follow_url_func' config option above.
vim.keymap.set('n', 'gf', function()
if require('obsidian').util.cursor_on_markdown_link() then
return 'ObsidianFollowLink'
else
return 'gf'
end
end, { noremap = false, expr = true })
end,
keys = {
{ 'of', 'ObsidianQuickSwitch', desc = 'Open Obsidian File' },
{ 'oo', 'ObsidianOpen', desc = 'Open Note in Obsidian' },
{ 'ob', 'ObsidianBacklinks', desc = 'Open Backlinks' },
},
}```
### Environment
```
NVIM v0.10.1
Build type: Release
LuaJIT 2.1.1724512491
Run "nvim -V1 -v" for more info
Obsidian.nvim v3.9.0 (14e0427bef6c55da0d63f9a313fd9941be3a2479)
Status:
• buffer directory: nil
• working directory: /Users/matthewscott/Obsidian/myVault
Workspaces:
✓ active workspace: Workspace(name='myVault', path='/Users/matthewscott/Obsidian/myVault', root='/Users/matthewscott/Obsidian/myVault')
Dependencies:
✓ plenary.nvim: ec289423a1693aeae6cd0d503bac2856af74edaa
✓ nvim-cmp: ae644feb7b67bf1ce4260c231d1d4300b19c6f30
✓ telescope.nvim: a0bbec21143c7bc5f8bb02e0005fa0b982edc026
Integrations:
✓ picker: TelescopePicker()
✓ completion: enabled (nvim-cmp) ✗ refs, ✗ tags, ✗ new
all sources:
• copilot
• nvim_lsp
• luasnip
• path
• otter
• treesitter
Tools:
✓ rg: ripgrep 14.1.0
Environment:
• operating system: Darwin
Config:
• notes_subdir: Zettelkasten/%
```
Contributor guide
Research direction
Reproduce completion with the reported Neovim and nvim-cmp setup using text after the cursor, then trace the completion handling entry point. Verify how the replacement range is determined and confirm that completing [[Note name]] preserves unrelated trailing text.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100