Skip to content

Instantly share code, notes, and snippets.

@lmduc

lmduc/init.vim Secret

Last active September 8, 2022 19:24
Show Gist options
  • Save lmduc/15039c6bec9f122b48d55ca130e11fa5 to your computer and use it in GitHub Desktop.
Save lmduc/15039c6bec9f122b48d55ca130e11fa5 to your computer and use it in GitHub Desktop.
" Installation
" Install vim-plug
" brew install ripgrep
" brew install tmux-mem-cpu-load
let mapleader=" "
call plug#begin()
" The default plugin directory will be as follows:
" - Vim (Linux/macOS): '~/.vim/plugged'
" - Vim (Windows): '~/vimfiles/plugged'
" - Neovim (Linux/macOS/Windows): stdpath('data') . '/plugged'
" You can specify a custom plugin directory by passing it as the argument
" - e.g. `call plug#begin('~/.vim/plugged')`
" - Avoid using standard Vim directory names like 'plugin'
" Make sure you use single quotes
" Set theme
Plug 'EdenEast/nightfox.nvim'
Plug 'rafamadriz/neon'
Plug 'jacoborus/tender.vim'
Plug 'rmehri01/onenord.nvim', { 'branch': 'main' }
" Terminal
" Type :h terminal-emulator for more information
Plug 'akinsho/toggleterm.nvim', {'tag' : '*'}
" Debug adapter protocol
Plug 'mfussenegger/nvim-dap'
" Scala metals
Plug 'scalameta/nvim-metals'
" Autocomplete
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
" COC
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" YAML helpers
Plug 'someone-stole-my-name/yaml-companion.nvim'
" Fuzzy file search
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
Plug 'nvim-telescope/telescope.nvim', { 'branch': '0.1.x' }
" Quick jump
Plug 'phaazon/hop.nvim'
" Auto pair
Plug 'windwp/nvim-autopairs'
" File explorer using nvim-tree
" https://github.com/kyazdani42/nvim-tree.lua
" Type :h nvim-tree-commands for more commands
Plug 'kyazdani42/nvim-tree.lua'
" Initialize plugin system
" - Automatically executes `filetype plugin indent on` and `syntax enable`.
call plug#end()
" You can revert the settings after the call like so:
" filetype indent off " Disable file-type-specific indentation
" syntax off " Disable syntax highlighting
" Hotkeys for fuzzy search
nnoremap <leader>oo <cmd>Telescope find_files<cr>
nnoremap <leader>os <cmd>Telescope live_grep<cr>
" Hotkeys for file explorer
" :help nvim-tree-commands
nnoremap <leader>eo <cmd>:NvimTreeToggle<cr>
nnoremap <leader>ec <cmd>:NvimTreeFindFile<cr>
" Hotkeys for quick jump
nnoremap <leader><leader>f <cmd>:HopChar1<cr>
vnoremap <leader><leader>f <cmd>:HopChar1<cr>
" Fast saving
nmap <leader>w :w!<cr>
" Fast quitting
nmap <leader>q :q<cr>
" Fast copy to clipboard
vmap <leader>yc "*y<cr>
" Move between splits
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>
" Indent
set tabstop=2
set shiftwidth=2
set softtabstop=2
set autoindent
" Show current line and current column
set cursorline! cursorcolumn!
" Highlight search
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2"
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
" Switch focus on new split
set splitright
set splitbelow
" Not show breaking line
set nowrap
" Turn off beep and flash
set noerrorbells visualbell t_vb=
autocmd GUIEnter * set visualbell t_vb=
" Remove trailing spaces when saving
autocmd BufWritePre * :%s/\s\+$//e
" Backspace
set backspace=indent,eol,start
" Vim gf
set path+=**
" Vim fold
set foldmethod=indent
set foldnestmax=10
set nofoldenable
set foldlevel=2
" Show line numbers
set number
" Set encoding to UTF8
set encoding=utf8
" Show spaces and tabs
set lcs+=space:·
set list
" Uncomment one of the colorschemes
" colorscheme terafox
colorscheme nordfox
" colorscheme duskfox
" colorscheme nightfox
" colorscheme neon
" colorscheme tender
" colorscheme onenord
" Terminal
:tnoremap <Esc> <C-\><C-n>
nnoremap <leader>t1 <cmd>:ToggleTerm1<cr>
nnoremap <leader>tv1 <cmd>:ToggleTerm1 direction=vertical size=150<cr>
nnoremap <leader>ta <cmd>:ToggleTermToggleAll<cr>
lua << EOF
local lib = require("nvim-tree.lib")
local view = require("nvim-tree.view")
local function collapse_all()
require("nvim-tree.actions.tree-modifiers.collapse-all").fn()
end
local function edit_or_open()
-- open as vsplit on current node
local action = "edit"
local node = lib.get_node_at_cursor()
-- Just copy what's done normally with vsplit
if node.link_to and not node.nodes then
require('nvim-tree.actions.node.open-file').fn(action, node.link_to)
view.close() -- Close the tree if file was opened
elseif node.nodes ~= nil then
lib.expand_or_collapse(node)
else
require('nvim-tree.actions.node.open-file').fn(action, node.absolute_path)
view.close() -- Close the tree if file was opened
end
end
local function vsplit_preview()
-- open as vsplit on current node
local action = "vsplit"
local node = lib.get_node_at_cursor()
-- Just copy what's done normally with vsplit
if node.link_to and not node.nodes then
require('nvim-tree.actions.node.open-file').fn(action, node.link_to)
elseif node.nodes ~= nil then
lib.expand_or_collapse(node)
else
require('nvim-tree.actions.node.open-file').fn(action, node.absolute_path)
end
-- Finally refocus on tree if it was lost
view.focus()
end
require'nvim-tree'.setup {
view = {
mappings = {
custom_only = false,
list = {
{ key = "l", action = "edit", action_cb = edit_or_open },
{ key = "L", action = "vsplit_preview", action_cb = vsplit_preview },
{ key = "h", action = "close_node" },
{ key = "H", action = "collapse_all", action_cb = collapse_all }
}
},
},
actions = {
open_file = {
quit_on_open = false
}
},
renderer = {
add_trailing = false,
group_empty = false,
highlight_git = false,
full_name = false,
highlight_opened_files = "none",
root_folder_modifier = ":~",
indent_width = 2,
indent_markers = {
enable = true,
inline_arrows = true,
icons = {
corner = "└",
edge = "│",
item = "│",
bottom = "─",
none = " ",
},
},
icons = {
show = {
file = false,
folder = true,
folder_arrow = false,
git = false
},
glyphs = {
folder = {
arrow_open = "▾",
arrow_closed = "▸",
default = "▸",
open = "▾",
empty = "▸",
empty_open = "▾",
symlink = "▸",
symlink_open = "▾"
}
}
}
},
}
EOF
lua require'hop'.setup {}
lua require'toggleterm'.setup {}
lua << EOF
require("nvim-autopairs").setup {}
EOF
lua << EOF
require("telescope").load_extension("yaml_schema")
require("yaml-companion").open_ui_select()
EOF
"-----------------------------------------------------------------------------
" Setting the autocomplete based on nvim-cmp
" From: https://github.com/hrsh7th/nvim-cmp
"-----------------------------------------------------------------------------
lua <<EOF
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
-- require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
-- require('snippy').expand_snippet(args.body) -- For `snippy` users.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
end,
},
window = {
-- completion = cmp.config.window.bordered(),
-- documentation = cmp.config.window.bordered(),
},
mapping = cmp.mapping.preset.insert({
['<C-j>'] = cmp.mapping.scroll_docs(-4),
['<C-k>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
["<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' }, -- For vsnip users.
-- { name = 'luasnip' }, -- For luasnip users.
-- { name = 'ultisnips' }, -- For ultisnips users.
-- { name = 'snippy' }, -- For snippy users.
}, {
{ name = 'buffer' },
})
})
-- Set configuration for specific filetype.
cmp.setup.filetype('gitcommit', {
sources = cmp.config.sources({
{ name = 'cmp_git' }, -- You can specify the `cmp_git` source if you were installed it.
}, {
{ name = 'buffer' },
})
})
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
-- Set up lspconfig.
--local capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
-- Replace <YOUR_LSP_SERVER> with each lsp server you've enabled.
--require('lspconfig')['<YOUR_LSP_SERVER>'].setup {
--capabilities = capabilities
--}
EOF
"-----------------------------------------------------------------------------
" Helpful general settings for Scala
" From: https://github.com/scalameta/nvim-metals/discussions/39
"-----------------------------------------------------------------------------
"-----------------------------------------------------------------------------
" nvim-lsp Mappings
"-----------------------------------------------------------------------------
nnoremap <silent> gf <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> gh <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> gi <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> gds <cmd>lua vim.lsp.buf.document_symbol()<CR>
nnoremap <silent> gws <cmd>lua vim.lsp.buf.workspace_symbol()<CR>
nnoremap <silent> <leader>rn <cmd>lua vim.lsp.buf.rename()<CR>
nnoremap <silent> <leader>f <cmd>lua vim.lsp.buf.formatting()<CR>
nnoremap <silent> <leader>ca <cmd>lua vim.lsp.buf.code_action()<CR>
nnoremap <silent> <leader>ws <cmd>lua require'metals'.worksheet_hover()<CR>
nnoremap <silent> <leader>a <cmd>lua require'metals'.open_all_diagnostics()<CR>
nnoremap <silent> <space>d <cmd>lua vim.lsp.diagnostic.set_loclist()<CR>
nnoremap <silent> [c <cmd>lua vim.lsp.diagnostic.goto_prev { wrap = false }<CR>
nnoremap <silent> ]c <cmd>lua vim.lsp.diagnostic.goto_next { wrap = false }<CR>
"-----------------------------------------------------------------------------
" nvim-metals setup with a few additions such as nvim-completions
"-----------------------------------------------------------------------------
:lua << EOF
vim.opt_global.completeopt = { "menuone", "noinsert", "noselect" }
vim.opt_global.shortmess:remove("F"):append("c")
metals_config = require'metals'.bare_config()
metals_config.settings = {
bloopSbtAlreadyInstalled = true,
showImplicitArguments = true,
showImplicitConversionsAndClasses = true,
showInferredType = true,
excludedPackages = {
"akka.actor.typed.javadsl",
"com.github.swagger.akka.javadsl"
}
}
metals_config.init_options.statusBarProvider = "on"
local capabilities = vim.lsp.protocol.make_client_capabilities()
metals_config.capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
local nvim_metals_group = vim.api.nvim_create_augroup("nvim-metals", { clear = true })
vim.api.nvim_create_autocmd("FileType", {
pattern = { "scala", "sbt", "java" },
callback = function()
require("metals").initialize_or_attach(metals_config)
end,
group = nvim_metals_group,
})
EOF
if has('nvim-0.5')
augroup lsp
au!
au FileType scala,sbt lua require('metals').initialize_or_attach(metals_config)
augroup end
endif
" Needed for compltions _only_ if you aren't using completion-nvim
" autocmd FileType scala setlocal omnifunc=v:lua.vim.lsp.omnifunc
"-----------------------------------------------------------------------------
" Troubleshoot
"-----------------------------------------------------------------------------
" Run the following command to ingerate metals with telescope
" :lua require"telescope".extensions.metals.commands()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment