Skip to content

Instantly share code, notes, and snippets.

@gtnbssn
Created December 17, 2021 11:37
Show Gist options
  • Save gtnbssn/61aabb5bdfb5068583f298a7cd4b96b6 to your computer and use it in GitHub Desktop.
Save gtnbssn/61aabb5bdfb5068583f298a7cd4b96b6 to your computer and use it in GitHub Desktop.
init.lua with treesitter, LSP and completion
vim.opt.shiftwidth=4
vim.opt.expandtab = true
vim.opt.tabstop = 4
vim.opt.softtabstop = 4
vim.opt.smartindent = true
vim.opt.number = true
vim.opt.relativenumber = true
vim.opt.ignorecase = true
vim.opt.smartcase = true
vim.opt.swapfile = false
vim.opt.backup = false
vim.opt.scrolloff = 5
vim.opt.completeopt = "menuone,noinsert,noselect"
vim.opt.signcolumn = "number"
vim.opt.updatetime = 300
vim.opt.shortmess:append('c')
vim.opt.mouse = 'a'
vim.opt.clipboard = "unnamedplus"
-- only show cursorline in the current split
vim.cmd [[
augroup CursorLine
au!
au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
au WinLeave * setlocal nocursorline
augroup END
]]
require'packer'.startup(function()
use 'nvim-lua/popup.nvim'
use 'nvim-lua/plenary.nvim'
use 'nvim-telescope/telescope.nvim'
use 'gruvbox-community/gruvbox'
use 'tpope/vim-commentary'
use 'tpope/vim-rhubarb'
use 'tpope/vim-fugitive'
use 'airblade/vim-gitgutter'
use {
'nvim-lualine/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true}
}
use 'cohama/lexima.vim'
use 'nvim-treesitter/nvim-treesitter'
use 'JoosepAlviste/nvim-ts-context-commentstring'
use 'neovim/nvim-lspconfig'
use 'williamboman/nvim-lsp-installer'
use 'hrsh7th/cmp-nvim-lsp'
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp'
use 'hrsh7th/cmp-vsnip'
use 'hrsh7th/vim-vsnip'
end)
require'lualine'.setup {
options = {
icons_enabled = true,
theme = 'gruvbox',
component_separators = { left = '', right = ''},
section_separators = { left = '', right = ''},
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'filename'},
lualine_x = {'encoding', 'fileformat', 'filetype'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
extensions = {'fugitive'}
}
require'nvim-treesitter.configs'.setup{
ensure_installed = "maintained", -- Only use parsers that are maintained
highlight = {
enable = true,
},
indent = {
enable = true,
},
context_commentstring = {
enable = true
}
}
-- Setup lspconfig.
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
require'nvim-lsp-installer'.on_server_ready(function(server)
local opts = { capabilities = capabilities }
if server.name == "sumneko_lua" then
opts = {
settings = {
Lua = {
diagnostics = {
globals = { 'vim', 'use' }
},
}
},
capabilities = capabilities
}
end
server:setup(opts)
end)
local cmp = require'cmp'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close(),
}),
-- Accept currently selected item. If none selected, `select` first item.
-- Set `select` to `false` to only confirm explicitly selected items.
['<CR>'] = cmp.mapping.confirm({ select = true }),
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
-- { name = 'vsnip' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
vim.opt.termguicolors = true
vim.g.gruvbox_italics = 1
vim.cmd[[colorscheme gruvbox]]
-- key mappings
vim.g.mapleader = " "
local keymap = vim.api.nvim_set_keymap
local opts = { noremap = true }
-- keep things centered when searching or joining lines
keymap('n', 'n', 'nzzzv', opts)
keymap('n', 'N', 'Nzzzv', opts)
keymap('n', 'J', 'mzJ`z', opts)
-- undo break points, only undoes until these
keymap('i', ',', ',<c-g>u', opts)
keymap('i', '.', '.<c-g>u', opts)
-- move lines of text around <3
keymap('v', 'J', ":m '>+1<CR>gv=gv", opts)
keymap('v', 'K', ":m '<-2<CR>gv=gv", opts)
keymap('i', '<C-j>', "<esc>:m .+1<CR>==", opts)
keymap('i', '<C-k>', "<esc>:m .-2<CR>==", opts)
keymap('n', '<leader>j', ":m .+1<CR>==", opts)
keymap('n', '<leader>k', ":m .-2<CR>==", opts)
-- telescope sugar
keymap('n', '<leader>ff', "<cmd>Telescope find_files<CR>", opts)
keymap('n', '<leader>fg', "<cmd>Telescope live_grep<CR>", opts)
keymap('n', '<leader>fb', "<cmd>Telescope buffers<CR>", opts)
keymap('n', '<leader>fh', "<cmd>Telescope help_tags<CR>", opts)
-- LSP sugar
keymap('n', 'gd', ':lua vim.lsp.buf.definition()<cr>', opts)
keymap('n', 'gD', ':lua vim.lsp.buf.declaration()<cr>', opts)
keymap('n', 'gi', ':lua vim.lsp.buf.implementation()<cr>', opts)
keymap('n', 'gw', ':lua vim.lsp.buf.document_symbol()<cr>', opts)
keymap('n', 'gw', ':lua vim.lsp.buf.workspace_symbol()<cr>', opts)
keymap('n', 'gr', ':lua vim.lsp.buf.references()<cr>', opts)
keymap('n', 'gt', ':lua vim.lsp.buf.type_definition()<cr>', opts)
keymap('n', 'K', ':lua vim.lsp.buf.hover()<cr>', opts)
keymap('n', '<c-k>', ':lua vim.lsp.buf.signature_help()<cr>', opts)
keymap('n', '<leader>af', ':lua vim.lsp.buf.code_action()<cr>', opts)
keymap('n', '<leader>rn', ':lua vim.lsp.buf.rename()<cr>', opts)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment