Skip to content

Instantly share code, notes, and snippets.

@ms747
Created October 28, 2021 12:46
Show Gist options
  • Save ms747/96f27da705be8139247c9ff9944236a1 to your computer and use it in GitHub Desktop.
Save ms747/96f27da705be8139247c9ff9944236a1 to your computer and use it in GitHub Desktop.
Basic Neovim Lua config
local global = vim.g
local option = vim.o
local set = vim.opt
local map = vim.api.nvim_set_keymap
-- Set conceallevel = 0
vim.api.nvim_exec("autocmd BufEnter *.json set conceallevel=0", false)
vim.api.nvim_exec("autocmd BufEnter *.json set concealcursor=n", false)
-- Tabs Settings
set.tabstop = 2
set.shiftwidth = 2
set.softtabstop = 2
set.expandtab = false
-- Keymaps
map('n', '<C-j>', '<Esc>', { noremap = true })
map('i', '<C-j>', '<Esc>', { noremap = true })
map('x', '<C-j>', '<Esc>', { noremap = true })
map('c', '<C-j>', '<Esc>', { noremap = true })
map('n', '<C-x>', '<C-v>', { noremap = true })
map('n', '<C-d>', '<C-x>', { noremap = true })
map('n', '<A-j>', ':m+<CR>==', { noremap = true })
map('n', '<A-k>', ':m-2<CR>==', { noremap = true })
map('x', '<A-j>', ":m'>+<CR>gv=gv", { noremap = true })
map('x', '<A-k>', ":m-2<CR>gv=gv", { noremap = true })
map('n', '<C-p>', '<cmd>Telescope find_files<CR>', { noremap = true })
map('n', '<C-s>', '<cmd>Telescope live_grep<CR>', { noremap = true })
map('i', '<C-a>', '<Esc>I', { noremap = true })
map('i', '<C-e>', '<Esc>A', { noremap = true })
-- Settings
option.colorcolumn = '80'
option.mouse = 'a'
option.number = true
option.cmdheight = 1
option.ignorecase = true
option.smartcase = true
option.relativenumber = true
global.noswapfile = true
option.undodir = "~/.undodir"
option.undofile = true
set.hlsearch = false
option.completeopt = 'menu,menuone,noselect,noinsert'
-- Telescope Config
local telescope = require('telescope')
telescope.setup{
defaults = {
mappings = {
i = {
["<C-j>"] = "close",
}
}
}
}
-- Autocompletion
local cmp = require('cmp')
cmp.setup({
mapping = {
['<C-n>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
['<C-p>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
['<Down>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
['<Up>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
['<S-Tab>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 's' })
},
sources = cmp.config.sources({
{ name = 'buffer'},
{ name = 'path'},
{ name = 'cmdline'},
})
})
-- Auto Pairs
require('nvim-autopairs').setup{}
-- Commentor
require('nvim_comment').setup()
-- Plugins
vim.cmd [[packadd packer.nvim]]
return require('packer').startup(function()
-- Telescope
use {
'nvim-telescope/telescope.nvim',
requires = { {'nvim-lua/plenary.nvim'} }
}
-- Nvim-Cmp
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp'
-- Auto Pairs
use 'windwp/nvim-autopairs'
-- Commentor
use 'terrortylor/nvim-comment'
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment