Initial Commit for New Config

writing
Nick Zana 3 years ago
parent 83788ca6f3
commit aeab7edde9
No known key found for this signature in database
GPG Key ID: A6E59E60FE474883

1
.gitignore vendored

@ -0,0 +1 @@
plugin/

@ -1,219 +1,5 @@
-- Install packer
local execute = vim.api.nvim_command
local install_path = vim.fn.stdpath('data')..'/site/pack/packer/opt/packer.nvim'
-- Check that packer is installed
if vim.fn.empty(vim.fn.glob(install_path)) > 0 then
execute('!git clone https://github.com/wbthomason/packer.nvim '..install_path)
end
vim.cmd [[packadd packer.nvim]]
vim.api.nvim_exec([[
augroup Packer
autocmd!
autocmd BufWritePost plugins.lua PackerCompile
augroup end
]], false)
local use = require('packer').use
local packer = require('packer')
packer.startup(function()
use { 'wbthomason/packer.nvim', opt = true } -- Package manager
-- visuals
use 'gruvbox-community/gruvbox'
-- file management
use {
'nvim-telescope/telescope.nvim',
requires = {
{'nvim-lua/popup.nvim'},
{'nvim-lua/plenary.nvim'},
{'nvim-treesitter/nvim-treesitter'},
}
}-- search and select tool
use 'preservim/nerdtree'
-- editing behaviour
use 'jiangmiao/auto-pairs'
use 'tpope/vim-commentary' -- Easily comment/uncomment code
use 'tpope/vim-surround' -- surround text objects with delimiters
-- git TODO: Learn how to use
use 'airblade/vim-gitgutter'
use 'tpope/vim-fugitive'
-- LSP
use 'neovim/nvim-lspconfig'
use 'nvim-lua/lsp_extensions.nvim'
use 'nvim-lua/completion-nvim'
-- Language specific
use 'rust-lang/rust.vim'
end)
-- settings -- this is all of the basic vim settings
local o = vim.o -- global
local g = vim.g -- global 2?
local wo = vim.wo -- window local
local bo = vim.bo -- buffer local
-- basic UI
o.background = 'dark'
o.termguicolors = true -- enable 24 bit colors in TUI
vim.cmd('colorscheme gruvbox')
vim.cmd('syntax enable')
wo.number = true
wo.relativenumber = true
o.signcolumn = 'yes'
o.splitright = true
o.splitbelow = true
-- text
wo.wrap = false
wo.foldenable = false
o.mouse = 'a'
-- search
o.hlsearch = false
o.incsearch = true
o.ignorecase = true
-- temporary file configuration
o.swapfile = false
o.undofile = true
bo.undofile = true
o.dir = '/tmp'
o.hidden = true -- do not save when switching buffers
-- LSP
o.updatetime = 250
o.completeopt = 'menuone,noinsert,noselect'
o.inccommand = 'nosplit'
-- keybindings
local map = vim.api.nvim_set_keymap
g.mapleader = ' '
-- window navigation
map('n', '<C-j>', '<C-W>j', {noremap = true})
map('n', '<C-k>', '<C-W>k', {noremap = true})
map('n', '<C-l>', '<C-W>l', {noremap = true})
map('n', '<C-h>', '<C-W>h', {noremap = true})
-- terminal
map('t', '<C-e>', '<C-\\><C-n>', {noremap = true})
-- NERDTree
map('n', '<leader>nt', '<cmd>NERDTreeToggle<CR>', {noremap = true})
-- Telescope
map('n', '<C-p>', '<cmd>Telescope git_files<cr>', {noremap = true})
-- LSP TODO: make lua instead of vimscript
--
-- Use completion-nvim in every buffer
vim.api.nvim_exec([[
autocmd BufEnter * lua require'completion'.on_attach()
]], false)
-- Avoid showing message extra message when using completion
--
-- Use <Tab> and <S-Tab> to navigate through popup menu
vim.api.nvim_exec([[
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
]], false)
-- use <Tab> as trigger keys
vim.api.nvim_exec([[
imap <Tab> <Plug>(completion_smart_tab)
imap <S-Tab> <Plug>(completion_smart_s_tab)
]], false)
-- code shortcuts
local opts = { noremap=true, silent=true }
map('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
map('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
map('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
-- map('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
map('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
map('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
map('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
map('n', '<leader>d', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
map('n', '[g', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
map('n', ']g', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
-- autocommands
-- Highlight on yank
vim.cmd('au TextYankPost * lua vim.highlight.on_yank {on_visual = false}' )-- disabled in visual mode
-- Trim Whitespace
vim.api.nvim_exec([[
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
augroup AUTOCOMMANDGROUP
autocmd!
autocmd BufWritePre * :call TrimWhitespace()
augroup END
]], false)
-- language server configs
-- LSP settings
local nvim_lsp = require('lspconfig')
local on_attach = function(_client, bufnr)
require'completion'.on_attach(_client)
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
local opts = { noremap=true, silent=true }
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
end
-- Rust
vim.cmd([[let g:rustfmt_autosave = 1]])
nvim_lsp['rust_analyzer'].setup {
on_attach = on_attach,
settings = {
["rust-analyzer"] = {
cargo = {
allFeatures = true
},
checkOnSave = {
command = "clippy",
extraArgs = "["--", "-W", "clippy::pedantic"]"
}
}
}
}
-- Python
require'lspconfig'.jedi_language_server.setup{}
-- Enable diagnostics
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = true,
signs = true,
update_in_insert = true,
}
)
-- Show diagnostic popup on cursor hold
vim.cmd([[autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()]])
-- Enable type inlay hints
vim.cmd([[autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost * lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} }]])
require('plugins') -- Setup packer.nvim and install plugins
require('nvim_opts') -- Basic vim options
require('autocmd') -- Convenient Autocommands
require('lsp')
require('keybindings')

@ -0,0 +1,16 @@
-- Highlight on yank
vim.cmd('au TextYankPost * lua vim.highlight.on_yank {on_visual = false}' )-- disabled in visual mode
-- Trim Whitespace
vim.api.nvim_exec([[
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
augroup AUTOCOMMANDGROUP
autocmd!
autocmd BufWritePre * :call TrimWhitespace()
autocmd BufEnter,BufWinEnter,TabEnter *.rs :lua require'lsp_extensions'.inlay_hints{}
augroup END
]], false)

@ -0,0 +1,81 @@
local map = vim.api.nvim_set_keymap
-- Avoid infinitely recursive definitions
options = { noremap = true }
-- Copy/paste
map('n', '<leader>y', '"+y', options)
map('v', '<leader>y', '"+y', options)
-- WINDOW MANAGEMENT
-- Navigate windows
map('n', '<C-h>', '<C-w>h', options)
map('n', '<C-j>', '<C-w>j', options)
map('n', '<C-k>', '<C-w>k', options)
map('n', '<C-l>', '<C-w>l', options)
-- Move windows TODO
-- Terminal
map('t', '<C-e>', '<C-\\><C-n>', options) -- Exit Terminal mode enter Normal
-- FILE NAVIGATION
map('n', '<C-p>', '<cmd>Telescope git_files<CR>', options)
map('n', '<C-f>', '<cmd>Telescope find_files<CR>', options)
-- Grep for prompted str project wide
map('n', '<leader>ps', "<cmd>lua require('telescope.builtin').grep_string({ search = vim.fn.input(\"Grep For > \")})<CR>", options)
-- Telescope fuzzy search for buffers
map('n', '<leader>pb', "<cmd>lua require('telescope.builtin').buffers()<CR>", options)
-- CODE NAVIGATOIN
-- Quick Fix Lists
-- global -- using control
map('n', 'J', '<cmd>cnext<CR>zz', options) -- Go to next item in global qfixlist
map('n', 'K', '<cmd>cprev<CR>zz', options) -- Go to previous item in global qfixlist
-- Toggle the window if there are items in the qfixlist; allow recursive
map('n', 'Q', '<cmd>call ToggleQFList(1)<CR>', {}) -- see plugin/navigation.vim for ToggleQFList definition
-- local -- using leader
map('n', '<leader>j', '<cmd>lnext<CR>zz', options) -- Go to next item in local qfixlist
map('n', '<leader>k', '<cmd>lprev<CR>zz', options) -- Go to previous item in global qfixlist
-- Toggle the window if there are items in the qfixlist; allow recursive
map('n', '<leader>q', '<cmd>call ToggleQFList(0)<CR>', {}) -- see plugin/navigation.vim for ToggleQFList definition
-- git
map('n', '<leader>gs', '<cmd>G<CR>', options)
-- LSP
-- Use an on_attach function to only map the following keys
-- after the language server attaches to the current buffer
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
buf_set_keymap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', options)
buf_set_keymap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', options)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.hover()<CR>', options)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', options)
buf_set_keymap('n', 's', '<cmd>lua vim.lsp.buf.signature_help()<CR>', options)
buf_set_keymap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', options)
buf_set_keymap('n', 'ga', '<cmd>lua vim.lsp.buf.code_action()<CR>', { noremap = true })
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', options)
buf_set_keymap('n', '<leader>d', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', options)
-- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', options)
-- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diaoNostic.goto_next()<CR>', options)
buf_set_keymap('n', '<leader>q', '<cmd>lua vim.diagnostic.set_qflist()<CR>', options)
buf_set_keymap('n', '<leader>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', options)
end
-- Code actions
map('n', '<leader>t', '<cmd>CargoTest<CR>', options) -- Run test under cursor
return { on_attach = on_attach }

@ -0,0 +1,22 @@
local on_attach = require'keybindings'.on_attach
local capabilities = require'cmp_nvim_lsp'.update_capabilities(vim.lsp.protocol.make_client_capabilities())
local cmp = require'nvim-cmp-cfg'.cmp
-- SERVERS
-- rust_analyzer
vim.g.rustfmt_autosave = 1
require'lspconfig'.rust_analyzer.setup{
on_attach = on_attach,
capabilities = capabilities,
settings = {
["rust-analyzer"] = {
procMacro = {
enable = true,
},
checkOnSave = {
command = 'clippy',
extraArgs = "-W clippy::pedantic"
},
}
}
}

@ -0,0 +1,56 @@
-- TODO: Improve docs
-- Setup nvim-cmp.
local cmp = require'cmp'
-- Ensure vsnip is installed
require'cmp_vsnip'
cmp.setup({
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
['<CR>'] = cmp.mapping.confirm({ select = true }),
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
}, {
{ 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' }
})
})
return { cmp = cmp }

@ -0,0 +1,42 @@
local o = vim.o -- global
local g = vim.g -- global 2?
local wo = vim.wo -- window local
local bo = vim.bo -- buffer local
g.mapleader = ' '
-- basic UI
o.background = 'dark'
o.termguicolors = true -- enable 24 bit colors in TUI
vim.cmd 'colorscheme gruvbox'
g.syntax = true
wo.number = true
wo.relativenumber = true
o.signcolumn = 'yes'
o.splitright = true
o.splitbelow = true
o.colorcolumn = '80'
-- text
wo.wrap = false
wo.foldenable = false
o.mouse = 'a' -- enable mouse in all modes
o.tabstop = 4 -- Display width of a <Tab>
o.softtabstop = 4 -- How large inserted tabs are
o.expandtab = false -- Insert <Tab> instead of spaces
o.shiftwidth = 4 -- "Number of spaces used for each step of an (auto)indent"
o.scrolloff = 8 -- Start scrolling when 8 away from top/bottom
-- search
o.hlsearch = false
o.incsearch = true -- Incremental highlighting while typing a search query
o.ignorecase = true
o.smartcase = true -- Match case if a capital letter is used
-- temporary file configuration
o.swapfile = false
o.undofile = true
o.dir = '/tmp'
-- Buffers
o.hidden = true -- Allow hidden buffers without saving

@ -0,0 +1,45 @@
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
packer_bootstrap = fn.system({'git', 'clone', '--depth', '1', 'https://github.com/wbthomason/packer.nvim', install_path})
end
local plugins = require('packer').startup(function(use)
use 'wbthomason/packer.nvim'
use 'gruvbox-community/gruvbox'
-- file management
use {
'nvim-telescope/telescope.nvim', -- search and select tool
requires = { {'nvim-lua/plenary.nvim'} }
}
-- git
use 'tpope/vim-fugitive'
-- LSP
use 'neovim/nvim-lspconfig' -- Common lsp server configurations
use 'tjdevries/lsp_extensions.nvim' -- Provides type inlay hint support
use 'hrsh7th/cmp-nvim-lsp' -- Completion LSP integeration
use 'hrsh7th/cmp-buffer'
use 'hrsh7th/cmp-path'
use 'hrsh7th/cmp-cmdline'
use 'hrsh7th/nvim-cmp' -- Autocompletion
-- Snippets (Required for nvim-cmp)
use 'hrsh7th/cmp-vsnip'
use 'hrsh7th/vim-vsnip'
-- Language Specfic
use 'rust-lang/rust.vim'
if packer_bootstrap then
require('packer').sync()
end
end)
-- Required for rust.vim
-- TODO: Convert to lua
vim.cmd([[filetype plugin indent on]])
return plugins
Loading…
Cancel
Save