Skip to content

Instantly share code, notes, and snippets.

@thugcee
Created August 12, 2021 07:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thugcee/8ce5721abc8b3ce7cfd3709248193bfa to your computer and use it in GitHub Desktop.
Save thugcee/8ce5721abc8b3ce7cfd3709248193bfa to your computer and use it in GitHub Desktop.
-- Plugins
require("packer").startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
-- Addon to Telescope to search key mappings
-- You have to use its custom function to define mappings
use {
"lazytanuki/nvim-mapper",
config = function()
require("nvim-mapper").setup {
search_path = (os.getenv("XDG_CONFIG_HOME") or os.getenv("HOME").."/.config").."/.config/nvim/lua"
}
end,
before = "telescope.nvim"
}
-- Use "gc" to comment visual regions/lines (lua version of tpope/vim-commentary)
use "b3nj5m1n/kommentary"
-- UI to select things (files, grep results, open buffers...)
use {"nvim-telescope/telescope.nvim",
requires = {{"nvim-lua/popup.nvim"}, {"nvim-lua/plenary.nvim"}},
config = function()
require("telescope").load_extension("mapper")
M = require("util-map")
M.map("n", "<leader>ff", "<cmd>Telescope find_files<CR>", {noremap = true}, "Telescope", "Telescope find_files", "Telescope find_files")
M.map("n", "<leader>fk", "<cmd>Telescope keymaps<CR>", {noremap = true}, "Telescope", "Telescope keymaps", "Telescope find_files")
M.map("n", "<leader>fg", "<cmd>Telescope live_grep<CR>", {noremap = true}, "Telescope", "Telescope live_grep", "Telescope live_grep")
M.map("n", "<leader>fb", "<cmd>Telescope buffers<CR>", {noremap = true}, "Telescope", "Telescope buffers", "Telescope buffers")
M.map("n", "<leader>fh", "<cmd>Telescope help_tags<CR>", {noremap = true}, "Telescope", "Telescope help_tags", "Telescope help_tags")
M.map("n", "<leader>fc", "<cmd>Telescope command_history<CR>", {noremap = true}, "Telescope", "Telescope command_history", "Telescope command_history")
M.map("n", "<leader>fr", "<cmd>Telescope oldfiles<CR>", {noremap = true}, "Telescope", "Telescope oldfiles", "Telescope oldfiles")
end
}
-- New Lua autocompletion
use {
"hrsh7th/nvim-compe",
config = function()
require("compe").setup {enabled = true, autocomplete = true, debug = false, min_length = 1, preselect = "disable",
throttle_time = 80, source_timeout = 200, resolve_timeout = 800, incomplete_delay = 400, max_abbr_width = 100,
max_kind_width = 100, max_menu_width = 100,
source = {path = true, buffer = true, calc = true, nvim_lsp = true, nvim_lua = true, vsnip = false, ultisnips = false,
luasnip = false}}
vim.o.completeopt = "menuone,noselect"
local M = require("util-map")
M.map("i", "<C-Space>", "compe#complete()", {silent = true, expr = true, noremap = true}, "Completion", "compe open completion", "Open completion menu by nvim-compe")
-- M.map('i', "<CR>", "compe#confirm('<CR>')", {silent=true, expr=true, noremap=true}, "Completion", "compe confirm completion", "Confirm completion in nvim-compe")
M.map("i", "<C-g>", "compe#close()", {silent = true, expr = true, noremap = true}, "Completion", "compe close completion g", "Close completion menu by nvim-compe")
M.map("i", "<C-y>", "compe#close()..'<C-y>'", {silent = true, expr = true, noremap = true}, "Completion", "compe close completion y", "Close completion menu by nvim-compe")
end
}
-- Autopairs
use {
"windwp/nvim-autopairs",
config = function()
require("nvim-autopairs").setup()
-- some compatibility fix for compe and autopairs
-- it was working without this, but documentation says it should be added
-- compe says this fix should be done other way
require("nvim-autopairs.completion.compe").setup {
mp_cr = true, -- mp <CR> on insert mode
map_complete = true -- it will auto insert parenthesis after select function or method item
}
end
}
-- Heurystyczne wykrywanie jakie mają być wcięcia w plikach
use "tpope/vim-sleuth"
-- OFF: replaced by treesitter selection expand
-- allows you to visually select increasingly larger regions of text using the same key combination
-- Press + to expand the visual selection and _ to shrink it.
-- use 'terryma/vim-expand-region'
-- Treesitter parsers and tools
use {"nvim-treesitter/nvim-treesitter",
branch = "0.5-compat",
run = ":TSUpdate",
config = function()
require"nvim-treesitter.configs".setup {
ensure_installed = "maintained", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
ignore_install = {}, -- List of parsers to ignore installing
highlight = {
enable = true, -- false will disable the whole extension
disable = {}, -- list of language that will be disabled
-- Setting this to true will run `:h syntax` and tree-sitter at the same time.
-- Set this to `true` if you depend on 'syntax' being enabled (like for indentation).
-- Using this option may slow down your editor, and you may see some duplicate highlights.
-- Instead of true it can also be a list of languages
additional_vim_regex_highlighting = false
},
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<leader>v",
node_incremental = "=",
node_decremental = "-",
scope_incremental = "+"}
},
indent = {enable = true}
}
local M = require("util-map")
M.map_buf_virtual("n", "<leader>v", ":lua require'nvim-treesitter.incremental_selection'.init_selection()<CR>",
{noremap = true}, "Selection", "ts selection start", "Start selecting using Tree-Sitter.")
M.map_buf_virtual("x", "=", ":lua require'nvim-treesitter.incremental_selection'.node_incremental()<CR>",
{noremap = true}, "Selection", "ts node extend selection", "Use Tree-Sitter to extend selection by node.")
M.map_buf_virtual("x", "-", ":lua require'nvim-treesitter.incremental_selection'.node_decremental()<CR>",
{noremap = true}, "Selection", "ts node shrink selection", "Use Tree-Sitter to shrink selection by node.")
M.map("v", "<Bar>", "=", { noremap = true, }, "Edit", "v-Bar--1628286091", "Indent selected text")
end
}
-- Zamiast vim-surround
-- == Add
-- Press sa{motion/textobject}{addition}. For example, a key sequence saiw[ makes foo to [foo].
-- == Delete
-- Press sdb or sd{deletion}. For example, key sequences sdb or sd[ makes [foo]
-- to foo. sdb searches a set of surrounding automatically.
-- == Replace
-- Press srb{addition} or sr{deletion}{addition}. For example, key sequences
-- srb" or sr[" makes (foo) to "foo".
use "machakann/vim-sandwich"
-- Vim plugin that defines a new text object representing lines of code at the same indent level.
-- Key bindings Description
-- <count>ai An Indentation level and line above.
-- <count>ii Inner Indentation level (no line above).
-- <count>aI An Indentation level and lines above/below.
-- <count>iI Inner Indentation level (no lines above/below).
use "michaeljsmith/vim-indent-object"
-- Vim plugin that provides additional text objects
-- i( i) i{ i} iB i[ i] ir i< i> ia it
-- a( a) a{ a} aB a[ a] ar a< a> aa at
-- I( I) I{ I} IB I[ I] Ir I< I> Ia It
-- A( A) A{ A} AB A[ A] Ar A< A> Aa At
--
-- in( in) in{ in} inB in[ in] inr in< in> ina int
-- an( an) an{ an} anB an[ an] anr an< an> ana ant
-- In( In) In{ In} InB In[ In] Inr In< In> Ina Int
-- An( An) An{ An} AnB An[ An] Anr An< An> Ana Ant
--
-- il( il) il{ il} ilB il[ il] ilr il< il> ila ilt
-- al( al) al{ al} alB al[ al] alr al< al> ala alt
-- Il( Il) Il{ Il} IlB Il[ Il] Ilr Il< Il> Ila Ilt
-- Al( Al) Al{ Al} AlB Al[ Al] Alr Al< Al> Ala Alt
use "wellle/targets.vim"
-- Flash yanked text
use "machakann/vim-highlightedyank"
-- Syntax support for TOML file format
use {
"cespare/vim-toml",
ft = "toml"
}
-- A neovim statusline plugin
use {"hoob3rt/lualine.nvim", requires = {"kyazdani42/nvim-web-devicons", opt = true}, config = function()
require("lualine").setup()
end}
-- A pretty file tree on the side
use {"kyazdani42/nvim-tree.lua", requires = {"kyazdani42/nvim-web-devicons", opt = true}, config = function()
local M = require("util-map")
M.map("n", "<leader>ft", ":NvimTreeToggle<CR>", {silent = true, noremap = true}, "Navigation", "nvim-tree-open",
"Open nvim-tree")
end}
-- Better syntax for python
use {
"vim-python/python-syntax",
ft = {"python"},
config = function()
vim.g.python_highlight_all = 1
end
}
-- Python indent (follows the PEP8 style)
use {"Vimjas/vim-python-pep8-indent", ft = {"python"}}
-- Python-related text object
use {"jeetsukumaran/vim-pythonsense", ft = {"python"}}
-- LSP: Configurer of Neovim's LSP clients
use {
"neovim/nvim-lspconfig",
ft = {"python", "bash", "sh", "lua", "typescriptreact"},
config = function()
vim.lsp.set_log_level "trace"
local nvim_lsp = require("lspconfig")
require("lspconfig").pyright.setup {autostart = false}
require("lspconfig").bashls.setup {autostart = false}
require("lspconfig").tsserver.setup {}
-- require("lspconfig")["null-ls"].setup({})
-- Use an on_attach func to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(_, bufnr)
local function buf_set_keymap(...)
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
local function buf_set_option(...)
vim.api.nvim_buf_set_option(bufnr, ...)
end
-- Enable completion triggered by <c-x><c-o>
buf_set_option("omnifunc", "v:lua.vim.lsp.omnifunc")
-- Mappings.
local opts = {noremap = true, silent = true}
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap("n", "gD", "<cmd>lua vim.lsp.buf.declaration()<CR>", opts)
buf_set_keymap("n", "gd", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts)
buf_set_keymap("n", "<leader>ls", "<cmd>lua vim.lsp.buf.signature_help()<CR>", opts)
buf_set_keymap("n", "<leader>wa", "<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<leader>wr", "<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>", opts)
buf_set_keymap("n", "<leader>wl", "<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>", opts)
buf_set_keymap("n", "<leader>D", "<cmd>lua vim.lsp.buf.type_definition()<CR>", opts)
buf_set_keymap("n", "<leader>rn", "<cmd>lua vim.lsp.buf.rename()<CR>", opts)
buf_set_keymap("n", "<leader>ca", "<cmd>lua vim.lsp.buf.code_action()<CR>", opts)
-- buf_set_keymap("n", "gr", "<cmd>lua vim.lsp.buf.references()<CR>", opts)
buf_set_keymap("n", "<leader>le", "<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>", opts)
buf_set_keymap("n", "<leader>l[", "<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>", opts)
buf_set_keymap("n", "<leader>l]", "<cmd>lua vim.lsp.diagnostic.goto_next()<CR>", opts)
buf_set_keymap("n", "<leader>ld", "<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>", opts)
buf_set_keymap("n", "<leader>li", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end
-- Generic setup for some LSPs
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = {"pyright", "bashls", "tsserver"}
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {on_attach = on_attach, flags = {debounce_text_changes = 150}}
end
-- Setup Lua LSP
local sumneko_root_path = "/home/ser/data/software/src/lua-language-server"
local sumneko_binary = sumneko_root_path .. "/bin/Linux/lua-language-server"
local runtime_path = vim.split(package.path, ";")
table.insert(runtime_path, "lua/?.lua")
table.insert(runtime_path, "lua/?/init.lua")
require"lspconfig".sumneko_lua.setup {
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
on_attach = on_attach,
settings = {
Lua = {
runtime = { -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT", -- Setup your lua path
path = runtime_path },
diagnostics = { -- Get the language server to recognize the `vim` global
globals = {"vim"}},
workspace = { -- Make the server aware of Neovim runtime files
library = vim.api.nvim_get_runtime_file("", true)},
-- Do not send telemetry data containing a randomized but unique identifier
telemetry = {enable = false}
}
}
}
end
}
-- LSP: Extra UI for LSP
use {
"glepnir/lspsaga.nvim",
ft = {"python", "bash", "sh", "lua", "typescriptreact"},
config = function()
local M = require("util-map")
local opts = { noremap = true, silent = true, }
M.map("n", "<localleader>lp", "<cmd>lua require'lspsaga.provider'.preview_definition()<CR>", opts, "LSP", "ngs-cmd-lua-require--lspsaga-preview-definiotion", "LSP Saga Preview Definition")
M.map("n", "<localleader>ls", "<cmd>lua require('lspsaga.signaturehelp').signature_help()<CR>", opts, "LSP", "ngs-cmd-lua-require--lspsaga-signaturehelp---signature-help---CR-1628281325", "cmdluarequirelspsagasignaturehelpsignaturehelpCR")
M.map("n", "<localleader>lf", "<cmd>lua require'lspsaga.provider'.lsp_finder()<CR>", opts, "LSP", "ngh-cmd-lua-require-lspsaga-provider--lsp-finder---CR-1628285177", "cmdluarequirelspsagaproviderlspfinderCR")
M.map("n", "gr", "<cmd>lua require'lspsaga.provider'.lsp_finder()<CR>", opts, "LSP", "ngh-cmd-lua-require-lspsaga-provider--lsp-finder---CR-1628285177", "cmdluarequirelspsagaproviderlspfinderCR")
M.map("n", "<localleader>la", "<cmd>lua require('lspsaga.codeaction').code_action()<CR>", opts, "LSP", "n-leader-ca-cmd-lua-require--lspsaga-codeaction---code-action---CR-1628280886", "LSP Saga Code Action")
M.map("v", "<localleader>la", ":<C-U>lua require('lspsaga.codeaction').range_code_action()<CR>", opts, "LSP", "v-leader-ca--C-U-lua-require--lspsaga-codeaction---range-code-action---CR-1628280951", "LSP Saga Code Action")
M.map("n", "<localleader>k", "<cmd>lua require('lspsaga.hover').render_hover_doc()<CR>", opts, "LSP", "nK-cmd-lua-require--lspsaga-hover---render-hover-doc---CR-1628281179", "lspsaga: show definition")
M.map("n", "<localleader>lr", "<cmd>lua require('lspsaga.rename').rename()<CR>", opts, "LSP", "ngr-cmd-lua-require--lspsaga-rename---rename---CR-1628281448", "lspsaga: rename")
end
}
-- LSP: A pretty diagnostics, references, telescope results, quickfix and location list
-- to help you solve all the trouble your code is causing.
use {
"folke/trouble.nvim",
ft = {"python", "bash", "sh", "lua", "typescriptreact"},
requires = "kyazdani42/nvim-web-devicons",
config = function()
require("trouble").setup { }
M.map("n", "gR", "<cmd>TroubleToggle lsp_references<cr>", { noremap = true, }, "Misc", "ngR-cmd-TroubleToggle-lsp-references-cr-1628289017", "cmdTroubleTogglelspreferencescr")
end
}
-- LSP with many utility functgions and integrations
--[[ use {
"jose-elias-alvarez/null-ls.nvim",
ft = {"python", "bash", "sh", "lua", "typescriptreact"},
requires = {"nvim-lua/plenary.nvim", "neovim/nvim-lspconfig"},
config = function()
require("null-ls").config({
diagnostics_format = "[#{c}] #{m} (#{s})",
save_after_format = false,
sources = { require("null-ls").builtins.formatting.stylua },
debug = true,
})
end,
} ]]
-- Stay after pressing * and search selected text
use "haya14busa/vim-asterisk"
-- Session management plugin
use "tpope/vim-obsession"
-- WhichKey is a lua plugin for Neovim 0.5 that displays a popup with possible keybindings of the command you started typing.
use {"folke/which-key.nvim",
config = function()
require("which-key").setup {
plugins = {
spelling = {
enabled = true
}
},
show_help = true,
layout = {
height = { min = 6, max = 25 }, -- min and max height of the columns
width = { min = 20, max = 150 }, -- min and max width of the columns
spacing = 3, -- spacing between columns
align = "left", -- align columns left, center or right
},
}
end
}
-- Another buffer line
use {
"akinsho/nvim-bufferline.lua",
requires = "kyazdani42/nvim-web-devicons",
config = function()
vim.opt.termguicolors = true
require("bufferline").setup {
options = {
numbers = "buffer_id",
number_style = "superscript", -- buffer_id at index 1, ordinal at index 2
mappings = false,
close_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
right_mouse_command = "bdelete! %d", -- can be a string | function, see "Mouse actions"
left_mouse_command = "buffer %d", -- can be a string | function, see "Mouse actions"
middle_mouse_command = nil, -- can be a string | function, see "Mouse actions"
-- NOTE: this plugin is designed with this icon in mind,
-- and so changing this is NOT recommended, this is intended
-- as an escape hatch for people who cannot bear it for whatever reason
indicator_icon = "▎",
buffer_close_icon = "x",
modified_icon = "●",
close_icon = "",
left_trunc_marker = "",
right_trunc_marker = "",
max_name_length = 18,
max_prefix_length = 15, -- prefix used when a buffer is de-duplicated
tab_size = 18, diagnostics = false, offsets = {{filetype = "NvimTree", text = "File Explorer", text_align = "left"}},
show_buffer_icons = true, -- disable filetype icons for buffers
show_buffer_close_icons = false, show_close_icon = false, show_tab_indicators = true, persist_buffer_sort = true, -- whether or not custom sorted buffers should persist
-- can also be a table containing 2 custom separators
-- [focused and unfocused]. eg: { '|', '|' }
separator_style = "thin", always_show_bufferline = false, sort_by = "id"}}
local M = require("util-map")
M.map("n", "<leader>b", "<cmd>BufferLinePick<CR>", { noremap = true, }, "Misc", "n-leader-b-BufferLinePick1528288479", "BufferLinePick")
end
}
-- Text replacer
use {
"svermeulen/vim-subversive",
config = function ()
-- Map 'S' for substitute
local M = require("util-map")
M.map("n", "S", "<plug>(SubversiveSubstitute)", {}, "Edit", "SubversiveSubstitute", "Substitute a text object with a register")
M.map("n", "SS", "<plug>(SubversiveSubstituteLine)", {}, "Edit", "SubversiveSubstituteLine", "Substitute a line with a register")
M.map("n", "<leader>S", "<plug>(SubversiveSubstituteRange)", {}, "Edit", "SubversiveSubstituteRange")
M.map("x", "<leader>S", "<plug>(SubversiveSubstituteRange)", {}, "Edit", "SubversiveSubstituteRange2")
M.map("n", "<leader>SS", "<plug>(SubversiveSubstituteWordRange)", {}, "Edit", "SubversiveSubstituteWordRange")
end
}
-- Use <leader>p[pn] to rotate registers content in pasted text
use {
"svermeulen/vim-yoink",
config = function ()
local M = require("util-map")
M.map("n", "<leader>pp", "<plug>(YoinkPostPasteSwapBack)", { },
"Edit", "n-c-n--plug--YoinkPostPasteSwapBack-1628251036", "Yoink: Cycle paste next")
M.map("n", "<leader>pn", "<plug>(YoinkPostPasteSwapForward)", { },
"Edit", "n-c-p--plug--YoinkPostPasteSwapForward-1628251116", "Yoink: Cycle paste prev")
M.map("n", "p", "<plug>(YoinkPaste_p)", { }, "Misc", "np-plug--YoinkPaste-p-1628251156", "plugYoinkPastep")
M.map("n", "P", "<plug>(YoinkPaste_P)", { }, "Misc", "nP-plug--YoinkPaste-P-1628251165", "plugYoinkPasteP")
end
}
-- Cycle text within predefined candidates.
-- by default mapped to <leader>a
--[[ use {
"bootleq/vim-cycle",
config = function()
M.map_virtual("n", "<leader>a", "<Plug>CycleNext", { }, "Misc", "n-leader-a-Plug-CycleNext1628251783", "PlugCycleNext")
end
} ]]
-- Use '<C-n>' to select multiple cursors
use "terryma/vim-multiple-cursors"
-- Lua REPL
use {
"bfredl/nvim-luadev",
cmd = "Luadev",
config = function()
vim.cmd [[:nmap <C-Enter> <Plug>(Luadev-RunLine) ]]
end
}
-- my plugin to convert vim map command to nvim lua function
use {
"~/lab/progr/nvim-map-to-lua",
ft = "lua",
config = function ()
require("map-to-lua").setup {
default_formatter = "mapper"
}
local M = require("util-map")
M.map("n", "<leader>cm", '<cmd>lua require("map-to-lua").convert_line()<cr>', { }, "Misc", "-C-m--cmd-lua-require--nvim-map-to-lua-map-to-lua---convert-line---cr--1628254156", "cmdluarequirenvimmaptoluamaptoluaconvertlinecr")
end
}
end)
-- Code copied from https://github.com/lazytanuki/nvim-mapper
-- It defines functions to create searchable keys maps (which have
-- descriptions) with fallback to neovim native functions in case when
-- nvim-mapper is not present.
local M = {}
local function is_module_available(name)
if package.loaded[name] then
return true
else
for _, searcher in ipairs(package.searchers or package.loaders) do
local loader = searcher(name)
if type(loader) == 'function' then
package.preload[name] = loader
return true
end
end
return false
end
end
local wk = require("which-key")
if is_module_available("nvim-mapper") then
local mapper = require("nvim-mapper")
M.map = function(mode, keys, cmd, options, category, unique_identifier, description)
wk.register({ [keys] = { description } }, { mode = mode })
mapper.map(mode, keys, cmd, options, category, unique_identifier, description)
end
M.map_buf = function(bufnr, mode, keys, cmd, options, category, unique_identifier, description)
wk.register({ [keys] = { description } }, { mode = mode })
mapper.map_buf(bufnr, mode, keys, cmd, options, category, unique_identifier, description)
end
M.map_virtual = function(mode, keys, cmd, options, category, unique_identifier, description)
wk.register({ [keys] = { description } }, { mode = mode })
mapper.map_virtual(mode, keys, cmd, options, category, unique_identifier, description)
end
M.map_buf_virtual = function(mode, keys, cmd, options, category, unique_identifier, description)
wk.register({ [keys] = { description } }, { mode = mode })
mapper.map_buf_virtual(mode, keys, cmd, options, category, unique_identifier, description)
end
else
M.map = function(mode, keys, cmd, options, _, _, description)
wk.register({ [keys] = { description } }, { mode = mode })
vim.api.nvim_set_keymap(mode, keys, cmd, options)
end
M.map_buf = function(mode, keys, cmd, options, _, _, description)
wk.register({ [keys] = { description } }, { mode = mode })
vim.api.nvim_buf_set_keymap(mode, keys, cmd, options)
end
M.map_virtual = function(mode, keys, _, _, _, _, description)
wk.register({ [keys] = { description } }, { mode = mode })
end
M.map_buf_virtual = function(mode, keys, _, _, _, _, description)
wk.register({ [keys] = { description } }, { mode = mode })
end
end
return M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment