Skip to content

Instantly share code, notes, and snippets.

@wilfreddenton
Last active March 23, 2023 01:03
Show Gist options
  • Save wilfreddenton/499f042654a8edb7fa2408f6b63234d2 to your computer and use it in GitHub Desktop.
Save wilfreddenton/499f042654a8edb7fa2408f6b63234d2 to your computer and use it in GitHub Desktop.
nvim lua config
-- deps: ripgrep, packer.nvim
-- packer
vim.cmd [[packadd packer.nvim]]
require('packer').startup(function(use)
-- Packer can manage itself
use 'wbthomason/packer.nvim'
use {
'nvim-telescope/telescope.nvim', tag = '0.1.1',
-- or , branch = '0.1.x',
requires = { { 'nvim-lua/plenary.nvim' } }
}
use 'Mofiqul/dracula.nvim'
use('nvim-treesitter/nvim-treesitter', { run = ':TSUpdate' })
use 'theprimeagen/harpoon'
use 'mbbill/undotree'
use 'tpope/vim-fugitive'
use {
'VonHeikemen/lsp-zero.nvim',
branch = 'v1.x',
requires = {
-- LSP Support
{ 'neovim/nvim-lspconfig' }, -- Required
{ 'williamboman/mason.nvim' }, -- Optional
{ 'williamboman/mason-lspconfig.nvim' }, -- Optional
-- Autocompletion
{ 'hrsh7th/nvim-cmp' }, -- Required
{ 'hrsh7th/cmp-nvim-lsp' }, -- Required
{ 'hrsh7th/cmp-buffer' }, -- Optional
{ 'hrsh7th/cmp-path' }, -- Optional
{ 'saadparwaiz1/cmp_luasnip' }, -- Optional
{ 'hrsh7th/cmp-nvim-lua' }, -- Optional
-- Snippets
{ 'L3MON4D3/LuaSnip' }, -- Required
{ 'rafamadriz/friendly-snippets' }, -- Optional
}
}
use {
'nvim-lualine/lualine.nvim',
requires = { 'kyazdani42/nvim-web-devicons', opt = true }
}
use 'christoomey/vim-tmux-navigator'
-- use '~/lua/history.nvim'
use {
'wilfreddenton/history.nvim',
requires = { { 'nvim-lua/plenary.nvim' } }
}
end)
-- set
vim.opt.encoding = "utf-8"
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.expandtab = true
vim.opt.smartindent = true
-- vim.opt.wrap = false
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
vim.opt.undofile = true
vim.opt.termguicolors = true
vim.opt.scrolloff = 8
vim.opt.updatetime = 50
vim.opt.laststatus = 2
vim.g.mapleader = " "
-- remap
vim.keymap.set("i", "jk", "<Esc>")
vim.keymap.set("n", "?", vim.cmd.noh)
vim.keymap.set("n", "<leader>pv", vim.cmd.Ex)
vim.keymap.set("x", "<leader>p", "\"_dP")
vim.keymap.set("n", "<C-u>", "<C-u>zz")
vim.keymap.set("n", "<C-d>", "<C-d>zz")
vim.keymap.set("n", "<leader>fs", vim.cmd.w)
vim.keymap.set("n", "<C-s>", vim.cmd.w)
vim.keymap.set("i", "<C-s>", vim.cmd.w)
vim.keymap.set("i", "<C-x>", vim.cmd.q)
vim.keymap.set("n", "<C-x>", vim.cmd.q)
vim.keymap.set("n", "<C-q>", ":q!<CR>")
vim.keymap.set("n", "<leader>y", "\"+y")
vim.keymap.set("v", "<leader>y", "\"+y")
vim.keymap.set("n", "<leader>Y", "\"+Y")
vim.keymap.set("n", "<leader>f", vim.lsp.buf.format)
vim.keymap.set("n", "<leader><leader>", vim.cmd.so)
vim.keymap.set("n", "<C-3>", "<nop>")
vim.keymap.set("n", "q", "<nop>")
-- colors
function ColorMyPencils(color)
color = color or "dracula"
vim.cmd.colorscheme(color)
vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
vim.api.nvim_set_hl(0, "NormalFloat", { bg = "none" })
end
ColorMyPencils()
-- treesitter
require('nvim-treesitter.configs').setup {
-- A list of parser names, or "all" (the five listed parsers should always be installed)
ensure_installed = { "javascript", "typescript", "rust", "go", "c", "lua", "vim", "help", "query" },
-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = false,
-- Automatically install missing parsers when entering buffer
-- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
auto_install = true,
highlight = {
enable = true,
-- 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,
},
}
-- lsp
local lsp = require('lsp-zero').preset({
name = 'minimal',
set_lsp_keymaps = true,
manage_nvim_cmp = true,
suggest_lsp_servers = false,
})
lsp.ensure_installed({
'lua_ls',
'tsserver',
'eslint',
'rust_analyzer',
})
lsp.nvim_workspace()
lsp.on_attach(function(client, bufnr)
vim.keymap.set("n", "<leader>rr", ":LspRestart<CR>")
end)
lsp.setup()
-- telescope
require('telescope').setup{
defaults = {
-- ...
preview = {
hide_on_startup = true
}
},
pickers = {
find_files = {
theme = "ivy",
}
},
extensions = {
'harpoon',
}
}
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>pf', builtin.find_files, {})
vim.keymap.set('n', '<leader>ps', builtin.live_grep, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})
-- fugitive
vim.keymap.set("n", "<leader>gs", vim.cmd.Git);
-- harpoon
require("harpoon").setup({
menu = {
width = vim.api.nvim_win_get_width(0) - 4,
}
})
local mark = require("harpoon.mark")
local ui = require("harpoon.ui")
vim.keymap.set("n", "<leader>ma", mark.add_file)
vim.keymap.set("n", "<leader>mm", ui.toggle_quick_menu)
vim.keymap.set("n", "<leader>mf", ":Telescope harpoon marks<CR>")
vim.keymap.set("n", "<leader>`1", function() ui.nav_file(1) end)
vim.keymap.set("n", "<leader>`2", function() ui.nav_file(2) end)
vim.keymap.set("n", "<leader>`3", function() ui.nav_file(3) end)
vim.keymap.set("n", "<leader>`4", function() ui.nav_file(4) end)
vim.keymap.set("n", "<leader>`5", function() ui.nav_file(5) end)
vim.keymap.set("n", "<leader>`6", function() ui.nav_file(6) end)
vim.keymap.set("n", "<leader>`7", function() ui.nav_file(7) end)
vim.keymap.set("n", "<leader>`8", function() ui.nav_file(8) end)
vim.keymap.set("n", "<leader>`9", function() ui.nav_file(9) end)
vim.keymap.set("n", "<leader>`0", function() ui.nav_file(0) end)
-- undotree
vim.keymap.set("n", "<leader>u", vim.cmd.UndotreeToggle)
-- lualine
require('lualine').setup {
options = {
-- ...
theme = 'dracula-nvim',
component_separators = { left = '|', right = '|'},
section_separators = { left = '', right = ''},
-- ...
}
}
-- history
require('history').setup({
keybinds = {
back = '<leader>bp',
forward = '<leader>bn',
view = '<leader>bh',
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment