From 6920fe2ca3b168f91ab1c72dc8a8c2f2146d48a1 Mon Sep 17 00:00:00 2001 From: Rokas Puzonas Date: Sat, 30 Oct 2021 14:30:55 +0300 Subject: [PATCH] feat: add telescope --- README.md | 8 +++++ lua/config/devicons.lua | 1 + lua/config/telescope.lua | 74 +++++++++++++++++++++++++++++++++++++++ lua/config/treesitter.lua | 6 ++++ lua/options.lua | 6 +++- lua/plugins.lua | 23 ++++++++++++ 6 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 README.md create mode 100644 lua/config/devicons.lua create mode 100644 lua/config/telescope.lua create mode 100644 lua/config/treesitter.lua diff --git a/README.md b/README.md new file mode 100644 index 0000000..1e93006 --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# Neovim Config + + +## Requirements +* ripgrep - for telescope +* [A patched font](https://www.nerdfonts.com/) - for dev icons + + diff --git a/lua/config/devicons.lua b/lua/config/devicons.lua new file mode 100644 index 0000000..74f601b --- /dev/null +++ b/lua/config/devicons.lua @@ -0,0 +1 @@ +require('nvim-web-devicons').setup() diff --git a/lua/config/telescope.lua b/lua/config/telescope.lua new file mode 100644 index 0000000..db8a3ff --- /dev/null +++ b/lua/config/telescope.lua @@ -0,0 +1,74 @@ +local telescope = require('telescope') +local map = require('utils.map') +local actions = require('telescope.actions') +local builtin = require('telescope.builtin') +local previewers = require('telescope.previewers') +local M = {} + +local function sizelimit_maker(filepath, bufnr, opts) + opts = opts or {} + local size_limit = 100 * 1024 -- 100KiB + + filepath = vim.fn.expand(filepath) + vim.loop.fs_stat(filepath, function(_, stat) + if not stat then return end + if stat.size > size_limit then + return + else + previewers.buffer_previewer_maker(filepath, bufnr, opts) + end + end) +end + +-- Falling back to find_files if git_files can't find a .git directory +function M.project_files(opts) + local ok = pcall(builtin.git_files, opts) + if not ok then builtin.find_files(opts) end +end + +function M.edit_config(opts) + return M.project_files{ + cwd = "~/.config/nvim", + prompt_title = "Neovim config" + } +end + +local silent = {silent = true} + +-- Search project files +map('n', '', [[:lua require('config.telescope').project_files()]], silent) + +-- Edit neovim config +map('n', 'ev', [[:lua require('config.telescope').edit_config()]], silent) + +-- Grep string +map('n', 'fg', [[:lua require('telescope.builtin').live_grep()]], silent) + +telescope.setup{ + defaults = { + buffer_previewer_maker = new_maker, + mappings = { + i = { + [""] = actions.close + } + } + }, + pickers = { + find_files = { + theme = "dropdown", + }, + git_files = { + theme = "dropdown", + }, + live_grep = { + theme = "dropdown", + } + } +} + +local fzfPlugin = packer_plugins["telescope-fzf-native.nvim"] +if fzfPlugin and fzfPlugin.loaded then + telescope.load_extension('fzf') +end + +return M diff --git a/lua/config/treesitter.lua b/lua/config/treesitter.lua new file mode 100644 index 0000000..7f2b457 --- /dev/null +++ b/lua/config/treesitter.lua @@ -0,0 +1,6 @@ +local treesitter = require("nvim-treesitter.configs") + +treesitter.setup{ + ensure_installed = "maintained", + highlight = { enable = true } +} diff --git a/lua/options.lua b/lua/options.lua index 4a9293e..4229058 100644 --- a/lua/options.lua +++ b/lua/options.lua @@ -9,6 +9,10 @@ cmd [[filetype plugin on]] local buffer = { o, bo } local window = { o, wo } +-- Pseudo transparent popup window +opt('pumblend', 15) +cmd [[highlight PmenuSel blend=0]] + -- Don't wrap text to next line if there isin't enough space opt('wrap', false) @@ -82,7 +86,7 @@ opt('clipboard', 'unnamedplus') -- Identation/Tab settings local tab_size = 2 -opt('foldmethod', 'indent', window) +opt('foldmethod', 'indent') opt('expandtab', false, buffer) opt('smartindent', true, buffer) opt('shiftwidth', tab_size, buffer) diff --git a/lua/plugins.lua b/lua/plugins.lua index 52c1dd9..a207883 100644 --- a/lua/plugins.lua +++ b/lua/plugins.lua @@ -9,6 +9,29 @@ local function usePlugins(use) -- Various lua utilities use 'nvim-lua/plenary.nvim' + -- Tree-sitter + use { + 'nvim-treesitter/nvim-treesitter', + config = [[require 'config.treesitter']], + run = ':TSUpdate' + } + + -- Emoji file icons + use { 'kyazdani42/nvim-web-devicons', config = [[require 'config.devicons']] } + + -- Fuzzy file finder + use { 'nvim-telescope/telescope-fzf-native.nvim', run = 'make' } + use { + 'nvim-telescope/telescope.nvim', + config = [[require 'config.telescope']], + requires = { + {'nvim-lua/plenary.nvim'}, + {'nvim-treesitter/nvim-treesitter'}, + {'kyazdani42/nvim-web-devicons', opt = true}, + {'nvim-telescope/telescope-fzf-native.nvim', opt = true} + } + } + -- Smooth smooth scrolling use 'psliwka/vim-smoothie'