From da62cc9fc36450751f37756f0ca9ccd356a5c417 Mon Sep 17 00:00:00 2001 From: Shubham Pawar Date: Fri, 10 Jan 2025 17:07:28 +0530 Subject: [PATCH] chore: adding custom snippets and switching from `mini.comments` to `ts-comments` --- .config/lazygit/state.yml | 3 +- .config/nvim/lua/plugins/blink-cmp.lua | 131 ++++++++++++++++++++- .config/nvim/lua/plugins/comment.lua | 41 ++----- .config/nvim/lua/plugins/dooing.lua | 1 + .config/nvim/lua/plugins/fzf-lua.lua | 57 ++++++++- .config/nvim/lua/plugins/lazydo.lua | 13 ++ .config/nvim/lua/plugins/lsp/astrolsp.lua | 17 +-- .config/nvim/lua/plugins/mini/comment.lua | 2 +- .config/nvim/lua/plugins/nvim-cmp.lua | 15 ++- .config/nvim/lua/plugins/nvim-scissors.lua | 28 +++++ .config/nvim/lua/plugins/sessions.lua | 124 +++---------------- .config/nvim/lua/plugins/toggleterm.lua | 31 ++--- .config/nvim/snippets/javascriptreact.json | 88 ++++++++++++++ .config/nvim/snippets/lua.json | 74 ++++++++++++ .config/nvim/snippets/package.json | 29 +++++ .config/nvim/snippets/typescriptreact.json | 91 ++++++++++++++ .gitignore | 1 - .ignore | 1 - 18 files changed, 558 insertions(+), 189 deletions(-) create mode 100644 .config/nvim/lua/plugins/lazydo.lua create mode 100644 .config/nvim/lua/plugins/nvim-scissors.lua create mode 100644 .config/nvim/snippets/javascriptreact.json create mode 100644 .config/nvim/snippets/lua.json create mode 100644 .config/nvim/snippets/package.json create mode 100644 .config/nvim/snippets/typescriptreact.json diff --git a/.config/lazygit/state.yml b/.config/lazygit/state.yml index 215bdd7..36e351e 100644 --- a/.config/lazygit/state.yml +++ b/.config/lazygit/state.yml @@ -1,8 +1,7 @@ lastupdatecheck: 0 recentrepos: - - /home/shubham/Documents/Programming/WebDev/temp-app - - /home/shubham/Documents/dotfiles - /home/shubham/Documents/Programming/WebDev/social-media-manager-app + - /home/shubham/Documents/dotfiles - /home/shubham/Documents/Programming/WebDev/invoice-genrator-nextjs - /home/shubham/Documents/Programming/WebDev/vue3-chrome-ai - /home/shubham/Documents/Programming/WebDev/demo-shadcn diff --git a/.config/nvim/lua/plugins/blink-cmp.lua b/.config/nvim/lua/plugins/blink-cmp.lua index 5bea415..2f680fc 100644 --- a/.config/nvim/lua/plugins/blink-cmp.lua +++ b/.config/nvim/lua/plugins/blink-cmp.lua @@ -1,12 +1,11 @@ +-- NOTE: Specify the trigger character(s) used for luasnip +local trigger_text = ';' ---@type LazySpec return { 'Saghen/blink.cmp', enabled = false, - -- use a release tag to download pre-built binaries version = '*', - -- optional: provides snippets for the snippet source dependencies = { - 'rafamadriz/friendly-snippets', 'mikavilpas/blink-ripgrep.nvim', { 'folke/lazydev.nvim', @@ -21,6 +20,43 @@ return { }, }, { 'Bilal2453/luvit-meta', lazy = true }, + { + 'L3MON4D3/LuaSnip', + version = 'v2.*', + build = 'make install_jsregexp', + dependencies = { 'rafamadriz/friendly-snippets' }, + opts = { history = true, delete_check_events = 'TextChanged', region_check_events = 'CursorMoved' }, + config = function(_, opts) + if opts then + require('luasnip').config.setup(opts) + end + + vim.tbl_map(function(type) + require('luasnip.loaders.from_' .. type).lazy_load() + end, { 'vscode', 'snipmate', 'lua' }) + require('luasnip.loaders.from_vscode').lazy_load({ paths = { vim.fn.stdpath 'config' .. '/snippets' } }) + + local extends = { + typescript = { 'tsdoc' }, + javascript = { 'jsdoc' }, + lua = { 'luadoc' }, + python = { 'pydoc' }, + rust = { 'rustdoc' }, + cs = { 'csharpdoc' }, + java = { 'javadoc' }, + c = { 'cdoc' }, + cpp = { 'cppdoc' }, + php = { 'phpdoc' }, + kotlin = { 'kdoc' }, + ruby = { 'rdoc' }, + sh = { 'shelldoc' }, + } + -- friendly-snippets - enable standardized comments snippets + for ft, snips in pairs(extends) do + require('luasnip').filetype_extend(ft, snips) + end + end, + }, }, ---@module 'blink.cmp' ---@type blink.cmp.Config @@ -69,7 +105,7 @@ return { ---@type blink-ripgrep.Options opts = { prefix_min_len = 4, - score_offset = 10, -- should be lower priority + score_offset = -3, -- should be lower priority max_filesize = '300K', search_casing = '--smart-case', }, @@ -80,6 +116,75 @@ return { -- make lazydev completions top priority (see `:h blink.cmp`) score_offset = 100, }, + lsp = { + name = 'lsp', + enabled = true, + module = 'blink.cmp.sources.lsp', + kind = 'LSP', + fallbacks = { 'snippets', 'buffer' }, + score_offset = 95, -- the higher the number, the higher the priority + }, + path = { + name = 'Path', + module = 'blink.cmp.sources.path', + score_offset = 25, + fallbacks = { 'buffer' }, + opts = { + trailing_slash = false, + label_trailing_slash = true, + get_cwd = function(context) + return vim.fn.expand(('#%d:p:h'):format(context.bufnr)) + end, + show_hidden_files_by_default = true, + }, + }, + buffer = { + name = 'Buffer', + enabled = true, + module = 'blink.cmp.sources.buffer', + min_keyword_length = 4, + score_offset = 15, -- the higher the number, the higher the priority + }, + snippets = { + name = 'snippets', + enabled = true, + min_keyword_length = 2, + module = 'blink.cmp.sources.snippets', + score_offset = 80, -- the higher the number, the higher the priority + -- Only show snippets if I type the trigger_text characters, so + -- to expand the "bash" snippet, if the trigger_text is ";" I have to + should_show_items = function() + local col = vim.api.nvim_win_get_cursor(0)[2] + local before_cursor = vim.api.nvim_get_current_line():sub(1, col) + -- NOTE: remember that `trigger_text` is modified at the top of the file + return before_cursor:match(trigger_text .. '%w*$') ~= nil + end, + -- After accepting the completion, delete the trigger_text characters + -- from the final inserted text + transform_items = function(_, items) + local col = vim.api.nvim_win_get_cursor(0)[2] + local before_cursor = vim.api.nvim_get_current_line():sub(1, col) + local trigger_pos = before_cursor:find(trigger_text .. '[^' .. trigger_text .. ']*$') + if trigger_pos then + for _, item in ipairs(items) do + item.textEdit = { + newText = item.insertText or item.label, + range = { + start = { line = vim.fn.line '.' - 1, character = trigger_pos - 1 }, + ['end'] = { line = vim.fn.line '.' - 1, character = col }, + }, + } + end + end + -- NOTE: After the transformation, I have to reload the luasnip source + -- Otherwise really crazy shit happens and I spent way too much time + -- figurig this out + vim.schedule(function() + require('blink.cmp').reload 'snippets' + end) + return items + end, + }, }, cmdline = function() local type = vim.fn.getcmdtype() @@ -92,5 +197,23 @@ return { return {} end, }, + snippets = { + preset = 'luasnip', + -- This comes from the luasnip extra, if you don't add it, won't be able to + -- jump forward or backward in luasnip snippets + -- https://www.lazyvim.org/extras/coding/luasnip#blinkcmp-optional + expand = function(snippet) + require('luasnip').lsp_expand(snippet) + end, + active = function(filter) + if filter and filter.direction then + return require('luasnip').jumpable(filter.direction) + end + return require('luasnip').in_snippet() + end, + jump = function(direction) + require('luasnip').jump(direction) + end, + }, }, } diff --git a/.config/nvim/lua/plugins/comment.lua b/.config/nvim/lua/plugins/comment.lua index 67d4c85..17f964e 100644 --- a/.config/nvim/lua/plugins/comment.lua +++ b/.config/nvim/lua/plugins/comment.lua @@ -1,39 +1,12 @@ ---@type LazySpec return { - { - 'numToStr/Comment.nvim', - enabled = false, - keys = { - { 'gc', mode = { 'x', 'n' }, desc = 'comment' }, - { 'gb', desc = 'Comment(block)' }, - { '/', 'lua require("Comment.api").toggle.linewise.current()', desc = 'Toggle Comment' }, - { - '/', - function() - local esc = vim.api.nvim_replace_termcodes('', true, false, true) - vim.api.nvim_feedkeys(esc, 'nx', false) - require('Comment.api').toggle.linewise(vim.fn.visualmode()) - end, - mode = 'v', - desc = 'Toggle Comment', - }, - { '', '"ayy"aplua require("Comment.api").toggle.linewise.current()', desc = 'Toggle Comment' }, + 'folke/ts-comments.nvim', + opts = { + lang = { + jsdoc = '/** %s */', + phpdoc = { '// %s' }, }, - dependencies = { - { - 'JoosepAlviste/nvim-ts-context-commentstring', - config = function() - -- vim.g.skip_ts_context_commentstring_module = true - require('ts_context_commentstring').setup({ - enable_autocmd = false, - }) - end, - }, - }, - config = function() - require('Comment').setup({ - pre_hook = require('ts_context_commentstring.integrations.comment_nvim').create_pre_hook(), - }) - end, }, + event = 'VeryLazy', + enabled = vim.fn.has 'nvim-0.10.0' == 1, } diff --git a/.config/nvim/lua/plugins/dooing.lua b/.config/nvim/lua/plugins/dooing.lua index 1bc171b..4397787 100644 --- a/.config/nvim/lua/plugins/dooing.lua +++ b/.config/nvim/lua/plugins/dooing.lua @@ -2,6 +2,7 @@ return { 'atiladefreitas/dooing', keys = { 'td' }, + enabled = false, cmd = { 'Dooing' }, opts = { -- Keymaps diff --git a/.config/nvim/lua/plugins/fzf-lua.lua b/.config/nvim/lua/plugins/fzf-lua.lua index 5c1c7b0..5576973 100644 --- a/.config/nvim/lua/plugins/fzf-lua.lua +++ b/.config/nvim/lua/plugins/fzf-lua.lua @@ -1,3 +1,44 @@ +--- ivy fzf +--[[ +local fzf_lua = require("fzf-lua") +fzf_lua.files{ + prompt = "Files", + fzf_opts = { ["--layout"] = "reverse" }, + winopts = { + height = 0.35, + width = 1.00, + row = 1, + col = 1, + border = { " ", " ", " ", " ", " ", " ", " ", " " }, + preview = { + layout = "flex", + hidden = "nohidden", + flip_columns = 130, + scrollbar = "float", + scrolloff = "-1", + scrollchars = { "█", "░" }, + }, + }, +} +--]] + +---Dropdown fzf +--[[ +local fzf_lua = require("fzf-lua") +fzf_lua.files{ + prompt = "Files", +fzf_opts = { ["--layout"] = "reverse" }, + winopts = { + height = 0.70, + width = 0.45, + row = 0.1, + col = 0.5, + preview = { hidden = "hidden", layout = "vertical", vertical = "up:50%" }, + }, +} +--]] + +---@type LazySpec return { 'ibhagwan/fzf-lua', dependencies = { 'nvim-tree/nvim-web-devicons' }, @@ -50,6 +91,7 @@ return { ['alt-enter'] = actions.file_tabedit, ['ctrl-t'] = actions.file_tabedit, ['ctrl-x'] = actions.file_split, + ['ctrl-g'] = fzf.actions.grep_lgrep, -- ['ctrl-q'] = actions.file_edit_or_qf, } -- calling `setup` is optional for customization @@ -167,10 +209,21 @@ return { helptags = { winopts = { preview = { layout = 'vertical', vertical = 'up:60%' } } }, grep = { winopts = { preview = { layout = 'vertical', vertical = 'up:60%' } }, + multiprocess = true, + prompt = ' ', actions = m_keys, + rg_opts = "--hidden --column --line-number --no-ignore-vcs --no-heading --color=always --smart-case -g '!{.git,node_modules,android,ios,.env,.next,dist,package-lock.json,yarn.lock,pnpm-lock.yaml,.svelte-kit,*.aider.*}'", + rg_glob = true, - glob_flah = '--glob', glob_separator = '%s%-%-', + glob_flag = '--iglob', -- for case sensitive globs use '--glob' + rg_glob_fn = function(query, opts) + -- this enables all `rg` arguments to be passed in after the `--` glob separator + local search_query, glob_str = query:match('(.*)' .. opts.glob_separator .. '(.*)') + local glob_args = glob_str:gsub('^%s+', ''):gsub('-', '%-') .. ' ' + + return search_query, glob_args + end, }, blines = { actions = m_keys, @@ -325,7 +378,7 @@ return { { desc = '[F]iles' }, }, ['fr'] = { fzf.resume, { desc = '[R]esume' } }, - ['fs'] = { fzf.live_grep_native, { desc = '[S]earch(Project)' } }, + ['fs'] = { fzf.live_grep, { desc = '[S]earch(Project)' } }, ['fc'] = { fzf_create_file, { desc = 'Create File' } }, ['fS'] = { function() diff --git a/.config/nvim/lua/plugins/lazydo.lua b/.config/nvim/lua/plugins/lazydo.lua new file mode 100644 index 0000000..9922816 --- /dev/null +++ b/.config/nvim/lua/plugins/lazydo.lua @@ -0,0 +1,13 @@ +---@type LazySpec +return { + 'Dan7h3x/LazyDo', + keys = { -- recommended keymap for easy toggle LazyDo in normal and insert modes (arbitrary) + { + '', + 'LazyDoToggle', + mode = { 'n', 'i' }, + desc = 'Toggle LazyDo', + }, + }, + opts = {}, +} diff --git a/.config/nvim/lua/plugins/lsp/astrolsp.lua b/.config/nvim/lua/plugins/lsp/astrolsp.lua index 4b30f3e..34186c2 100644 --- a/.config/nvim/lua/plugins/lsp/astrolsp.lua +++ b/.config/nvim/lua/plugins/lsp/astrolsp.lua @@ -278,11 +278,11 @@ return { desc = 'Workspace symbols', cond = 'workspace/symbol', }, - [''] = { - vim.lsp.buf.rename, - desc = 'Rename', - cond = 'textDocument/rename', - }, + -- [''] = { + -- vim.lsp.buf.rename, + -- desc = 'Rename', + -- cond = 'textDocument/rename', + -- }, ['lr'] = { vim.lsp.buf.rename, desc = 'Rename', @@ -350,9 +350,12 @@ return { }, handlers = { function(server, opts) - local ok, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp') - if ok then + local ok_cmp, cmp_nvim_lsp = pcall(require, 'cmp_nvim_lsp') + local ok_blink, blink = pcall(require, 'blink.cmp') + if ok_cmp then opts.capabilities = cmp_nvim_lsp.default_capabilities(opts.capabilities) + elseif ok_blink then + opts.capabilities = blink.get_lsp_capabilities(opts.capabilities) end require('lspconfig')[server].setup(opts) end, diff --git a/.config/nvim/lua/plugins/mini/comment.lua b/.config/nvim/lua/plugins/mini/comment.lua index 2004af6..434ccf7 100644 --- a/.config/nvim/lua/plugins/mini/comment.lua +++ b/.config/nvim/lua/plugins/mini/comment.lua @@ -2,7 +2,7 @@ return { 'echasnovski/mini.comment', version = '*', - enabled = true, + enabled = false, keys = { { 'gc', mode = { 'n', 'x', 'o' } }, { 'gcc' }, diff --git a/.config/nvim/lua/plugins/nvim-cmp.lua b/.config/nvim/lua/plugins/nvim-cmp.lua index 9abef46..47597da 100644 --- a/.config/nvim/lua/plugins/nvim-cmp.lua +++ b/.config/nvim/lua/plugins/nvim-cmp.lua @@ -20,16 +20,14 @@ end --- detect if the current completion item is an emmet completion item --- @param entry cmp.Entry ---- @return boolean +---@return boolean local function isEmmet(entry) - return ( - entry:get_kind() == require('cmp.types').lsp.CompletionItemKind.Text + local isTextOrSnippet = entry:get_kind() == require('cmp.types').lsp.CompletionItemKind.Text or entry:get_kind() == require('cmp.types').lsp.CompletionItemKind.Snippet - ) - and ( - entry.source:get_debug_name() == 'nvim_lsp:emmet_language_server' - or entry.source:get_debug_name() == 'nvim_lsp:emmet_ls' - ) + local isEmmetls = entry.source:get_debug_name() == 'nvim_lsp:emmet_language_server' + or entry.source:get_debug_name() == 'nvim_lsp:emmet_ls' + + return isTextOrSnippet and isEmmetls end ---@type LazySpec @@ -62,6 +60,7 @@ return { vim.tbl_map(function(type) require('luasnip.loaders.from_' .. type).lazy_load() end, { 'vscode', 'snipmate', 'lua' }) + require('luasnip.loaders.from_vscode').lazy_load({ paths = { vim.fn.stdpath 'config' .. '/snippets' } }) local extends = { typescript = { 'tsdoc' }, diff --git a/.config/nvim/lua/plugins/nvim-scissors.lua b/.config/nvim/lua/plugins/nvim-scissors.lua new file mode 100644 index 0000000..669ced9 --- /dev/null +++ b/.config/nvim/lua/plugins/nvim-scissors.lua @@ -0,0 +1,28 @@ +---@type LazySpec +return { + 'chrisgrieser/nvim-scissors', + opts = { + snippetDir = vim.fn.stdpath 'config' .. '/snippets/', -- this is already the default, but I want to be explicit + ---@type "yq"|"jq"|"none"|string[] + jsonFormatter = vim.fn.executable 'jq' == 1 and 'jq' or 'none', + }, + keys = { + { 's', '', desc = '+[S]nippets' }, + { + 'se', + function() + require('scissors').editSnippet() + end, + desc = 'Snippet: [E]dit', + }, + { + 'sn', + function() + require('scissors').addNewSnippet() + end, + mode = { 'n', 'x' }, + { desc = 'Snippet: [N]ew' }, + }, + { 'sd', 'AutoSession delete', desc = '[D]elte' }, + }, +} diff --git a/.config/nvim/lua/plugins/sessions.lua b/.config/nvim/lua/plugins/sessions.lua index 19eb0b4..e61818f 100644 --- a/.config/nvim/lua/plugins/sessions.lua +++ b/.config/nvim/lua/plugins/sessions.lua @@ -1,113 +1,21 @@ -local au_group = vim.api.nvim_create_augroup('sp_sessions', { clear = true }) ---@type LazySpec return { - { - 'Shatur/neovim-session-manager', - event = 'BufWinEnter', - enabled = false, - cmd = 'SessionManager', - keys = { - { 'sl', 'SessionManager! load_session', desc = '[S]ession [L]oad' }, - { 'sL', 'SessionManager! load_last_session', desc = '[S]ession [L]oad Last' }, - { - 'sc', - 'SessionManager! load_current_dir_session', - desc = '[S]ession Load Current Directory', - }, - }, - dependencies = { - 'nvim-lua/plenary.nvim', - -- { - -- 'stevearc/dressing.nvim', - -- opts = { - -- select = { - -- backend = { 'fzf_lua', 'telescope', 'builtin', 'nui' }, - -- }, - -- }, - -- }, - }, - config = function() - local session_manager = require 'session_manager' - session_manager.setup({ - -- Possible values: Disabled, CurrentDir, LastSession - autoload_mode = require('session_manager.config').AutoloadMode.CurrentDir, - }) - end, + 'rmagatti/auto-session', + lazy = false, + cmd = { 'AutoSession', 'SessionManager' }, + ---enables autocomplete for opts + ---@module "auto-session" + ---@type AutoSession.Config + opts = { + enabled = true, + auto_save = true, + suppressed_dirs = { '~/', '~/Projects', '~/Downloads', '/' }, + use_git_branch = true, }, - { - 'stevearc/resession.nvim', - enabled = false, - lazy = true, - init = function() - local function get_session_name() - local name = vim.fn.getcwd() - local branch = vim.trim(vim.fn.system 'git branch --show-current') - if vim.v.shell_error == 0 then - return name .. branch - else - return name - end - end - vim.api.nvim_create_autocmd('VimEnter', { - desc = 'Load session on VimEnter', - callback = function() - -- Only load the session if nvim was started with no args - if vim.fn.argc(-1) == 0 then - vim.schedule(function() - require('resession').load(get_session_name(), { dir = 'dirsession', silence_errors = true }) - end) - end - end, - nested = true, - }) - vim.api.nvim_create_autocmd('VimLeavePre', { - desc = 'Save session on VimLeavePre', - callback = function() - require('resession').save(get_session_name(), { dir = 'dirsession', notify = false }) - end, - }) - end, - opts = {}, - config = function(_, opts) - require('resession').setup(opts) - end, - keys = { - { 'ss', 'lua require("resession").save()', desc = '[S]ession [S]ave' }, - { 'sd', 'lua require("resession").delete()', desc = '[S]ession [D]elete' }, - { - 'sl', - function() - vim.ui.select( - require('resession').list({ dir = 'dirsession' }), - { prompt = 'Select Session> ' }, - function(selected_session) - if selected_session == nil or not selected_session then - return - end - require('resession').load(selected_session, { dir = 'dirsession', silence_errors = true }) - end - ) - end, - desc = '[S]ession [L]ist', - }, - }, - }, - { - 'rmagatti/auto-session', - lazy = false, - cmd = { 'AutoSession', 'SessionManager' }, - ---enables autocomplete for opts - ---@module "auto-session" - ---@type AutoSession.Config - opts = { - suppressed_dirs = { '~/', '~/Projects', '~/Downloads', '/' }, - use_git_branch = true, - }, - keys = { - { 's', '', desc = '+[S]ession' }, - { 'ss', 'SessionSave', desc = '[S]ave' }, - { 'sl', 'AutoSession search', desc = '[L]ist' }, - { 'sd', 'AutoSession delete', desc = '[D]elte' }, - }, + keys = { + { 'S', '', desc = '+[S]ession' }, + { 'Ss', 'SessionSave', desc = '[S]ave' }, + { 'Sl', 'AutoSession search', desc = '[L]ist' }, + { 'Sd', 'AutoSession delete', desc = '[D]elte' }, }, } diff --git a/.config/nvim/lua/plugins/toggleterm.lua b/.config/nvim/lua/plugins/toggleterm.lua index fea0ef7..b90c6d2 100644 --- a/.config/nvim/lua/plugins/toggleterm.lua +++ b/.config/nvim/lua/plugins/toggleterm.lua @@ -1,15 +1,22 @@ +---@type LazySpec return { 'akinsho/nvim-toggleterm.lua', version = '*', keys = { 'tl', '' }, - config = function() + opts = { + shell = vim.o.shell == '/bin/fish' and '/bin/zsh' or vim.o.shell, + direction = 'float', + open_mapping = [[]], + highlights = { FloatBorder = { link = 'FloatBorder' } }, + float_opts = { border = 'single' }, + }, + config = function(_, opts) local Terminal = require('toggleterm.terminal').Terminal local toggleterm = require 'toggleterm' local lazygit = Terminal:new({ cmd = 'lazygit', dir = 'git_dir', direction = 'float', - -- shell = vim.o.shell == '/bin/fish' and '/bin/zsh' or vim.o.shell, float_opts = { border = 'curved' }, }) @@ -17,25 +24,7 @@ return { lazygit:toggle() end - toggleterm.setup({ - shell = vim.o.shell == '/bin/fish' and '/bin/zsh' or vim.o.shell, - direction = 'float', - open_mapping = [[]], - highlights = { - FloatBorder = { link = 'FloatBorder' }, - }, - float_opts = { - border = 'single', - }, - -- highlights = { - -- Normal = { - -- guibg = '#080818', - -- }, - -- NormalFloat = { - -- guibg = '#080818', - -- }, - -- }, - }) + toggleterm.setup(opts) vim.keymap.set('n', 'tl', lazygit_toggle, { desc = '[T]erminal [L]azygit' }) end, } diff --git a/.config/nvim/snippets/javascriptreact.json b/.config/nvim/snippets/javascriptreact.json new file mode 100644 index 0000000..49b9870 --- /dev/null +++ b/.config/nvim/snippets/javascriptreact.json @@ -0,0 +1,88 @@ +{ + "useClient": { + "prefix": "uc", + "body": ["\"use client\";$0"], + "description": "use client for next.js" + }, + "reactClientComponent": { + "prefix": "rnc", + "body": [ + "\"use client\";", + "", + "const ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}} = () => {", + " return (", + "
$0
", + " )", + "}", + "", + "export default ${1}" + ], + "description": "Creates a React Client Component" + }, + "reactFunctionalComponent": { + "prefix": "rfc", + "body": [ + "const ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}} = () => {", + " return (", + "
$0
", + " )", + "}", + "", + "export default ${1}" + ], + "description": "Creates a React Functional Component with ES7 module system" + }, + "reactFunctionalLayoutComponent": { + "prefix": "rlc", + "body": [ + "const ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}Layout = ({children}) => {", + " return (", + "
$0", + " \t{children}", + "
", + " )", + "}", + "", + "export default ${1}Layout" + ], + "description": "Creates a React Layout Functional Component with ES7 module system" + }, + "reactNativeFC": { + "prefix": "rnf", + "body": [ + "import { View } from 'react-native';", + "", + "const ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}} = () => {", + " return $0", + "}", + "", + "export default ${1};" + ], + "description": "Create React Native Functional Component" + }, + "reactNativeFCWithStyles": { + "prefix": "rnfs", + "body": [ + "import { View, StyleSheet } from 'react-native';", + "", + "const ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}} = () => {", + " return $0", + "}", + "", + "const styles = StyleSheet.create({$2})", + "", + "export default ${1};" + ], + "description": "Create React Native Functional Component(with styles)" + }, + "jsx elements ternary": { + "prefix": "jc", + "body": "{${1:true} ?
$0
: ${2:null}}", + "description": "ternary jsx elements" + }, + "jsx elements ternaryNative": { + "prefix": "jcn", + "body": "{${1:true} ? $0 : ${2:null}}", + "description": "ternary jsx elements" + } +} diff --git a/.config/nvim/snippets/lua.json b/.config/nvim/snippets/lua.json new file mode 100644 index 0000000..e014a7d --- /dev/null +++ b/.config/nvim/snippets/lua.json @@ -0,0 +1,74 @@ +{ + "mod": { + "prefix": "mod", + "body": ["---@type LazySpec", "return {", "\t'$1'", "\topts = {}", "}"], + "description": "Create a lazy plugin spec" + }, + "modConfig": { + "prefix": "modc", + "body": [ + "---@type LazySpec", + "return {", + "\t'$1'", + "\tconfig = function()\n$0\n\tend", + "}" + ], + "description": "Create a lazy plugin spec - config" + }, + "plugin": { + "prefix": "plug", + "body": ["---@type LazySpec", "return {", "\t'$1'", "\topts = {$2}", "}"], + "description": "Create a lazy plugin spec" + }, + "pluginConfig": { + "prefix": "plugc", + "body": [ + "---@type LazySpec", + "return {", + "\t'$1'", + "\tconfig = function()\n$0\n\tend", + "}" + ], + "description": "Create a lazy plugin spec - config" + }, + "autocmd (Filetype)": { + "prefix": "autocmd (Filetype)", + "body": [ + "vim.api.nvim_create_autocmd('FileType', {", + "\t-- desc = '',", + "\t-- group = '',", + "\tpattern = { '${1:ft}' },", + "\tcallback = function()", + "\t\t$0", + "\tend,", + "})" + ], + "description": "Create an autocmd for FileType" + }, + "autocmd (any)": { + "prefix": "autocmd (any)", + "body": [ + "vim.api.nvim_create_autocmd('$1', {", + "\t-- desc = '',", + "\t-- group = '',", + "\tpattern = { '${2:event}' },", + "\tcallback = function()", + "\t\t$0", + "\tend,", + "})" + ], + "description": "Create an autocmd for FileType" + }, + "augroup": { + "prefix": "augroup", + "body": [ + "local ${1:augroup} = vim.api.nvim_create_augroup('sp_${1}', {})$0" + ], + "description": "Create an augroup" + }, + "executable": { + "prefix": "exe", + "body": ["vim.fn.executable('${1:cmd}') == 1"], + "description": "Check if a command is executable" + } +} diff --git a/.config/nvim/snippets/package.json b/.config/nvim/snippets/package.json new file mode 100644 index 0000000..4c400a9 --- /dev/null +++ b/.config/nvim/snippets/package.json @@ -0,0 +1,29 @@ +{ + "name": "my-snippets", + "engines": { + "vscode": "^1.11.0" + }, + "contributes": { + "snippets": [ + { + "language": [ + "lua" + ], + "path": "./lua.json" + }, + { + "language": [ + "javascriptreact", + "typescriptreact" + ], + "path": "./javascriptreact.json" + }, + { + "language": [ + "typescriptreact" + ], + "path": "./typescriptreact.json" + } + ] + } +} diff --git a/.config/nvim/snippets/typescriptreact.json b/.config/nvim/snippets/typescriptreact.json new file mode 100644 index 0000000..8ff3d7d --- /dev/null +++ b/.config/nvim/snippets/typescriptreact.json @@ -0,0 +1,91 @@ +{ + "typescriptReactFunctionalComponent": { + "prefix": "tfc", + "body": [ + "import { FunctionComponent } from 'react'", + "", + "type ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}Props = {}", + "", + "const ${1}:FunctionComponent<${1}Props> = ({$2}) => {", + " return (", + "
$0
", + " )", + "}", + "", + "export default ${1}" + ], + "description": "Creates a React Functional Component with TypeScript interface" + }, + "typescriptReactFunctionalLayoutComponent": { + "prefix": "tlc", + "body": [ + "import { FunctionComponent, ReactNode } from 'react'", + "", + "type ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}LayoutProps = {\n\tchildren: ReactNode\n}", + "", + "const ${1}Layout:FunctionComponent<${1}LayoutProps> = ({children}) => {", + " return (", + "
$0", + " \t{children}", + "
", + " )", + "}", + "", + "export default ${1}Layout" + ], + "description": "Creates a React Layout Functional Component with TypeScript interface" + }, + "typescriptReactClientComponent": { + "prefix": "tnc", + "body": [ + "\"use client\";", + "", + "import { FunctionComponent } from 'react'", + "", + "type ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}Props = {}", + "", + "const ${1}:FunctionComponent<${1}Props> = ({$2}) => {", + " return (", + "
$0
", + " )", + "}", + "", + "export default ${1}" + ], + "description": "Creates a React Client Component with TypeScript interface" + }, + "typescriptReactNativeFC": { + "prefix": "tnf", + "body": [ + "import { FunctionComponent } from 'react'", + "import { View } from 'react-native';", + "", + "type ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}Props = {}", + "", + "const ${1}: FunctionComponent<${1}Props> = () => {", + " return $0", + "}", + "", + "export default ${1};" + ], + "description": "Create React Native Functional Component" + }, + "typescriptReactNativeFCWithStyles": { + "prefix": "tnfs", + "body": [ + "import { FunctionComponent } from 'react'", + "import { View, StyleSheet } from 'react-native';", + "", + "type ${1:${TM_FILENAME_BASE/(?:^|[-_])(\\w)/${1:/upcase}/g}}Props = {}", + "", + "const ${1}: FunctionComponent<${1}Props> = () => {", + " return $0", + "}", + "", + "const styles = StyleSheet.create({$2})", + "", + "export default ${1};" + ], + "description": "Create React Native Functional Component(with styles)" + } +} diff --git a/.gitignore b/.gitignore index 375c69c..8cac54a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .config/tmux/plugins .config/nvim/plugin/packer_compiled.* -.config/nvim/snippets/ .config/nvim/spell/ .config/nvim/tmp_dirs/ .local/share/nvim/* diff --git a/.ignore b/.ignore index 9a0b94d..56fff83 100644 --- a/.ignore +++ b/.ignore @@ -1,6 +1,5 @@ .config/tmux/plugins .config/nvim/plugin/packer_compiled.* -.config/nvim/snippets/ .config/nvim/spell/ .config/nvim/tmp_dirs/ .local/share/nvim/*