f-person / git-blame.nvim

Git Blame plugin for Neovim written in Lua
GNU General Public License v3.0
884 stars 43 forks source link

lazyvim proper setup #129

Closed davidgao7 closed 5 months ago

davidgao7 commented 5 months ago

Hi,

I'm trying to tweak to adapt the setting in lazy nvim, I could successfully set commands, but options like gitblame_message_template, gitblame_enabled doesn't work, and I couldn't be able to see git blames after open a committed file in a git repo.

I try to set gitblame_enabled = 0/1, none of the options work, but if I call the command it will work

-- TODO: default show git blame when opening git files
return {
    {
      -- git blame plugin
      "f-person/git-blame.nvim",
      init = function()
        -- git blame template
        -- Available options: <author>, <committer>, <date>, <committer-date>, <summary>, <sha>
        vim.g.gitblame_message_template = " <summary> • <date> • <author>"
        -- enables git-blame.nvim on Neovim startup
        vim.g.gitblame_enabled = 1
        -- start virtual text at column
        -- Have the blame message start at a given column instead of EOL.
        -- If the current line is longer than the specified column value
        -- the blame message will default to being displayed at EOL.
        vim.g.gitblame_virtual_text_column = 1
      end,

      keys = {
        {
          "<leader>gbu",
          "<cmd>GitBlameToggle<cr>",
          desc = "toggle git blame",
        },
        {
          "<leader>gbe",
          "<cmd>GitBlameEnable<cr>",
          desc = "enable git blame",
        },
        {
          "<leader>gbd",
          "<cmd>GitBlameDisable<cr>",
          desc = "disable git blame",
        },
        {
          "<leader>gbh",
          "<cmd>GitBlameCopySHA<cr>",
          desc = "copy line commit SHA",
        },
        {
          "<leader>gbl",
          "<cmd>GitBlameCopyCommitURL<cr>",
          desc = "copy line commit URL",
        },
        {
          "<leader>gbo",
          "<cmd>GitBlameOpenFileURL<cr>",
          desc = "opens file in default browser",
        },
        {
          "<leader>gbc",
          "<cmd>GitBlameCopyFileURL<cr>",
          desc = "copy file url to clipboard",
        },
      },
    },
    {
      "folke/which-key.nvim",
      opts = {
        defaults = {
          ["<leader>gb"] = { name = "git blame+" },
        },
      },
    },
}

let me know if I could help/There's something I'm doing wrong! I want to thank everyone who is maintaining this awesome plugin!

timofurrer commented 5 months ago

Something like the following works to set the options:

  {
    'f-person/git-blame.nvim',
    opts = {
      enabled = false,
      message_template = "<<sha>> • <author> • <date> • <summary>",
      date_format = "%Y-%m-%d",
    },
    keys = {
      { "<leader>Gb", "<cmd>GitBlameToggle<cr>", desc = "Toggle blame information" },
      { "<leader>GB", "<cmd>GitBlameOpenFileURL<cr>", desc = "Open blame in browser" },
    }
davidgao7 commented 5 months ago

@timofurrer Thank you for replying!

sorry I probably didn't describe my issue clearly

When I open a git file I have to manually call the command < GitBlameEnable> by using my shortcut to see the git blame,

If I just use default settings

return {
    "f-person/git-blame.nvim",
}

the git blame message will show right after opening a git file without calling the command,

is there a way to see the blame message right after opening a git file by default?


I read the :help gitblame and tried to set gitblame_enabled/enabled to true/false/0/1 but none of them worked.

instead of using the init function, I also tried lazy opts but it didn't work either

return{
    "f-person/git-blame.nvim",
    opts = {
        -- gitblame_enabled = 1,
      enabled = true,
      message_template = " <summary> • <date> • <author> • <<sha>>",
      date_format = "%m-%d-%Y %H:%M",
    },
   keys = {
      ......
   }
}
f-person commented 5 months ago

There have been some other issues related to lazyvim, as well. I don't know if it directly somehow configures the plugin before you do, which results in the issues, but I'm not very familiar with it. However, if there's an option to only "import" a plugin and call the init/setup function yourself, perhaps that's worth trying?

folke commented 5 months ago

Because of the keys part, you will be lazy loading this plugin. The plugin wil only load once one of the keys is used.

If you want to load the plugin at startup, add something like event = "VeryLazy", or lazy = false. One of both options will work.

davidgao7 commented 5 months ago

Because of the keys part, you will be lazy loading this plugin. The plugin wil only load once one of the keys is used.

If you want to load the plugin at startup, add something like event = "VeryLazy", or lazy = false. One of both options will work.

Thanks everyone, I add event = "VeryLazy and the plugin is loaded at startup! For other people who are having the similar issues, here's my config, feel free taking my setup as a reference

return {
  {
    -- git blame plugin
    "f-person/git-blame.nvim",
    -- dir = "~/git-blame.nvim",
    -- load the plugin at startup
    event = "VeryLazy",
    -- Because of the keys part, you will be lazy loading this plugin.
    -- The plugin wil only load once one of the keys is used.
    -- If you want to load the plugin at startup, add something like event = "VeryLazy",
    -- or lazy = false. One of both options will work.
    opts = {
      enabled = true,
      message_template = " <summary> • <date> • <author> • <<sha>>",
      date_format = "%m-%d-%Y %H:%M:%S",
      virtual_text_column = 1,
    },
    keys = {
      {
        "<leader>gbu",
        "<cmd>GitBlameToggle<cr>",
        desc = "toggle git blame",
      },
      {
        "<leader>gbe",
        "<cmd>GitBlameEnable<cr>",
        desc = "enable git blame",
      },
      {
        "<leader>gbd",
        "<cmd>GitBlameDisable<cr>",
        desc = "disable git blame",
      },
      {
        "<leader>gbh",
        "<cmd>GitBlameCopySHA<cr>",
        desc = "copy line commit SHA",
      },
      {
        "<leader>gbl",
        "<cmd>GitBlameCopyCommitURL<cr>",
        desc = "copy line commit URL",
      },
      {
        "<leader>gbo",
        "<cmd>GitBlameOpenFileURL<cr>",
        desc = "opens file in default browser",
      },
      {
        "<leader>gbc",
        "<cmd>GitBlameCopyFileURL<cr>",
        desc = "copy file url to clipboard",
      },
    },
  },
  {
    "folke/which-key.nvim",
    -- default show git blame when open git files
    opts = {
      defaults = {
        ["<leader>gb"] = { name = "git blame+" },
      },
    },
  },
}

@folke hope you have a wonderful vacation man! @f-person I could also update the installation and configuration instructions for lazy.nvim

davidgao7 commented 5 months ago

I'm going to close this issue

f-person commented 5 months ago

@f-person I could also update the installation and configuration instructions for lazy.nvim

Yup, that would be great, @davidgao7. Glad it's resolved now, hope you enjoy the plugin! :)

@folke thanks for the help and have a great vacation :)

davidgao7 commented 5 months ago

@f-person I could also update the installation and configuration instructions for lazy.nvim

Yup, that would be great, @davidgao7. Glad it's resolved now, hope you enjoy the plugin! :)

@folke thanks for the help and have a great vacation :)

@f-person Yeah, thank you and thank everyone who is maintaining this plugin here is the pull request for lazy installation instuction and here is the pull request for Chinese version for lua-timeago

I'm still learning how to contribute to opensource, feel free to tell me what are the proper ways of doing pull requests, comments etc.

thanks everyone!