Skip to content

Warmer weather

Thoughts for the week

Practicalli AstroNvim User Config changed to be as additive as possible, leaving the template as unchanged as possible.

The sunnier weather is a boots to motivation, although its still very windy. At least I can get into the garden without sinking.

Another Saturday morning ride, a tough experience although not completely exhausted afterward.

AstroNvim example configλ︎

A really nice addition to AstroNvim 4 is the use of a conditional check at the start of configuration files. This conditional check provides a simple way to disable or activate the configuration in a specific file.

Rather than significantly edit the existing AstroNvim template configuration, additional files in lua/plugins/ can be added and easily enabled or disabled, making the configuration more widely usable.

By avoiding changes to the original template configuration, it is far simpler to update the Practicalli AstroNvim User Config with enhancements from the AstroNvim template.

Activate configuration statement

if true then return {} end -- WARN: REMOVE THIS LINE TO ACTIVATE THIS FILE
Add or Override Plugin and configuration
lua/plugins/example-config.lua
return {
  {
    "domain/project-name",
    -- lazy = true,  -- true: load at startup, false: load on filetype
    filetype = { "language", "*.fileextension" },
    dependencies = {
      "AstroNvim/astrocore",
      opts = {
        options = {
          -- configure general options: vim.opt.<key>
          g = {
            -- configure global vim variables: vim.g
          },
        },
        mappings = {
          n = {
            -- normal mode key bindings
            -- setting a mapping to false will disable it
            -- ["<esc>"] = false,
          },
          t = {
            -- terminal? mode key bindings
          },
          v = {
            -- visual mode key bindings
          },
        },
      },
    },
  },
}

AstroNvim Clojure configλ︎

nvim-treesitter-sexp neovim plugin is a lua rewrite of the commonly used vim-sexp vim plugin.

nvim-treesitter-sexp is easier to configure with the lazy package manager.

Default key map is provided with the nvim-treesitter-sexp, although keys can be disabled using the ops = {keymaps = {commands = {command_name = false,}}}. I tried providing alternative key mappings using this section but that did not seem to work.

Using the standard approach to key maps worked well, so a set of alternate key maps were provided.

Alternative SPC k key map for nvim-treesitter-sexp
      {
        "PaterJason/nvim-treesitter-sexp",
        filetype = ["clojure"],
        dependencies = {
          "AstroNvim/astrocore",
          opts = {
            mappings = {
              n = {
                -- Additional Which-key key bindings for nvim-treesitter-sexp
                ["<leader>k"] = { name = "Structural Editing" },
                ["<leader>kE"] = { "<cmd>TSSexp swap_prev_elem<cr>", desc = "Swap Previous Element" },
                ["<leader>ke"] = { "<cmd>TSSexp swap_next_elem<cr>", desc = "Swap Previous Element" },
                ["<leader>kF"] = { "<cmd>TSSexp swap_prev_form<cr>", desc = "Swap Previous Form" },
                ["<leader>kf"] = { "<cmd>TSSexp swap_next_form<cr>", desc = "Swap Previous Form" },
                ["<leader>kk"] = { "<cmd>TSSexp promote_elem<cr>", desc = "Promote Element" },
                ["<leader>kr"] = { "<cmd>TSSexp promote_form<cr>", desc = "Promote Form" },
                ["<leader>k@"] = { "<cmd>TSSexp splice<cr>", desc = "Splice" },
                ["<leader>kS"] = { "<cmd>TSSexp slurp_left<cr>", desc = "Slurp Left" },
                ["<leader>ks"] = { "<cmd>TSSexp slurp_right<cr>", desc = "Slurp Right" },
                ["<leader>kB"] = { "<cmd>TSSexp barf_left<cr>", desc = "Barf Left" },
                ["<leader>kb"] = { "<cmd>TSSexp barf_right<cr>", desc = "Barf Right" },
                ["<leader>kI"] = { "<cmd>TSSexp barf_right<cr>", desc = "Insert Head" },
                ["<leader>ki"] = { "<cmd>TSSexp barf_right<cr>", desc = "Insert Tail" },
              },
              t = {
                -- terminal? mode key bindings
              },
              v = {
                -- visual mode key bindings
              },
            },
          },
        },
      },

