Skip to content

Instantly share code, notes, and snippets.

@ardasener
Last active November 7, 2022 18:48
Show Gist options
  • Save ardasener/1a91778550b2ab62bea9ce879428a60e to your computer and use it in GitHub Desktop.
Save ardasener/1a91778550b2ab62bea9ce879428a60e to your computer and use it in GitHub Desktop.
Nvim Pure Lua Config
-- INDEX
-- BASE
-- PACKER_SETUP
-- PLUGINS
-- DASHBOARD
-- COMMANDS
-- KEYBINDINGS
-- BASE
-- Base Neovim Configuration
-- Turn on line numbers
vim.o.number = true
-- When searching,
-- Purely lowercase queries match mixedcase strings
-- Mixedcase and uppercase queries require exact match
vim.o.ignorecase = true
vim.o.smartcase = true
-- Tab set to two spaces
vim.o.tabstop = 2
vim.o.shiftwidth = 2
vim.o.softtabstop = 2
vim.o.expandtab = true
-- Keeps the signcolumn on at all times
-- (prevents constant movement there)
-- (signcolumn is where the error symbols appear)
vim.o.signcolumn = "yes"
-- Set <leader> key to space
vim.g.mapleader = ' '
-- Affects the delay for which-key menu
vim.o.timeoutlen = 300
-- PACKER_SETUP
-- This section looks for the packer package manager
-- If it is not found installs it
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()
-- PLUGINS
-- This section loads the plugins
-- and does the base configuration for most of them
-- Some larger packages (like which-key and dashboard) may be configured elsewhere
require('packer').startup(function(use)
-- Package Manager (packer)
use { 'wbthomason/packer.nvim' }
-- Colorscheme
use {
'sainnhe/sonokai',
config = function()
vim.cmd [[colorscheme sonokai]]
end
}
-- Really fast statusline
use {
'nvim-lualine/lualine.nvim',
requires = { 'kyazdani42/nvim-web-devicons' },
config = function()
require('lualine').setup()
end
}
-- Tab/Buffer line
use {
'romgrk/barbar.nvim',
requires = { 'kyazdani42/nvim-web-devicons' },
config = function()
require('bufferline').setup()
end
}
-- Keybinding management and menu (see KEYBINDINGS section)
use {
'folke/which-key.nvim',
config = function()
require('which-key').setup({
layout = {
spacing = 5
}
})
end
}
-- Fuzzy finder (similar to FZF but written in lua)
use {
'nvim-telescope/telescope.nvim', tag = '0.1.0',
requires = { { 'nvim-lua/plenary.nvim' } }
}
-- Project Management
use {
'ahmedkhalf/project.nvim',
config = function()
require('project_nvim').setup()
require('telescope').load_extension('projects')
end
}
-- Hassle-free setup for LSP, autocompletion etc.
use {
'VonHeikemen/lsp-zero.nvim',
requires = {
-- LSP Support
{ 'neovim/nvim-lspconfig' },
{ 'williamboman/mason.nvim' },
{ 'williamboman/mason-lspconfig.nvim' },
-- Autocompletion
{ 'hrsh7th/nvim-cmp' },
{ 'hrsh7th/cmp-buffer' },
{ 'hrsh7th/cmp-path' },
{ 'saadparwaiz1/cmp_luasnip' },
{ 'hrsh7th/cmp-nvim-lsp' },
{ 'hrsh7th/cmp-nvim-lua' },
-- Snippets
{ 'L3MON4D3/LuaSnip' },
{ 'rafamadriz/friendly-snippets' },
},
config = function()
local lsp = require('lsp-zero')
lsp.preset('recommended')
lsp.setup()
end
}
-- Toggle an internal terminal
use {
"akinsho/toggleterm.nvim",
tag = '*',
config = function()
require("toggleterm").setup()
end
}
-- Comment/Uncomment line with gcc and selection with gc
use {
'terrortylor/nvim-comment',
config = function()
require('nvim_comment').setup()
end
}
-- Similar to sneak, search with s<char><char>
use {
'ggandor/leap.nvim',
config = function()
require('leap').set_default_keymaps()
end
}
-- File manager similar to nerdtree
use {
'kyazdani42/nvim-tree.lua',
requires = { 'kyazdani42/nvim-web-devicons' },
config = function()
require('nvim-tree').setup()
end
}
-- Customizable Dashboard
use { 'glepnir/dashboard-nvim' }
-- Automatically syncs plugins on first use (should come last in this section)
if packer_bootstrap then
require('packer').sync()
end
end)
-- DASHBOARD
local db = require('dashboard')
db.custom_center = {
{
icon = ' ',
desc = 'Find File',
action = 'Telescope find_files',
},
{
icon = ' ',
desc = 'Recent Projects',
action = 'Telescope projects',
},
{
icon = ' ',
desc = 'Recent Files',
action = 'Telescope oldfiles'
},
{
icon = '漣',
desc = 'Configuration',
action = 'Config'
},
}
db.custom_header = {
'',
' :- .: ',
' :=++=. .+=: ',
':.-++++=: .+++=:',
'--::+++++- .++++=',
'----:=++++= .+++++',
'-----.=++++=. .+++++',
'----- -+++++-.+++++',
'----- .=++++=:=+++',
'----- =++++=:=++',
'----- -+++++:-=',
' .--- :=+++=. ',
' .- ==. ',
'',
'Configured by Arda Sener <github.com/ardasener>',
'',
}
-- COMMANDS
local def_cmd = vim.api.nvim_create_user_command
def_cmd('Config', 'e ~/.config/nvim/init.lua', { nargs = 0 })
def_cmd('SourceConfig', 'source ~/.config/nvim/init.lua', { nargs = 0 })
-- KEYBINDINGS
local def_key = vim.keymap.set
-- Switch buffers with the tab key
def_key('n', '<tab>', '<cmd>bnext<CR>')
def_key('n', '<s-tab>', '<cmd>bprev<CR>')
-- Move between windows with CTRL + move
def_key('n', '<C-h>', '<C-w>h')
def_key('n', '<C-j>', '<C-w>j')
def_key('n', '<C-k>', '<C-w>k')
def_key('n', '<C-l>', '<C-w>l')
def_key('n', '<C-Left>', '<C-w>h')
def_key('n', '<C-Down>', '<C-w>j')
def_key('n', '<C-Up>', '<C-w>k')
def_key('n', '<C-Right>', '<C-w>l')
-- Vim's native line and file completion
-- with CTRL + L/F respectively in insert mode
def_key('i', '<C-l>', '<C-x><C-l>')
def_key('i', '<C-f>', '<C-x><C-f>')
-- Toggle terminal with CTRL + T in normal/terminal modes
def_key('n', '<C-t>', '<cmd>ToggleTerm<CR>')
def_key('t', '<C-t>', '<cmd>ToggleTerm<CR>')
-- Toggle nvim-tree with CTRL + N in normal mode
def_key('n', '<C-n>', '<cmd>NvimTreeToggle<CR>')
-- Toggle telescope file search with CTRL + P in normal mode
def_key('n', '<C-p>', '<cmd>Telescope find_files<CR>')
-- Which key map
-- Usage: <space><char1><char2> in normal mode
local wk_map = {
f = {
name = "Find",
f = { '<cmd>Telescope find_files<CR>', 'Files' },
b = { '<cmd>Telescope buffers<CR>', 'Buffers' },
h = { '<cmd>Telescope oldfiles<CR>', 'History' },
p = { '<cmd>Telescope projects<CR>', 'Projects' },
r = { '<cmd>Telescope registers<CR>', 'Registers' }
},
l = {
name = 'LSP',
s = { '<cmd>LspInfo<CR>', 'Status' },
f = { '<cmd>LspZeroFormat<CR>', 'Format' },
i = { '<cmd>LspInstall<CSR>', 'Install' },
d = { '<cmd>Telescope lsp_document_symbols<CR>', 'Document Symbols' },
p = { '<cmd>Telescope lsp_workspace_symbols<CR>', 'Project Symbols' }
}
}
require('which-key').register(wk_map, { prefix = '<leader>' })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment