Skip to content

Instantly share code, notes, and snippets.

@eduardoarandah
eduardoarandah / init.lua
Created April 6, 2025 03:54
neovim command to copy selection as a code snippet, with filename, line number and then the code snippet
-- Command to copy selection as a code snippet, with filename, line number and then the code snippet
vim.api.nvim_create_user_command("CopyCodeSnippet", function(opts)
local start_line = vim.fn.line("'<") - 1
local end_line = vim.fn.line("'>")
local file_name = vim.fn.expand("%:.")
local lines = vim.api.nvim_buf_get_lines(0, start_line, end_line, false)
local file_type = vim.api.nvim_buf_get_option(0, "filetype")
-- set clipboard
vim.fn.setreg("*", file_name .. " +" .. (start_line + 1) .. "\n\n```" .. file_type .. "\n" .. table.concat(lines, "\n") .. "\n```")
@eduardoarandah
eduardoarandah / llm_context.lua
Created February 25, 2025 20:31
Create context for LLM in neovim, save all your buffers as context.xml with F10
-----------------------------
-- Create context for the LLM
--
-- Save as: lua/llm_context.lua
--
-- How to use: require("llm_context").setup()
--
-- Reference:
-- Long context prompting tips
-- https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips#example-quote-extraction
@eduardoarandah
eduardoarandah / commands.lua
Last active February 19, 2025 17:35
create context for the llm in neovim
-----------------------------
-- Create context for the LLM
-- Long context prompting tips
-- https://docs.anthropic.com/en/docs/build-with-claude/prompt-engineering/long-context-tips#example-quote-extraction
-----------------------------
-- Dump context with documents tags
vim.api.nvim_create_user_command("ContextDump", function()
local content = vim.fn.getreg("z")
vim.fn.setreg("+", "<documents>\n" .. content .. "</documents>")
@eduardoarandah
eduardoarandah / commands.lua
Created February 7, 2025 05:43
Copy context in neovim using textobjects
-----------------------------
-- Create context for the LLM
-----------------------------
-- Clear register z
vim.api.nvim_create_user_command("ContextClear", 'let @z=""', { bang = true })
-- Create a user command :CopyFunction that calls our function.
vim.api.nvim_create_user_command("ContextAddFunction", function()
-- Append relative path and line number
@eduardoarandah
eduardoarandah / example.vim
Created February 6, 2024 22:49
Command to duplicate a filename and rename its class name
" Duplicate class
command! -nargs=1 DuplicateClass :call DuplicateClass(<f-args>)
function! DuplicateClass(new_class)
let l:original_class = expand('%:t:r')
let l:original_extension = expand('%:e')
let l:new_full_path = expand('%:h').'/'. a:new_class.'.'.l:original_extension
" Copy contents of original file to new file
execute 'silent execute "write ' .l:new_full_path.'"'
execute 'silent execute "edit ' .l:new_full_path.'"'
@eduardoarandah
eduardoarandah / complex_replace.lua
Last active August 3, 2023 19:10
Neovim, complex replacement in lua
-- GOAL: replace placeholders with values
--
-- FIELDS EXAMPLE:
-- title,text,link
-- hello,world,something.com
-- good,morning,example.com
-- another,line,asdf.com
-- last,line,asdf.com
--
-- PATTERN EXAMPLE:
@eduardoarandah
eduardoarandah / init.lua
Created June 6, 2023 18:12
Show a floating popup in neovim with lua
-- show a floating popup
local function show_popup(size_percentage, filetype, title, lines)
-- build buffer
local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_option(buf, "bufhidden", "wipe")
vim.api.nvim_buf_set_option(buf, "filetype", filetype)
vim.api.nvim_buf_set_keymap(buf, "n", "<esc>", ":bd<cr>", { nowait = true, noremap = true, silent = true })
vim.api.nvim_open_win(buf, true, {
style = "minimal",
relative = "editor",
@eduardoarandah
eduardoarandah / Dockerfile
Last active March 6, 2023 23:58
php7.4, mariadb and mailcrab on docker for laravel/wordpress
# https://www.digitalocean.com/community/tutorials/how-to-install-and-set-up-laravel-with-docker-compose-on-ubuntu-22-04
FROM php:7.4-cli
# Arguments defined in docker-compose.yml
ARG user
ARG uid
# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
@eduardoarandah
eduardoarandah / commands.lua
Last active October 6, 2022 15:54
neovim lua command to copy filename, line number and branch
-- Copy filename, line number and branch
-- example: src/filename.js +123 # branch master
vim.api.nvim_create_user_command("CopyPathLineNumberBranch", function()
local branch = vim.fn.systemlist("git branch --show-current")
local comment = ""
if not string.find(branch[1], "not a git repository") then
comment = " # branch " .. branch[1]
end
vim.fn.setreg("*", vim.fn.expand("%") .. " +" .. vim.api.nvim_win_get_cursor(0)[1] .. comment)
end, args)
@eduardoarandah
eduardoarandah / bug1.vue
Created August 30, 2022 16:59
bugs in volar
<script setup lang="ts">
interface IFoo {
id: number;
name: string;
}
const foos: Array<IFoo> = [
{ id: 1, name: "aaa" },
{ id: 2, name: "bbb" },
];
</script>