Using a common Space k menu for they key bindings simplifies the discovery of commands.

nvim-treesitter-sexp config with alternate key mappings

lua/plugins/clojure.clj
  {
    "PaterJason/nvim-treesitter-sexp",
    filetype = lisp_dialects,
    dependencies = {
      "AstroNvim/astrocore",
      opts = {
        -- configuration:
        -- https://github.com/PaterJason/nvim-treesitter-sexp#configuration
        enabled = false,
        --     -- Set to false to disable individual keymaps
        set_cursor = true,
        -- keymaps = {
        -- Default key bindings - set to false to disable
        --   commands = {
        --     swap_prev_elem = "<e",
        --     swap_next_elem = ">e",
        --     swap_prev_form = "<f",
        --     swap_next_form = ">f",
        --     promote_elem = "<LocalLeader>O",
        --     promote_form = "<LocalLeader>o",
        --     splice = "<LocalLeader>@",
        --     slurp_left = "<(",
        --     slurp_right = ">)",
        --     barf_left = ">(",
        --     barf_right = "<)",
        --     insert_head = "<I",
        --     insert_tail = ">I",
        --   },
        --   motions = {
        --     form_start = "(",
        --     form_end = ")",
        --     prev_elem = "[e",
        --     next_elem = "]e",
        --     prev_elem_end = "[E",
        --     next_elem_end = "]E",
        --     prev_top_level = "[[",
        --     next_top_level = "]]",
        --   },
        --   textobjects = {
        --     inner_elem = "ie",
        --     outer_elem = "ae",
        --     inner_form = "if",
        --     outer_form = "af",
        --     inner_top_level = "iF",
        --     outer_top_level = "aF",
        --   },
        -- },
        options = {
          g = {},
        },
        mappings = {
          n = {
            -- Additional Which-key key bindings for nvim-treesitter-sexp
            ["<leader>k"] = { name = "Structural Editing" },
            ["<leader>kE"] = { "<cmd>TSSexp swap_prev_elem<cr>", desc = "Swap Previous Element" },
            ["<leader>ke"] = { "<cmd>TSSexp swap_next_elem<cr>", desc = "Swap Previous Element" },
            ["<leader>kF"] = { "<cmd>TSSexp swap_prev_form<cr>", desc = "Swap Previous Form" },
            ["<leader>kf"] = { "<cmd>TSSexp swap_next_form<cr>", desc = "Swap Previous Form" },
            ["<leader>kk"] = { "<cmd>TSSexp promote_elem<cr>", desc = "Promote Element" },
            ["<leader>kr"] = { "<cmd>TSSexp promote_form<cr>", desc = "Promote Form" },
            ["<leader>k@"] = { "<cmd>TSSexp splice<cr>", desc = "Splice" },
            ["<leader>kS"] = { "<cmd>TSSexp slurp_left<cr>", desc = "Slurp Left" },
            ["<leader>ks"] = { "<cmd>TSSexp slurp_right<cr>", desc = "Slurp Right" },
            ["<leader>kB"] = { "<cmd>TSSexp barf_left<cr>", desc = "Barf Left" },
            ["<leader>kb"] = { "<cmd>TSSexp barf_right<cr>", desc = "Barf Right" },
            ["<leader>kI"] = { "<cmd>TSSexp barf_right<cr>", desc = "Insert Head" },
            ["<leader>ki"] = { "<cmd>TSSexp barf_right<cr>", desc = "Insert Tail" },
          },
          t = {
            -- terminal? mode key bindings
          },
          v = {
            -- visual mode key bindings
          },
        },
      },
    },
  },

Thank you.

🌐 Practical.li Website

Practical.li GitHub Org practicalli-johnny profile

@practicalli@clj.social @practical_li