Skip to content

Instantly share code, notes, and snippets.

@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>
@eduardoarandah
eduardoarandah / ok.lua
Created August 25, 2022 19:37
#tip don’t run some files in your config if requirements are needed.
-- Check requirements
local all_requirements = 1
for _, requirement in ipairs({ "git", "rg", "node", "npm" }) do
if vim.fn.executable(requirement) == 0 then
print("plugins require " .. requirement)
all_requirements = 0
end
end
if all_requirements == 0 then
@eduardoarandah
eduardoarandah / script.sh
Created August 25, 2022 13:18
neovim is your config REALLY portable?
# run ubuntu in docker
docker run -it --rm --name myubuntu ubuntu:latest
## requirements
apt update
apt -y install software-properties-common dirmngr apt-transport-https lsb-release ca-certificates build-essential git ripgrep nodejs npm
## add neovim
add-apt-repository ppa:neovim-ppa/stable -y
apt update
@eduardoarandah
eduardoarandah / a.vim
Created August 24, 2022 20:42
Close all empty buffers with this function
function! CloseEmptyBuffers()
let buffers = filter(range(1, bufnr('$')), 'buflisted(v:val) && empty(bufname(v:val)) && bufwinnr(v:val)<0 && !getbufvar(v:val, "&mod")')
if !empty(buffers)
exe 'bw ' . join(buffers, ' ')
endif
endfunction
command! CloseEmptyBuffers :call CloseEmptyBuffers()
@eduardoarandah
eduardoarandah / init.lua
Last active July 6, 2022 17:50
vim to neovim migration helper
-------------------------------------------------------------------------------------
-- 1) Copy this file anywhere,
-- 2) Paste your options in "opts"
-- 3) Source it with :source %
--
-- If you get "unknown option" then remove it from opts and put it in "globals"
--
-- checkopts() checks for values that already are defaults. Remove this function when you're done
-- checkglobals() the same but for globals
--