xvzc / chezmoi.nvim

Chezmoi plugin for neovim
MIT License
73 stars 3 forks source link

Chezmoi vim and chezmoi nvim conflict together #11

Closed Demianeen closed 4 months ago

Demianeen commented 5 months ago

Hi, I just recently fall in love with chezmoi and dotfiles) To manage chezmoi files I use:

  1. chezmoi.vim. It provides highlighting for .tmpl and name-specific files like .zshrc
  2. chezmoi.nvim for editing chezmoi files and automatically applying them

But I stumbled over that chezmoi.vim conflicts with chezmoi.nvim when chezmoi.vim creates a temp buffer for supporting files like .tmpl. I don't understand why, but it just copies empty strings into the clipboard when I open a NEW chezmoi buffer.

https://github.com/xvzc/chezmoi.nvim/assets/51330172/e8396cf2-c88a-41c6-9a5d-21a8bb0fc0d3

The issue only appears when autocmd from docs is set:

vim.api.nvim_create_autocmd({ 'BufRead', 'BufNewFile' }, {
  pattern = { os.getenv('HOME') .. '/.local/share/chezmoi/*' },
  callback = function()
    vim.schedule(require('chezmoi.commands.__edit').execute())
  end,
})

Do you think it is possible to find a workaround around it?

xvzc commented 5 months ago

Would you try with minimal config? i've tried setting up chezmoi.nvim and chezmoi.vim together, but this issue could not be reproduced.

xvzc commented 5 months ago

I also have a question for you. Is there any reason to use both chezmoi.vim and chezmoi.nvim? because now it seems like chezmoi.vim also provides some methods to automatically apply the changes for your chezmoi-managed files. Why don't you just pick one of them?

Demianeen commented 5 months ago

Sure. I will try to do minimal repro tomorrow.

I also have a question for you. Is there any reason to use both chezmoi.vim and chezmoi.nvim? because now it seems like chezmoi.vim also provides some methods to automatically apply the changes for your chezmoi-managed files. Why don't you just pick one of them?

I like chezmoi search files preserving old naming feature. Through I didn't know I can have auto applying with chezmoi vim.

Main reason I use chezmoi vim alongside chezmoi nvim is syntax highlighting in chezmoi files like dot_zshrc or .tmpl. Do you think it possible to have syntax highlighting in chezmoi files with only your plugin? Or would you recommend try to stick with chezmoi vim for everything?

xvzc commented 5 months ago

Oh i see. i've never had any problems with syntax highlighting tho. I tend to just use the modeline feature which is built-in for both vim and neovim

my chezmoi template files look like below

aliases.zsh.tmpl


#!/bin/zsh
# vim:filetype=sh:tw=80

alias vi='nvim'

{{ if eq .osid "darwin" }}

alias ofd='open .'

{{ else if eq .osid "linux-arch" }}

alias open='thunar'

{{ end }}

...



And yaeh, if you can get it working with whatever plugin, it's up to you deciding which plugin to stick only with :smile:
Demianeen commented 4 months ago

Thanks for the idea. Didn't know you can use something like this)

While I was trying to reproduce again, I found that the issue was caused by chezmoi.vim alone, without any chezmoi.nvim included. I just forgot to apply chezmoi file by myself when the chezmoi.nvim was disabled. Already used to it)