Skip to content

Instantly share code, notes, and snippets.

@midir99
Last active July 5, 2023 18:29
Show Gist options
  • Save midir99/d70d446adb4df870aebe98e9f395a3fc to your computer and use it in GitHub Desktop.
Save midir99/d70d446adb4df870aebe98e9f395a3fc to your computer and use it in GitHub Desktop.
Set up Neovim the way I like it!
#!/usr/bin/env bash
cat <<"END"
You are about to set up Neovim using midir99's installation script, the following
plugins are included:
- bluz71/vim-nightfly-guicolors
Used for the color schemes.
- nvim-lua/plenary.nvim
It's a dependency of many Neovim plugins, specifically for
nvim-telescope/telescope.nvim.
- christoomey/vim-tmux-navigator
For an easier moving between splits experience.
- tpope/vim-commentary
Use it to comment code of different programming languages.
- kyazdani42/nvim-web-devicons
Some icons to enhance the UI.
- nvim-tree/nvim-tree.lua
A file explorer!
- nvim-lualine/lualine.nvim
A status line at the bottom of the window.
- nvim-telescope/telescope.nvim
You can use this one to find files or text easier!
- lewis6991/gitsigns.nvim
Signs for added, removed and changes lines.
- petertriho/nvim-scrollbar
Something like a minimap with Git signs.
- nvim-treesitter/nvim-treesitter
A parsing library other plugins require.
- hrsh7th/nvim-cmp, hrsh7th/cmp-buffer and hrsh7th/cmp-path
For basic autocompletion based on the text within the current buffer or
file system paths.
- L3MON4D3/LuaSnip, saadparwaiz1/cmp_luasnip and rafamadriz/friendly-snippets
Your snippet engine and various snippets!
- williamboman/mason.nvim, williamboman/mason-lspconfig.nvim, neovim/nvim-lspconfig,
hrsh7th/cmp-nvim-lsp, glepnir/lspsaga.nvim
Manage, install and configure LSP servers.
During this installation the following files will be created:
.config/nvim/
├── lua
│ ├── core
│ │ ├── colorscheme.lua
│ │ ├── keymaps.lua
│ │ └── options.lua
│ ├── plugins
│ │ ├── lsp
│ │ │ ├── lspconfig.lua
│ │ │ ├── lspsaga.lua
│ │ │ └── mason.lua
│ │ ├── gitsigns.lua
│ │ ├── lualine.lua
│ │ ├── nvim-cmp.lua
│ │ ├── nvim-tree.lua
│ │ ├── scrollbar.lua
│ │ ├── telescope.lua
│ │ └── treesitter.lua
│ └── plugins.lua
└── init.lua
4 directories, 15 files
Dependencies:
1. neovim >= 0.8.3 (https://neovim.io/)
2. git (https://git-scm.com/)
3. ripgrep (https://github.com/BurntSushi/ripgrep)
4. tree-sitter (https://github.com/tree-sitter/tree-sitter)
5. node and npm (https://nodejs.org/en/)
Instructions:
1. Download this script into your home directory
2. "cd" into your home directory
3. Make this script executable:
chmod +x install-my-neovim.sh
4. Run the script:
./install-my-neovim.sh
5. Install plugins and packer:
nvim +PackerInstall
6. Exit Neovim (:qa)
7. Open Neovim again, you are done ;)
END
read -p "Do you want to continue? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
mkdir -p $HOME/.config/nvim/lua/core
cat <<"END" > $HOME/.config/nvim/lua/core/options.lua
local opt = vim.opt -- for conciseness
-- line numbers
opt.relativenumber = true
opt.number = true
-- tabs and indentation
opt.tabstop = 4
opt.shiftwidth = 4
opt.expandtab = true
opt.autoindent = true
-- line wrapping
opt.wrap = true
-- search settings
opt.ignorecase = true
opt.smartcase = true
-- cursor line and column
opt.cursorline = true
opt.cursorcolumn = true
-- appearance
opt.termguicolors = true
opt.background = "dark"
opt.signcolumn = "yes"
-- backspace
opt.backspace = "indent,eol,start"
-- clipboard
opt.clipboard:append("unnamedplus")
-- split windows
opt.splitright = true
opt.splitbelow = true
-- keywords
opt.iskeyword:append("-")
END
cat <<"END" > $HOME/.config/nvim/lua/core/keymaps.lua
local keymap = vim.keymap -- for conciseness
-- general keymaps
keymap.set("n", "<leader>nh", ":nohl<CR>") -- clear highlights
keymap.set("n", "x", '"_x') -- delete character without copying it
keymap.set("v", "x", '"_x') -- delete character without copying it
keymap.set("n", "<leader>sv", "<C-w>v") -- split window vertically
keymap.set("n", "<leader>sh", "<C-w>s") -- split window horizontally
keymap.set("n", "<leader>se", "<C-w>=") -- make split windows equal width
keymap.set("n", "<leader>sx", ":close<CR>") -- close current split window
keymap.set("n", "<leader>to", ":tabnew<CR>") -- open new tab
keymap.set("n", "<leader>tx", ":tabclose<CR>") -- close current tab
keymap.set("n", "<leader>tn", ":tabn<CR>") -- go to next tab
keymap.set("n", "<leader>tp", ":tabp<CR>") -- go to previous tab
-- plugin keymaps
-- nvim-tree.lua
keymap.set("n", "<leader>e", ":NvimTreeToggle<CR>") -- toggle the file explorer
-- telescope
keymap.set("n", "<leader>ff", "<cmd>Telescope find_files<CR>")
keymap.set("n", "<leader>fs", "<cmd>Telescope live_grep<CR>")
keymap.set("n", "<leader>fc", "<cmd>Telescope grep_string<CR>")
keymap.set("n", "<leader>fb", "<cmd>Telescope buffers<CR>")
keymap.set("n", "<leader>fh", "<cmd>Telescope help_tags<CR>")
-- gitsigns
keymap.set("n", "<leader>hp", ":Gitsigns preview_hunk<CR>")
keymap.set("n", "<leader>hs", ":Gitsigns stage_hunk<CR>")
keymap.set("n", "<leader>hu", ":Gitsigns undo_stage_hunk<CR>")
keymap.set("n", "<leader>hr", ":Gitsigns reset_hunk<CR>")
END
cat <<"END" > $HOME/.config/nvim/lua/core/colorscheme.lua
local colorscheme_status, _ = pcall(vim.cmd, "colorscheme iceberg")
if not colorscheme_status then
print("colorscheme not found!")
return
end
END
mkdir -p $HOME/.config/nvim/lua/plugins
cat <<"END" > $HOME/.config/nvim/lua/plugins/nvim-tree.lua
local nvimtree_setup, nvimtree = pcall(require, "nvim-tree")
if not nvimtree_setup then
return
end
-- recommended settings from nvim-tree.lua documentation
vim.g.loaded = 1
vim.g.loaded_netrwPlugin = 1
nvimtree.setup()
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/lualine.lua
local lualine_setup, lualine = pcall(require, "lualine")
if not lualine_setup then
return
end
lualine.setup()
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/telescope.lua
local telescope_setup, telescope = pcall(require, "telescope")
if not telescope_setup then
return
end
local actions_setup, actions = pcall(require, "telescope.actions")
if not actions_setup then
return
end
telescope.setup()
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/gitsigns.lua
local gitsigns_setup, gitsigns = pcall(require, "gitsigns")
if not gitsigns_setup then
return
end
gitsigns.setup({
current_line_blame = true, -- Toggle with `:Gitsigns toggle_current_line_blame`
})
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/scrollbar.lua
local scrollbar_setup, scrollbar = pcall(require, "scrollbar")
if not scrollbar_setup then
return
end
local scrollbar_gitsigns_setup, scrollbar_gitsigns = pcall(require, "scrollbar.handlers.gitsigns")
if not scrollbar_gitsigns_setup then
return
end
scrollbar.setup()
scrollbar_gitsigns.setup()
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/treesitter.lua
local treesitter_setup, treesitter = pcall(require, "treesitter")
if not treesitter_setup then
return
end
treesitter.setup({
highlight = {
enable = true,
},
indent = {
enable = true,
},
ensure_installed = {
"bash",
"dockerfile",
"json",
"markdown",
"markdown_inline",
"yaml",
},
auto_install = true,
})
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/nvim-cmp.lua
local cmp_status, cmp = pcall(require, "cmp")
if not cmp_status then
return
end
local luasnip_status, luasnip = pcall(require, "luasnip")
if not luasnip_status then
return
end
-- load friendly-snippets
require("luasnip/loaders/from_vscode").lazy_load()
vim.opt.completeopt = "menu,menuone,noselect"
cmp.setup({
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
["<C-k>"] = cmp.mapping.select_prev_item(), -- previous suggestion
["<C-j>"] = cmp.mapping.select_next_item(), -- next suggestion
["<C-b>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(), -- show completion suggestions
["<C-e>"] = cmp.mapping.abort(), -- close completion window
["<CR>"] = cmp.mapping.confirm({ select = false }), -- choose a selection
}),
sources = cmp.config.sources({
{ name = "nvim_lsp" }, -- LSP
{ name = "luasnip" }, -- snippets
{ name = "buffer" }, -- text within current buffer
{ name = "path" }, -- file system paths
}),
})
END
mkdir -p $HOME/.config/nvim/lua/plugins/lsp/
cat <<"END" > $HOME/.config/nvim/lua/plugins/lsp/mason.lua
local mason_status, mason = pcall(require, "mason")
if not mason_status then
return
end
local mason_lspconfig_status, mason_lspconfig = pcall(require, "mason-lspconfig")
if not mason_lspconfig_status then
return
end
mason.setup()
mason_lspconfig.setup({
-- Check this list for the available options: https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers
ensure_installed = {
}
})
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/lsp/lspconfig.lua
local lspconfig_status, lspconfig = pcall(require, "lspconfig")
if not lspconfig_status then
return
end
local cmp_nvim_lsp_status, cmp_nvim_lsp = pcall(require, "cmp_nvim_lsp")
if not cmp_nvim_lsp_status then
return
end
local on_attach = function(client, bufnr)
local opts = { noremap = true, silent = true, buffer = bufnr }
local keymap = vim.keymap
-- set keybinds
keymap.set("n", "gf", "<cmd>Lspsaga lsp_finder<CR>", opts) -- show definition, references
keymap.set("n", "gD", "<Cmd>lua vim.lsp.buf.declaration()<CR>", opts) -- got to declaration
keymap.set("n", "gd", "<cmd>Lspsaga peek_definition<CR>", opts) -- see definition and make edits in window
keymap.set("n", "gi", "<cmd>lua vim.lsp.buf.implementation()<CR>", opts) -- go to implementation
keymap.set("n", "<leader>ca", "<cmd>Lspsaga code_action<CR>", opts) -- see available code actions
keymap.set("n", "<leader>rn", "<cmd>Lspsaga rename<CR>", opts) -- smart rename
keymap.set("n", "<leader>D", "<cmd>Lspsaga show_line_diagnostics<CR>", opts) -- show diagnostics for line
keymap.set("n", "<leader>d", "<cmd>Lspsaga show_cursor_diagnostics<CR>", opts) -- show diagnostics for cursor
keymap.set("n", "[d", "<cmd>Lspsaga diagnostic_jump_prev<CR>", opts) -- jump to previous diagnostic in buffer
keymap.set("n", "]d", "<cmd>Lspsaga diagnostic_jump_next<CR>", opts) -- jump to next diagnostic in buffer
keymap.set("n", "K", "<cmd>Lspsaga hover_doc<CR>", opts) -- show documentation for what is under cursor
keymap.set("n", "<leader>o", "<cmd>LSoutlineToggle<CR>", opts) -- see outline on right hand side
end
-- used to enable autocompletion
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Check this list for the available options: https://github.com/williamboman/mason-lspconfig.nvim#available-lsp-servers
-- lspconfig["replace_me"].setup({
-- capabilities = capabilities,
-- on_attach = on_attach,
-- })
END
cat <<"END" > $HOME/.config/nvim/lua/plugins/lsp/lspsaga.lua
local saga_status, saga = pcall(require, "lspsaga")
if not saga_status then
return
end
saga.setup({
move_in_saga = {
prev = "<C-k>",
next = "<C-j>",
},
finder_action_keys = {
open = "<CR>",
},
definition_action_keys = {
edit = "<CR>",
},
})
END
cat <<"END" > $HOME/.config/nvim/lua/plugins.lua
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath('data')..'/site/pack/packer/start/packer.nvim'
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
vim.cmd [[packadd packer.nvim]]
return true
end
return false
end
local packer_bootstrap = ensure_packer()
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerCompile
augroup end
]])
local status, packer = pcall(require, "packer")
if not status then
return
end
return require('packer').startup(function(use)
use 'wbthomason/packer.nvim'
-- My plugins here
-- colorschemes
use("bluz71/vim-nightfly-guicolors")
use("cocopon/iceberg.vim")
-- lua general functions
use("nvim-lua/plenary.nvim")
-- tmux & split window navigation
use("christoomey/vim-tmux-navigator")
-- commenting with gc
use("tpope/vim-commentary")
-- icons
use("kyazdani42/nvim-web-devicons")
-- file explorer
use("nvim-tree/nvim-tree.lua")
-- status line
use("nvim-lualine/lualine.nvim")
-- fuzzy finding
use({ "nvim-telescope/telescope.nvim", branch = "0.1.x" })
-- git integration
use("lewis6991/gitsigns.nvim")
-- scroll bar
use("petertriho/nvim-scrollbar")
-- highlights
use({
"nvim-treesitter/nvim-treesitter",
run = function()
require("nvim-treesitter.install").update({ with_sync = true })
end,
})
-- basic autocompletion
use("hrsh7th/nvim-cmp")
use("hrsh7th/cmp-buffer")
use("hrsh7th/cmp-path")
-- snippet engine
use("L3MON4D3/LuaSnip")
use("saadparwaiz1/cmp_luasnip")
use("rafamadriz/friendly-snippets")
-- managing & installing LSP servers
use("williamboman/mason.nvim")
use("williamboman/mason-lspconfig.nvim")
-- configuring LSP servers
use("neovim/nvim-lspconfig")
use("hrsh7th/cmp-nvim-lsp")
use({ "glepnir/lspsaga.nvim", branch = "main" })
-- 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)
END
cat <<'END' > $HOME/.config/nvim/init.lua
require("plugins")
require("core.colorscheme")
require("core.keymaps")
require("core.options")
require("plugins.nvim-tree")
require("plugins.lualine")
require("plugins.telescope")
require("plugins.gitsigns")
require("plugins.scrollbar")
require("plugins.treesitter")
require("plugins.nvim-cmp")
require("plugins.lsp.mason")
require("plugins.lsp.lspsaga")
require("plugins.lsp.lspconfig")
END
echo 'You are DONE!'
@midir99
Copy link
Author

midir99 commented Feb 6, 2023

Most of this configuration is based on the amazing video Josean Martinez did!
https://www.youtube.com/watch?v=vdn_pKJUda8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment