LazyVim for coding

See also: notes/LazyVim

Things I still wanna do

Useful things to know right-away

Folding

Sometimes you open a complex code with a lot of blocks with nested indentation.

Useful keybindings to use in these cases:

LSP

Sometimes Language Servers don't work and a :LspStart (or :LspRestart) solves the issue.


configs

.bats as shell scripts

This is important to have shfmt and shellcheck even when working on bats files.

Put this at the end of lua/config/options.lua

vim.filetype.add({
  extension = { bats = "sh" },
})

disable json and yaml "renderization"

NOTE: we can also disable conceallevel on demand with <leader>uc

lua/config/autocmds.lua:

-- Disable the concealing in some file formats
-- This "conceal" thing omits quotes.
vim.api.nvim_create_autocmd({ "FileType" }, {
  pattern = { "json", "jsonc", "yaml" },
  callback = function()
    vim.wo.conceallevel = 0
  end,
})

LazyExtras

SQL

database queries from inside neovim

I started to play with dadbod.vim to interact with a Postgres Data Base, and it is awesome!

For the notes/LazyVim users, you just need to enable lang.sql in :LazyExtrasnow you can do things like:

  • <leader>D - open the DBUI
  • while in normal/visual mode, <leader>S  to run an SQL query
  • you can save your queries

tip: use this connection URL to access a Postgres DB

postgres://{USER}:{PASS}@{DB_HOST}:{PORT}/{DB_NAME}

There are more features, but these simple ones are already killer features for me.

Now I don't need to interrupt my flow to run a simple query in the database.

references

GitHub Copilot

https://www.lazyvim.org/extras/coding/copilot

:LazyExtras -> coding.copilot

I also configured a way to enable/disable copilot in lua/plugins/copilot.lua:

return {
  -- TODO: find a way to toggle copilot

  vim.keymap.set("n", "<leader>cpd", ":Copilot disable<cr>", { desc = "GitHub Copilot Disable" }),
  vim.keymap.set("n", "<leader>cpe", ":Copilot enable<cr>", { desc = "GitHub Copilot Enable" }),
}

external plugins

treesj

A very satisfying plugin to split blocks with breaklines lines!

return {
  "Wansmer/treesj",
  keys = {
    {
      "<leader>ct",
      ":TSJToggle<cr>",
      desc = "Toggle Treesitter Split",
    },
  },
  cmd = { "TSJToggle", "TSJSplit", "TSJJoin" },
  opts = { use_default_keymaps = false },
}

Open in GitHub

Useful to open the current project/file in the browser (or simply copy the URL to the clipboard)

lua/plugins/openingh.lua

return {
  "Almo7aya/openingh.nvim",
  -- tip from here:
  -- https://github.com/Almo7aya/openingh.nvim/issues/24#issuecomment-2212536651
  init = function()
    vim.g.openingh_copy_to_register = true
  end,
  keys = {
    -- open in browser
    {
      "<leader>gBr",
      ":OpenInGHRepo<cr>",
      desc = "Open Repo on Browser",
    },
    {
      "<leader>gBf",
      ":OpenInGHFile<cr>",
      desc = "Open File on GitHub",
    },
    {
      "<leader>gBf",
      ":OpenInGHFileLines<cr>",
      desc = "Open Lines on GitHub",
      mode = "v",
    },

    -- yank to clipboard
    {
      "<leader>gyr",
      ":OpenInGHRepo+<cr>",
      desc = "Yank Repo URL",
    },
    {
      "<leader>gyf",
      ":OpenInGHFile+<cr>",
      desc = "Yank File URL",
    },
    {
      "<leader>gyf",
      ":OpenInGHFileLines+<cr>",
      desc = "Yank Lines URL",
      mode = "v",
    },
  },
}


references