bcampolo / nvim-starter-kit

Neovim Starter Kit
MIT License
236 stars 37 forks source link

Improved gx #7

Closed voyeg3r closed 2 months ago

voyeg3r commented 8 months ago

whit this you do not need full url so gx works

local open_command = 'xdg-open'
if vim.fn.has('mac') == 1 then
  open_command = 'open'
end

local function url_repo()
  local cursorword = vim.fn.expand('<cfile>')
  if string.find(cursorword, '^[a-zA-Z0-9-_.]*/[a-zA-Z0-9-_.]*$') then
    cursorword = 'https://github.com/' .. cursorword
  end
  return cursorword or ''
end

map(
  'n',
  'gx',
  function()
    vim.fn.jobstart({ open_command, url_repo() }, { detach = true })
  end,
  {
    silent = true,
    desc = 'xdg open link',
  }
)

there is also a map function on my utils

-- https://blog.devgenius.io/create-custom-keymaps-in-neovim-with-lua-d1167de0f2c2
-- https://oroques.dev/notes/neovim-init/
M.map = function(mode, lhs, rhs, opts)
  local options = { noremap = true }
  if opts then
    options = vim.tbl_extend('force', options, opts)
  end
  -- vim.api.nvim_set_keymap(mode, lhs, rhs, options)
  vim.keymap.set(mode, lhs, rhs, options)
end
voyeg3r commented 8 months ago

improved dd

map(
  'n',
  'dd',
  function()
    local empty_line = vim.api.nvim_get_current_line():match('^%s*$')
    return (empty_line and '"_dd' or 'dd')
  end,
  { expr = true, desc = "delete blank lines to black hole register" }
)
bcampolo commented 2 months ago

This seems like a nice change, but I don't know that everyone would want this, so I will close the issue for now.