diff --git a/lua/user/cmp.lua b/lua/user/cmp.lua new file mode 100644 index 00000000..2da236c4 --- /dev/null +++ b/lua/user/cmp.lua @@ -0,0 +1,131 @@ +local cmp_status_ok, cmp = pcall(require, "cmp") +if not cmp_status_ok then + return +end + +local snip_status_ok, luasnip = pcall(require, "luasnip") +if not snip_status_ok then + return +end + +require("luasnip/loaders/from_vscode").lazy_load() + +local check_backspace = function() + local col = vim.fn.col "." - 1 + return col == 0 or vim.fn.getline("."):sub(col, col):match "%s" +end + +--   פּ ﯟ   some other good icons +local kind_icons = { + Text = "", + Method = "m", + Function = "", + Constructor = "", + Field = "", + Variable = "", + Class = "", + Interface = "", + Module = "", + Property = "", + Unit = "", + Value = "", + Enum = "", + Keyword = "", + Snippet = "", + Color = "", + File = "", + Reference = "", + Folder = "", + EnumMember = "", + Constant = "", + Struct = "", + Event = "", + Operator = "", + TypeParameter = "", +} +-- find more here: https://www.nerdfonts.com/cheat-sheet + +cmp.setup { + snippet = { + expand = function(args) + luasnip.lsp_expand(args.body) -- For `luasnip` users. + end, + }, + mapping = { + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(1), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `` mapping. + [""] = cmp.mapping { + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }, + -- Accept currently selected item. If none selected, `select` first item. + -- Set `select` to `false` to only confirm explicitly selected items. + [""] = cmp.mapping.confirm { select = true }, + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expandable() then + luasnip.expand() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif check_backspace() then + fallback() + else + fallback() + end + end, { + "i", + "s", + }), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_prev_item() + elseif luasnip.jumpable(-1) then + luasnip.jump(-1) + else + fallback() + end + end, { + "i", + "s", + }), + }, + formatting = { + fields = { "kind", "abbr", "menu" }, + format = function(entry, vim_item) + -- Kind icons + vim_item.kind = string.format("%s", kind_icons[vim_item.kind]) + -- vim_item.kind = string.format('%s %s', kind_icons[vim_item.kind], vim_item.kind) -- This concatonates the icons with the name of the item kind + vim_item.menu = ({ + nvim_lsp = "[LSP]", + nvim_lua = "[NVIM_LUA]", + luasnip = "[Snippet]", + buffer = "[Buffer]", + path = "[Path]", + })[entry.source.name] + return vim_item + end, + }, + sources = { + { name = "nvim_lsp" }, + { name = "nvim_lua" }, + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + }, + confirm_opts = { + behavior = cmp.ConfirmBehavior.Replace, + select = false, + }, + window = { + documentation = cmp.config.window.bordered() + }, + experimental = { + ghost_text = false, + native_menu = false, + }, +} diff --git a/lua/user/colorscheme.lua b/lua/user/colorscheme.lua new file mode 100644 index 00000000..e180a953 --- /dev/null +++ b/lua/user/colorscheme.lua @@ -0,0 +1,7 @@ +local colorscheme = 'default' + +local status_ok, _ = pcall(vim.cmd, 'colorscheme ' .. colorscheme) +if not status_ok then + vim.notify('colorscheme ' .. colorscheme .. ' not found!') + return +end diff --git a/lua/user/keymaps.lua b/lua/user/keymaps.lua new file mode 100644 index 00000000..ec910283 --- /dev/null +++ b/lua/user/keymaps.lua @@ -0,0 +1,108 @@ +local opts = { noremap = true, silent = true } + +local term_opts = { silent = true } + +-- Shorten function name +local keymap = vim.api.nvim_set_keymap + +--Remap space as leader key +keymap('', '', '', opts) +vim.g.mapleader = ' ' +vim.g.maplocalleader = ' ' + +-- Modes +-- normal_mode = "n", +-- insert_mode = "i", +-- visual_mode = "v", +-- visual_block_mode = "x", +-- term_mode = "t", +-- command_mode = "c", + +-- Normal -- +-- Better window navigation +keymap('n', '', 'h', opts) +keymap('n', '', 'j', opts) +keymap('n', '', 'k', opts) +keymap('n', '', 'l', opts) + +keymap('n', 'e', ':Lex 30', opts) -- hit again to close + +-- Resize with arrows +keymap('n', '', ':resize +2', opts) +keymap('n', '', ':resize -2', opts) +keymap('n', '', ':vertical resize -2', opts) +keymap('n', '', ':vertical resize +2', opts) + +-- Navigate buffers +keymap('n', '', ':bnext', opts) +keymap('n', '', ':bprevious', opts) + +-- Insert -- +-- Press jk fast to enter +keymap('i', 'jk', '', opts) + +-- Visual -- +-- Stay in indent mode +keymap('v', '<', '', '>gv', opts) + +-- Move text up and down +keymap('v', '', ':m .+1==', opts) +keymap('v', '', ':m .-2==', opts) +keymap('v', 'p', '"_dP', opts) + +-- Visual Block -- +-- Move text up and down +keymap('x', 'J', ":move '>+1gv-gv", opts) +keymap('x', 'K', ":move '<-2gv-gv", opts) +keymap('x', '', ":move '>+1gv-gv", opts) +keymap('x', '', ":move '<-2gv-gv", opts) + +-- Terminal -- +-- Better terminal navigation +keymap('t', '', 'h', term_opts) +keymap('t', '', 'j', term_opts) +keymap('t', '', 'k', term_opts) +keymap('t', '', 'l', term_opts) + + +-- keymap("n", "f", "Telescope find_files", opts) +keymap("n", "f", "lua require'telescope.builtin'.find_files(require('telescope.themes').get_dropdown({ previewer = false }))", opts) +keymap("n", "", "Telescope live_grep", opts) +-- +-- See `:help telescope.builtin` +local builtin = require 'telescope.builtin' +vim.keymap.set('n', 'sh', builtin.help_tags, { desc = '[S]earch [H]elp' }) +vim.keymap.set('n', 'sk', builtin.keymaps, { desc = '[S]earch [K]eymaps' }) +vim.keymap.set('n', 'sf', builtin.find_files, { desc = '[S]earch [F]iles' }) +vim.keymap.set('n', 'ss', builtin.builtin, { desc = '[S]earch [S]elect Telescope' }) +vim.keymap.set('n', 'sw', builtin.grep_string, { desc = '[S]earch current [W]ord' }) +vim.keymap.set('n', 'sg', builtin.live_grep, { desc = '[S]earch by [G]rep' }) +vim.keymap.set('n', 'sd', builtin.diagnostics, { desc = '[S]earch [D]iagnostics' }) +vim.keymap.set('n', 'sr', builtin.resume, { desc = '[S]earch [R]esume' }) +vim.keymap.set('n', 's.', builtin.oldfiles, { desc = '[S]earch Recent Files ("." for repeat)' }) +vim.keymap.set('n', '', builtin.buffers, { desc = '[ ] Find existing buffers' }) + +-- Slightly advanced example of overriding default behavior and theme +vim.keymap.set('n', '/', function() + -- You can pass additional configuration to Telescope to change the theme, layout, etc. + builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { + winblend = 10, + previewer = false, + }) +end, { desc = '[/] Fuzzily search in current buffer' }) + +-- It's also possible to pass additional configuration options. +-- See `:help telescope.builtin.live_grep()` for information about particular keys +-- vim.keymap.set('n', 's/', function() +-- builtin.live_grep { +-- grep_open_files = true, +-- prompt_title = 'Live Grep in Open Files', +-- } +-- end, { desc = '[S]earch [/] in Open Files' }) + +-- Shortcut for searching your Neovim configuration files +vim.keymap.set('n', 'sn', function() + builtin.find_files { cwd = vim.fn.stdpath 'config' } +end, { desc = '[S]earch [N]eovim files' }) + diff --git a/lua/user/lsp/handlers.lua b/lua/user/lsp/handlers.lua new file mode 100644 index 00000000..b540d09b --- /dev/null +++ b/lua/user/lsp/handlers.lua @@ -0,0 +1,91 @@ +local M = {} + +local status_cmp_ok, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp") +if not status_cmp_ok then + return +end + +M.capabilities = vim.lsp.protocol.make_client_capabilities() +M.capabilities.textDocument.completion.completionItem.snippetSupport = true +M.capabilities = cmp_nvim_lsp.default_capabilities(M.capabilities) + +M.setup = function() + local signs = { + + { name = "DiagnosticSignError", text = "" }, + { name = "DiagnosticSignWarn", text = "" }, + { name = "DiagnosticSignHint", text = "" }, + { name = "DiagnosticSignInfo", text = "" }, + } + + for _, sign in ipairs(signs) do + vim.fn.sign_define(sign.name, { texthl = sign.name, text = sign.text, numhl = "" }) + end + + local config = { + virtual_text = false, -- disable virtual text + signs = { + active = signs, -- show signs + }, + update_in_insert = true, + underline = true, + severity_sort = true, + float = { + focusable = true, + style = "minimal", + border = "rounded", + source = "always", + header = "", + prefix = "", + }, + } + + vim.diagnostic.config(config) + + vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { + border = "rounded", + }) + + vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { + border = "rounded", + }) +end + +local function lsp_keymaps(bufnr) + local opts = { noremap = true, silent = true } + local keymap = vim.api.nvim_buf_set_keymap + keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) + keymap(bufnr, "n", "gd", "lua vim.lsp.buf.definition()", opts) + keymap(bufnr, "n", "K", "lua vim.lsp.buf.hover()", opts) + keymap(bufnr, "n", "gI", "lua vim.lsp.buf.implementation()", opts) + keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) + keymap(bufnr, "n", "gl", "lua vim.diagnostic.open_float()", opts) + keymap(bufnr, "n", "lf", "lua vim.lsp.buf.format{ async = true }", opts) + keymap(bufnr, "n", "li", "LspInfo", opts) + keymap(bufnr, "n", "lI", "LspInstallInfo", opts) + keymap(bufnr, "n", "la", "lua vim.lsp.buf.code_action()", opts) + keymap(bufnr, "n", "lj", "lua vim.diagnostic.goto_next({buffer=0})", opts) + keymap(bufnr, "n", "lk", "lua vim.diagnostic.goto_prev({buffer=0})", opts) + keymap(bufnr, "n", "lr", "lua vim.lsp.buf.rename()", opts) + keymap(bufnr, "n", "ls", "lua vim.lsp.buf.signature_help()", opts) + keymap(bufnr, "n", "lq", "lua vim.diagnostic.setloclist()", opts) +end + +M.on_attach = function(client, bufnr) + if client.name == "tsserver" then + client.server_capabilities.documentFormattingProvider = false + end + + if client.name == "sumneko_lua" then + client.server_capabilities.documentFormattingProvider = false + end + + lsp_keymaps(bufnr) + local status_ok, illuminate = pcall(require, "illuminate") + if not status_ok then + return + end + illuminate.on_attach(client) +end + +return M diff --git a/lua/user/lsp/init.lua b/lua/user/lsp/init.lua new file mode 100644 index 00000000..0cc7120d --- /dev/null +++ b/lua/user/lsp/init.lua @@ -0,0 +1,9 @@ +local status_ok, _ = pcall(require, "lspconfig") +if not status_ok then + return +end + +require "user.lsp.mason" +require("user.lsp.handlers").setup() +require "user.lsp.null-ls" + diff --git a/lua/user/lsp/mason.lua b/lua/user/lsp/mason.lua new file mode 100644 index 00000000..6bdd03d5 --- /dev/null +++ b/lua/user/lsp/mason.lua @@ -0,0 +1,52 @@ +local servers = { + "lua_ls", + -- "cssls", + -- "html", + -- "tsserver", + "pyright", + -- "bashls", + "jsonls", + -- "yamlls", +} + +local settings = { + ui = { + border = "none", + icons = { + package_installed = "◍", + package_pending = "◍", + package_uninstalled = "◍", + }, + }, + log_level = vim.log.levels.INFO, + max_concurrent_installers = 4, +} + +require("mason").setup(settings) +require("mason-lspconfig").setup({ + ensure_installed = servers, + automatic_installation = true, +}) + +local lspconfig_status_ok, lspconfig = pcall(require, "lspconfig") +if not lspconfig_status_ok then + return +end + +local opts = {} + +for _, server in pairs(servers) do + opts = { + on_attach = require("user.lsp.handlers").on_attach, + capabilities = require("user.lsp.handlers").capabilities, + } + + server = vim.split(server, "@")[1] + + local require_ok, conf_opts = pcall(require, "user.lsp.settings." .. server) + if require_ok then + opts = vim.tbl_deep_extend("force", conf_opts, opts) + end + + lspconfig[server].setup(opts) +end diff --git a/lua/user/lsp/null-ls.lua b/lua/user/lsp/null-ls.lua new file mode 100644 index 00000000..874e19c5 --- /dev/null +++ b/lua/user/lsp/null-ls.lua @@ -0,0 +1,19 @@ +local null_ls_status_ok, null_ls = pcall(require, "null-ls") +if not null_ls_status_ok then + return +end + +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/formatting +local formatting = null_ls.builtins.formatting +-- https://github.com/jose-elias-alvarez/null-ls.nvim/tree/main/lua/null-ls/builtins/diagnostics +local diagnostics = null_ls.builtins.diagnostics + +null_ls.setup({ + debug = false, + sources = { + formatting.prettier.with({ extra_args = { "--no-semi", "--single-quote", "--jsx-single-quote" } }), + formatting.black.with({ extra_args = { "--fast" } }), + formatting.stylua, + -- diagnostics.flake8 + }, +}) diff --git a/lua/user/lsp/settings/jsonls.lua b/lua/user/lsp/settings/jsonls.lua new file mode 100644 index 00000000..e202e1e1 --- /dev/null +++ b/lua/user/lsp/settings/jsonls.lua @@ -0,0 +1,197 @@ +local default_schemas = nil +local status_ok, jsonls_settings = pcall(require, "nlspsettings.jsonls") +if status_ok then + default_schemas = jsonls_settings.get_default_schemas() +end + +local schemas = { + { + description = "TypeScript compiler configuration file", + fileMatch = { + "tsconfig.json", + "tsconfig.*.json", + }, + url = "https://json.schemastore.org/tsconfig.json", + }, + { + description = "Lerna config", + fileMatch = { "lerna.json" }, + url = "https://json.schemastore.org/lerna.json", + }, + { + description = "Babel configuration", + fileMatch = { + ".babelrc.json", + ".babelrc", + "babel.config.json", + }, + url = "https://json.schemastore.org/babelrc.json", + }, + { + description = "ESLint config", + fileMatch = { + ".eslintrc.json", + ".eslintrc", + }, + url = "https://json.schemastore.org/eslintrc.json", + }, + { + description = "Bucklescript config", + fileMatch = { "bsconfig.json" }, + url = "https://raw.githubusercontent.com/rescript-lang/rescript-compiler/8.2.0/docs/docson/build-schema.json", + }, + { + description = "Prettier config", + fileMatch = { + ".prettierrc", + ".prettierrc.json", + "prettier.config.json", + }, + url = "https://json.schemastore.org/prettierrc", + }, + { + description = "Vercel Now config", + fileMatch = { "now.json" }, + url = "https://json.schemastore.org/now", + }, + { + description = "Stylelint config", + fileMatch = { + ".stylelintrc", + ".stylelintrc.json", + "stylelint.config.json", + }, + url = "https://json.schemastore.org/stylelintrc", + }, + { + description = "A JSON schema for the ASP.NET LaunchSettings.json files", + fileMatch = { "launchsettings.json" }, + url = "https://json.schemastore.org/launchsettings.json", + }, + { + description = "Schema for CMake Presets", + fileMatch = { + "CMakePresets.json", + "CMakeUserPresets.json", + }, + url = "https://raw.githubusercontent.com/Kitware/CMake/master/Help/manual/presets/schema.json", + }, + { + description = "Configuration file as an alternative for configuring your repository in the settings page.", + fileMatch = { + ".codeclimate.json", + }, + url = "https://json.schemastore.org/codeclimate.json", + }, + { + description = "LLVM compilation database", + fileMatch = { + "compile_commands.json", + }, + url = "https://json.schemastore.org/compile-commands.json", + }, + { + description = "Config file for Command Task Runner", + fileMatch = { + "commands.json", + }, + url = "https://json.schemastore.org/commands.json", + }, + { + description = "AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.", + fileMatch = { + "*.cf.json", + "cloudformation.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/cloudformation.schema.json", + }, + { + description = "The AWS Serverless Application Model (AWS SAM, previously known as Project Flourish) extends AWS CloudFormation to provide a simplified way of defining the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application.", + fileMatch = { + "serverless.template", + "*.sam.json", + "sam.json", + }, + url = "https://raw.githubusercontent.com/awslabs/goformation/v5.2.9/schema/sam.schema.json", + }, + { + description = "Json schema for properties json file for a GitHub Workflow template", + fileMatch = { + ".github/workflow-templates/**.properties.json", + }, + url = "https://json.schemastore.org/github-workflow-template-properties.json", + }, + { + description = "golangci-lint configuration file", + fileMatch = { + ".golangci.toml", + ".golangci.json", + }, + url = "https://json.schemastore.org/golangci-lint.json", + }, + { + description = "JSON schema for the JSON Feed format", + fileMatch = { + "feed.json", + }, + url = "https://json.schemastore.org/feed.json", + versions = { + ["1"] = "https://json.schemastore.org/feed-1.json", + ["1.1"] = "https://json.schemastore.org/feed.json", + }, + }, + { + description = "Packer template JSON configuration", + fileMatch = { + "packer.json", + }, + url = "https://json.schemastore.org/packer.json", + }, + { + description = "NPM configuration file", + fileMatch = { + "package.json", + }, + url = "https://json.schemastore.org/package.json", + }, + { + description = "JSON schema for Visual Studio component configuration files", + fileMatch = { + "*.vsconfig", + }, + url = "https://json.schemastore.org/vsconfig.json", + }, + { + description = "Resume json", + fileMatch = { "resume.json" }, + url = "https://raw.githubusercontent.com/jsonresume/resume-schema/v1.0.0/schema.json", + }, +} + +local function extend(tab1, tab2) + for _, value in ipairs(tab2 or {}) do + table.insert(tab1, value) + end + return tab1 +end + +local extended_schemas = extend(schemas, default_schemas) + +local opts = { + settings = { + json = { + schemas = extended_schemas, + }, + }, + setup = { + commands = { + Format = { + function() + vim.lsp.buf.range_formatting({}, { 0, 0 }, { vim.fn.line "$", 0 }) + end, + }, + }, + }, +} + +return opts diff --git a/lua/user/lsp/settings/lua_ls.lua b/lua/user/lsp/settings/lua_ls.lua new file mode 100644 index 00000000..0ac454a7 --- /dev/null +++ b/lua/user/lsp/settings/lua_ls.lua @@ -0,0 +1,16 @@ +return { + settings = { + + Lua = { + diagnostics = { + globals = { "vim" }, + }, + workspace = { + library = { + [vim.fn.expand("$VIMRUNTIME/lua")] = true, + [vim.fn.stdpath("config") .. "/lua"] = true, + }, + }, + }, + }, +} diff --git a/lua/user/lsp/settings/pyright.lua b/lua/user/lsp/settings/pyright.lua new file mode 100644 index 00000000..c2a518db --- /dev/null +++ b/lua/user/lsp/settings/pyright.lua @@ -0,0 +1,9 @@ +return { + settings = { + python = { + analysis = { + typeCheckingMode = "off", + }, + }, + }, +} diff --git a/lua/user/options.lua b/lua/user/options.lua new file mode 100644 index 00000000..68636b6e --- /dev/null +++ b/lua/user/options.lua @@ -0,0 +1,46 @@ +local options = { + backup = false, -- creates a backup file + clipboard = 'unnamedplus', -- allows neovim to access the system clipboard + cmdheight = 2, -- more space in the neovim command line for displaying messages + completeopt = { 'menuone', 'noselect' }, -- mostly just for cmp + conceallevel = 0, -- so that `` is visible in markdown files + fileencoding = 'utf-8', -- the encoding written to a file + hlsearch = true, -- highlight all matches on previous search pattern + ignorecase = true, -- ignore case in search patterns + mouse = 'a', -- allow the mouse to be used in neovim + pumheight = 10, -- pop up menu height + showmode = false, -- we don't need to see things like -- INSERT -- anymore + showtabline = 2, -- always show tabs + smartcase = true, -- smart case + smartindent = true, -- make indenting smarter again + splitbelow = true, -- force all horizontal splits to go below current window + splitright = true, -- force all vertical splits to go to the right of current window + swapfile = false, -- creates a swapfile + termguicolors = true, -- set term gui colors (most terminals support this) + timeoutlen = 1000, -- time to wait for a mapped sequence to complete (in milliseconds) + undofile = true, -- enable persistent undo + updatetime = 300, -- faster completion (4000ms default) + writebackup = false, -- if a file is being edited by another program (or was written to file while editing with another program), it is not allowed to be edited + expandtab = true, -- convert tabs to spaces + shiftwidth = 2, -- the number of spaces inserted for each indentation + tabstop = 2, -- insert 2 spaces for a tab + cursorline = true, -- highlight the current line + number = true, -- set numbered lines + relativenumber = false, -- set relative numbered lines + numberwidth = 4, -- set number column width to 2 {default 4} + signcolumn = 'yes', -- always show the sign column, otherwise it would shift the text each time + wrap = false, -- display lines as one long line + scrolloff = 8, -- is one of my fav + sidescrolloff = 8, + guifont = 'monospace:h17', -- the font used in graphical neovim applications +} + +vim.opt.shortmess:append 'c' + +for k, v in pairs(options) do + vim.opt[k] = v +end + +vim.cmd 'set whichwrap+=<,>,[,],h,l' +vim.cmd [[set iskeyword+=-]] +vim.cmd [[set formatoptions-=cro]] -- TODO: this doesn't seem to work diff --git a/lua/user/plugins.lua b/lua/user/plugins.lua new file mode 100644 index 00000000..9bfec7cf --- /dev/null +++ b/lua/user/plugins.lua @@ -0,0 +1,81 @@ +local fn = vim.fn + +-- Automatically install packer +local install_path = fn.stdpath "data" .. "/site/pack/packer/start/packer.nvim" +if fn.empty(fn.glob(install_path)) > 0 then + PACKER_BOOTSTRAP = fn.system { + "git", + "clone", + "--depth", + "1", + "https://github.com/wbthomason/packer.nvim", + install_path, + } + print "Installing packer close and reopen Neovim..." + vim.cmd [[packadd packer.nvim]] +end + +-- Autocommand that reloads neovim whenever you save the plugins.lua file +vim.cmd [[ + augroup packer_user_config + autocmd! + autocmd BufWritePost plugins.lua source | PackerSync + augroup end +]] + +-- Use a protected call so we don't error out on first use +local status_ok, packer = pcall(require, "packer") +if not status_ok then + return +end + +-- Have packer use a popup window +packer.init { + display = { + open_fn = function() + return require("packer.util").float { border = "rounded" } + end, + }, +} + +-- Install your plugins here +return packer.startup(function(use) + -- My plugins here + use "wbthomason/packer.nvim" -- Have packer manage itself + use "nvim-lua/popup.nvim" -- An implementation of the Popup API from vim in Neovim + use "nvim-lua/plenary.nvim" -- Useful lua functions used ny lots of plugins + + -- Colorschemes + -- use "lunarvim/colorschemes" -- A bunch of colorschemes you can try out + use "lunarvim/darkplus.nvim" + + -- cmp plugins + use "hrsh7th/nvim-cmp" -- The completion plugin + use "hrsh7th/cmp-buffer" -- buffer completions + use "hrsh7th/cmp-path" -- path completions + use "hrsh7th/cmp-cmdline" -- cmdline completions + use "saadparwaiz1/cmp_luasnip" -- snippet completions + use "hrsh7th/cmp-nvim-lsp" + + -- snippets + use "L3MON4D3/LuaSnip" --snippet engine + use "rafamadriz/friendly-snippets" -- a bunch of snippets to use + + -- LSP + use "neovim/nvim-lspconfig" -- enable LSP + use "williamboman/mason.nvim" -- simple to use language server installer + use "williamboman/mason-lspconfig.nvim" -- simple to use language server installer + + -- Telescope + use { + 'nvim-telescope/telescope.nvim', + requires = { {'nvim-lua/plenary.nvim'} } + } + use "nvim-telescope/telescope-media-files.nvim" + + -- Automatically set up your configuration after cloning packer.nvim + -- Put this at the end after all plugins + if PACKER_BOOTSTRAP then + require("packer").sync() + end +end) diff --git a/lua/user/telescope.lua b/lua/user/telescope.lua new file mode 100644 index 00000000..e36adec8 --- /dev/null +++ b/lua/user/telescope.lua @@ -0,0 +1,136 @@ +local status_ok, telescope = pcall(require, "telescope") +if not status_ok then + return +end + +telescope.load_extension('media_files') + +local actions = require "telescope.actions" +local builtin = require 'telescope.builtin' + +-- -- Enable Telescope extensions if they are installed +-- pcall(require('telescope').load_extension, 'fzf') +-- pcall(require('telescope').load_extension, 'ui-select') +-- +-- +-- -- Slightly advanced example of overriding default behavior and theme +-- vim.keymap.set('n', '/', function() +-- -- You can pass additional configuration to Telescope to change the theme, layout, etc. +-- builtin.current_buffer_fuzzy_find(require('telescope.themes').get_dropdown { +-- winblend = 10, +-- previewer = false, +-- }) +-- end, { desc = '[/] Fuzzily search in current buffer' }) +-- +-- -- It's also possible to pass additional configuration options. +-- -- See `:help telescope.builtin.live_grep()` for information about particular keys +-- vim.keymap.set('n', 's/', function() +-- builtin.live_grep { +-- grep_open_files = true, +-- prompt_title = 'Live Grep in Open Files', +-- } +-- end, { desc = '[S]earch [/] in Open Files' }) +-- +-- -- Shortcut for searching your Neovim configuration files +-- vim.keymap.set('n', 'sn', function() +-- builtin.find_files { cwd = vim.fn.stdpath 'config' } +-- end, { desc = '[S]earch [N]eovim files' }) +-- end, +-- }, +-- + +telescope.setup { + defaults = { + + prompt_prefix = " ", + selection_caret = " ", + path_display = { "smart" }, + + mappings = { + i = { + [""] = actions.cycle_history_next, + [""] = actions.cycle_history_prev, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.close, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + [""] = actions.complete_tag, + [""] = actions.which_key, -- keys from pressing + }, + + n = { + [""] = actions.close, + [""] = actions.select_default, + [""] = actions.select_horizontal, + [""] = actions.select_vertical, + [""] = actions.select_tab, + + [""] = actions.toggle_selection + actions.move_selection_worse, + [""] = actions.toggle_selection + actions.move_selection_better, + [""] = actions.send_to_qflist + actions.open_qflist, + [""] = actions.send_selected_to_qflist + actions.open_qflist, + + ["j"] = actions.move_selection_next, + ["k"] = actions.move_selection_previous, + ["H"] = actions.move_to_top, + ["M"] = actions.move_to_middle, + ["L"] = actions.move_to_bottom, + + [""] = actions.move_selection_next, + [""] = actions.move_selection_previous, + ["gg"] = actions.move_to_top, + ["G"] = actions.move_to_bottom, + + [""] = actions.preview_scrolling_up, + [""] = actions.preview_scrolling_down, + + [""] = actions.results_scrolling_up, + [""] = actions.results_scrolling_down, + + ["?"] = actions.which_key, + + }, + }, + }, + pickers = { + -- Default configuration for builtin pickers goes here: + -- picker_name = { + -- picker_config_key = value, + -- ... + -- } + -- Now the picker_config_key will be applied every time you call this + -- builtin picker + planets = { + show_pluto = true, + }, + }, + extensions = { + media_files = { + -- filetypes whitelist + -- defaults to {"png", "jpg", "mp4", "webm", "pdf"} + filetypes = {"png", "webp", "jpg", "jpeg"}, + -- find command (defaults to `fd`) + find_cmd = "rg" + } + }, +}