Skip to content

Instantly share code, notes, and snippets.

@folkertdev
Last active August 10, 2023 18:38
Show Gist options
  • Save folkertdev/724df2c710bf36786a0e8ca69f4c458e to your computer and use it in GitHub Desktop.
Save folkertdev/724df2c710bf36786a0e8ca69f4c458e to your computer and use it in GitHub Desktop.
public init.vim
let mapleader=","
" unset the mouse
set mouse=
au BufRead,BufNewFile *.elm set filetype=elm
" copy to system clipboard
" see http://askubuntu.com/questions/347519/unable-to-copy-from-vim-to-system-clipboard
set clipboard=unnamedplus
"paste does not destroy the clipboard
xnoremap p pgvy
" display UI for switching buffers
:nnoremap <F5> :buffers<CR>:buffer<Space>
"switch to previous buffer
nnoremap <silent> <Leader>s :b#<CR>
nnoremap <silent> <Leader>cc :cclose<CR>
nnoremap <silent> <Leader>ck :cprev<CR>
nnoremap <silent> <Leader>cj :cnext<CR>
" search settings
set incsearch "start searching immediately
set ignorecase " ignore the case
set smartcase "except when there is an uppercase letter in the search term
call plug#begin('~/.vim/plugged')
" Collection of common configurations for the Nvim LSP client
Plug 'neovim/nvim-lspconfig'
" Completion framework
Plug 'hrsh7th/nvim-cmp'
" LSP completion source for nvim-cmp
Plug 'hrsh7th/cmp-nvim-lsp'
" Snippet completion source for nvim-cmp
Plug 'hrsh7th/cmp-vsnip'
" Other usefull completion sources
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-buffer'
" See hrsh7th's other plugins for more completion sources!
" To enable more of the features of rust-analyzer, such as inlay hints and more!
Plug 'simrat39/rust-tools.nvim'
" Snippet engine
Plug 'hrsh7th/vim-vsnip'
" Fuzzy finder
" Optional
Plug 'nvim-lua/popup.nvim'
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
" color schemes
Plug 'chriskempson/base16-vim'
Plug 'tpope/vim-surround'
Plug 'godlygeek/tabular'
"
Plug 'terryma/vim-multiple-cursors'
Plug 'rhysd/vim-llvm'
Plug 'nvim-lua/completion-nvim'
Plug 'ziglang/zig.vim' "broken with new neovim?
call plug#end()
" For init.vim
lua << EOF
local lspconfig = require('lspconfig')
lspconfig.zls.setup{}
EOF
autocmd ColorScheme * hi multiple_cursors_cursor term=reverse cterm=reverse gui=reverse
" Bind the tab key
inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"
" allow the . to execute once for each line of a visual selection
vnoremap . :normal .<CR>
""" COLORS """
syntax on
" make comments readable
set background=dark
let base16colorspace=256
colorscheme base16-default-dark
" Set completeopt to have a better completion experience
" :help completeopt
" 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
" Configure LSP through rust-tools.nvim plugin.
" rust-tools will configure and enable certain LSP features for us.
" See https://github.com/simrat39/rust-tools.nvim#configuration
lua <<EOF
local nvim_lsp = require'lspconfig'
local opts = {
tools = { -- rust-tools options
autoSetHints = true,
inlay_hints = {
show_parameter_hints = false,
parameter_hints_prefix = "",
other_hints_prefix = "",
},
},
-- all the opts to send to nvim-lspconfig
-- these override the defaults set by rust-tools.nvim
-- see https://github.com/neovim/nvim-lspconfig/blob/master/doc/server_configurations.md#rust_analyzer
server = {
-- on_attach is a callback called when the language server attachs to the buffer
-- on_attach = on_attach,
settings = {
-- to enable rust-analyzer settings visit:
-- https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/generated_config.adoc
["rust-analyzer"] = {
-- enable clippy on save
checkOnSave = {
command = "clippy"
},
},
}
},
}
local rt = require("rust-tools")
rt.setup({
server = {
on_attach = function(_, bufnr)
-- Hover actions
vim.keymap.set("n", "<C-space>", rt.hover_actions.hover_actions, { buffer = bufnr })
-- Code action groups
vim.keymap.set("n", "<Leader>a", rt.code_action_group.code_action_group, { buffer = bufnr })
end,
},
})
EOF
" Setup Completion
" See https://github.com/hrsh7th/nvim-cmp#basic-configuration
lua <<EOF
local cmp = require'cmp'
cmp.setup({
-- Enable LSP snippets
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
-- Add tab support
['<S-Tab>'] = cmp.mapping.select_prev_item(),
['<Tab>'] = cmp.mapping.select_next_item(),
['<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.Insert,
select = true,
})
},
-- Installed sources
sources = {
{ name = 'nvim_lsp' },
{ name = 'vsnip' },
{ name = 'path' },
{ name = 'buffer' },
},
})
EOF
" autocmd BufWritePre *.rs lua vim.lsp.buf.formatting_sync(nil, 200)
" format-on-save
autocmd BufWritePre *.rs lua vim.lsp.buf.format()
" Define a custom color for type names in Rust
hi @lsp.type.parameter guifg=Yellow
hi @lsp.type.property guifg=Grey
hi @lsp.type.struct guifg=Grey
hi @lsp.type.enumMember guifg=Grey
hi @lsp.type.variable.rust guifg=Grey
hi @lsp.type.enum guifg=Blue
hi @lsp.type.decorator.rust guifg=Yellow
hi @lsp.mod.documentation.rust guifg=Green
hi @lsp.typemod.comment.documentation.rust guifg=Green
hi @lsp.type.comment.rust guifg=Grey
" prevent syntax highlight flickering in zig
hi @lsp.type.variable.zig guifg=Grey
hi @lsp.type.function.zig guifg=Grey
hi @lsp.type.type.zig guifg=Grey
" Code navigation shortcuts
nnoremap <silent> <c-]> <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> K <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gD <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <c-k> <cmd>lua vim.lsp.buf.signature_help()<CR>
nnoremap <silent> gT <cmd>lua vim.lsp.buf.type_definition()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> g0 <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gW <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> ga <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> <leader>rn <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <silent> gdk <cmd>lua vim.diagnostic.goto_prev()<CR>
nnoremap <silent> gdj <cmd>lua vim.diagnostic.goto_next()<CR>
lua require('telescope')
" Find files using Telescope command-line sugar.
nnoremap <leader>f <cmd>Telescope find_files<cr>
nnoremap <leader>g <cmd>Telescope live_grep<cr>
nnoremap <leader>tr <cmd>Telescope resume<cr>
" Make sure Vim returns to the same line when you reopen a file.
" Thanks, Amit
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" allow the . to execute once for each line of a visual selection
vnoremap . :normal .<CR>
" Clean trailing whitespace
nnoremap <leader>w mz:%s/\s\+$//<cr>:let @/=''<cr>`z
""" LINE NUMBERING
set relativenumber "show relative line numbers
set number "but current line number is the actual number
" Cycle through relativenumber + number, number (only), and no numbering.
function! Cycle_numbering() abort
if exists('+relativenumber')
execute {
\ '00': 'set relativenumber | set number',
\ '01': 'set norelativenumber | set number',
\ '10': 'set norelativenumber | set nonumber',
\ '11': 'set norelativenumber | set number' }[&number . &relativenumber]
else
" No relative numbering, just toggle numbers on and off.
set number!<CR>
endif
endfunction
nnoremap <silent> <Leader>r :call Cycle_numbering()<CR>
" have a fixed column for the diagnostics to appear in
" this removes the jitter when warnings/errors flow in
set signcolumn=yes
set noswapfile
set nobackup
set cursorline " highlight current line
set showmatch " show matching bracket
set showmode "show current mode"
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
" remap split switching keys
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" make Y yank from the cursor to the end of the line
noremap Y y$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment