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

lazyvim proper setup #129

Closed
davidgao7 opened this issue Apr 7, 2024 · 8 comments
Closed

lazyvim proper setup #129

davidgao7 opened this issue Apr 7, 2024 · 8 comments

Comments

@davidgao7
Copy link
Contributor

davidgao7 commented Apr 7, 2024

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
Copy link

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
Copy link
Contributor Author

davidgao7 commented Apr 9, 2024

@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
Copy link
Owner

f-person commented Apr 9, 2024

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
Copy link

folke commented Apr 12, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

I'm going to close this issue

@f-person
Copy link
Owner

@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
Copy link
Contributor Author

@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!

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