Skip to content

Commit

Permalink
Updated some nvim configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ruanpetterson committed May 1, 2022
1 parent bc90586 commit 1357433
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 59 deletions.
58 changes: 49 additions & 9 deletions .config/nvim/init.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ set encoding=UTF-8
set t_Co=256

call plug#begin()
Plug 'psf/black', { 'branch': 'stable' }
Plug 'psf/black'
Plug 'cespare/vim-toml'
Plug 'dag/vim-fish'
Plug 'tmux-plugins/vim-tmux'
Plug 'wakatime/vim-wakatime'

" Collection of common configurations for the Nvim LSP client
" Semantic language support
Plug 'neovim/nvim-lspconfig'
" Extensions to built-in LSP, for example, providing type inlay hints
Plug 'nvim-lua/lsp_extensions.nvim'
" Autocompletion framework for built-in LSP
Plug 'nvim-lua/completion-nvim'
Plug 'hrsh7th/cmp-nvim-lsp', {'branch': 'main'}
Plug 'hrsh7th/cmp-buffer', {'branch': 'main'}
Plug 'hrsh7th/cmp-cmdline', {'branch': 'main'}
Plug 'hrsh7th/nvim-cmp', {'branch': 'main'}

" Only because nvim-cmp _requires_ snippets
Plug 'hrsh7th/cmp-vsnip', {'branch': 'main'}
Plug 'hrsh7th/vim-vsnip'
Plug 'nvim-lua/plenary.nvim'

" Syntactic language support
Plug 'cespare/vim-toml'
Plug 'stephpy/vim-yaml'
Plug 'rust-lang/rust.vim'
Plug 'rhysd/vim-clang-format'

" Neovim style
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Expand All @@ -28,24 +40,52 @@ let g:airline_powerline_fonts = 0

"" Line numbers
set number
set numberwidth=4
set number relativenumber
set numberwidth=6

"" Set default identation
set tabstop=4
set shiftwidth=4
set expandtab

set showcmd " Show (partial) command in status line.
set mouse=a " Enable mouse usage (all modes) in terminals
set shortmess+=c " don't give |ins-completion-menu| messages.

"" Turn on color scheme
set termguicolors
syntax on
filetype plugin indent on

"" Theming
set background=dark
colorscheme gruvbox

" transparent bg
"highlight Normal guibg=NONE ctermbg=NONE
"hi Normal ctermbg=NONE
"hi Normal guibg=NONE
"highlight LineNr guifg=grey guibg=NONE ctermfg=NONE ctermbg=NONE
set background=dark

" wrapping options
set formatoptions=tc " wrap text and comments using textwidth
set formatoptions+=r " continue comments when pressing ENTER in I mode
set formatoptions+=q " enable formatting of comments with gq
set formatoptions+=n " detect lists for formatting
set formatoptions+=b " auto-wrap in insert mode, and do not wrap old long lines

" Proper search
set incsearch
set ignorecase
set smartcase
set gdefault

" Search results centered please
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
source <sfile>:h/lsp.vim

source <sfile>:h/telescope.vim
"source <sfile>:h/telescope.vim
139 changes: 94 additions & 45 deletions .config/nvim/lsp.vim
Original file line number Diff line number Diff line change
@@ -1,65 +1,114 @@
" Set completeopt to have a better completion experience
" :help completeopt
" Completion
" Better completion
" menuone: popup even when there's only one match
" noinsert: Do not insert text until a selection is made
" noselect: Do not select, force user to select one from the menu
set completeopt=menuone,noinsert,noselect

" Avoid showing extra messages when using completion
set shortmess+=c

" Set updatetime for CursorHold
" 300ms of no cursor movement to trigger CursorHold
set completeopt+=menuone,noinsert,noselect
" Better display for messages
set cmdheight=2
" You will have bad experience for diagnostic messages when it's default 4000.
set updatetime=300
" Show diagnostic popup on cursor hold
autocmd CursorHold * lua vim.lsp.diagnostic.show_line_diagnostics()

" Enable type inlay hints
autocmd CursorMoved,InsertLeave,BufEnter,BufWinEnter,TabEnter,BufWritePost *
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} }
" LSP configuration
lua << EOF
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED by nvim-cmp. get rid of it once we can
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = cmp.mapping.preset.insert({
-- Tab immediately completes. C-n/C-p to select.
--['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}),
--['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}),
['<Tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
-- TODO: currently snippets from lsp end up getting prioritized -- stop that!
{ name = 'nvim_lsp' },
}, {
name = 'buffer'
}),
completion = {
completeopt = 'menu,menuone,noinsert'
},
experimental = {
ghost_text = true,
},
})

" Enable code actions (Alt + .)
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline({
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), {'i','c'}),
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), {'i','c'}),
['<Tab>'] = cmp.mapping.confirm({ select = true }),
}),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})

" Auto format (Ctrl + Shift + I)
nnoremap <silent> <C-S-I> <cmd>lua vim.lsp.buf.formatting()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
-- Setup lspconfig.
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

lua << EOF
-- nvim_lsp object
local nvim_lsp = require'lspconfig'
--Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')

-- Mappings.
local opts = { noremap=true, silent=true }
-- function to attach completion when setting up lsp
local on_attach = function(client)
require'completion'.on_attach(client)
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts)
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
buf_set_keymap('n', '<space>r', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<space>a', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts)
end

-- enable rust_analyzer
nvim_lsp.rust_analyzer.setup {
local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
local lspconfig = require'lspconfig'
lspconfig.rust_analyzer.setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
},
settings = {
["rust-analyzer"] = {
assist = {
importMergeBehavior = "last",
importPrefix = "by_self",
},
diagnostics = {
disabled = { "unresolved-import" }
},
cargo = {
loadOutDirsFromCheck = true
},
procMacro = {
enable = true
allFeatures = true,
},
checkOnSave = {
command = "clippy"
},
}
}
},
},
capabilities = capabilities,
}

-- enable ccls
nvim_lsp.ccls.setup{on_attach=on_attach}
-- 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,
}
)
EOF

" Enable type inlay hints
autocmd CursorHold,CursorHoldI *.rs
\ lua require'lsp_extensions'.inlay_hints{ prefix = '', highlight = "Comment", enabled = {"TypeHint", "ChainingHint", "ParameterHint"} }

5 changes: 0 additions & 5 deletions .config/nvim/telescope.vim

This file was deleted.

0 comments on commit 1357433

Please sign in to comment.