Skip to content

Instantly share code, notes, and snippets.

@cocoastorm
Last active May 11, 2022 23:51
Show Gist options
  • Save cocoastorm/05decbca768611203a76645f49cf70e8 to your computer and use it in GitHub Desktop.
Save cocoastorm/05decbca768611203a76645f49cf70e8 to your computer and use it in GitHub Desktop.
neovim config
" =================================================================
" settings
" =================================================================
" middle-click paste with mouse
set mouse=v
" number of columns occupied by tab character
set tabstop=2
" multiple spaces as tabstops so <BS> does the right thing
set softtabstop=2
" width for autoindents
set shiftwidth=2
" tabs to spaces
set expandtab
" =================================================================
" plugins
" =================================================================
call plug#begin()
Plug 'williamboman/nvim-lsp-installer'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSUpdate' }
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-sleuth'
Plug 'junegunn/vim-easy-align'
" File Explorer
Plug 'kyazdani42/nvim-web-devicons'
Plug 'projekt0n/circles.nvim'
Plug 'kyazdani42/nvim-tree.lua'
" telescope
Plug 'nvim-lua/plenary.nvim'
Plug 'nvim-telescope/telescope.nvim'
Plug 'nvim-telescope/telescope-fzf-native.nvim', { 'do': 'make' }
" themes
Plug 'Mofiqul/dracula.nvim'
" initialize plugin system
call plug#end()
" =================================================================
" init scripts
" =================================================================
" lsp
lua << EOF
-- lsp-installer
require'nvim-lsp-installer'.setup {
ensure_installed = {
"bashls",
"ccls",
"cssls",
"gopls",
"jsonls",
"rust_analyzer",
"sumneko_lua",
"psalm",
"taplo",
"tsserver",
"yamlls",
"vls",
"vuels"
}
}
EOF
lua << EOF
-- Mappings.
-- See `:help vim.diagnostic.*` for documentation on any of the below functions
local opts = { noremap=true, silent=true }
vim.api.nvim_set_keymap('n', '<space>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
vim.api.nvim_set_keymap('n', '<space>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
-- 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)
-- Enable completion triggered by <c-x><c-o>
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
-- See `:help vim.lsp.*` for documentation on any of the below functions
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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
vim.api.nvim_buf_set_keymap(bufnr, 'n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<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', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = {
"bashls",
"ccls",
"cssls",
"gopls",
"jsonls",
"rust_analyzer",
"sumneko_lua",
"psalm",
"taplo",
"tsserver",
"yamlls",
"vuels"
}
for _, lsp in pairs(servers) do
require('lspconfig')[lsp].setup {
on_attach = on_attach,
flags = {
-- This will be the default in neovim 0.7+
debounce_text_changes = 150,
}
}
end
EOF
" treesitter
lua << EOF
require'nvim-treesitter.configs'.setup {
ensure_installed = {
"bash",
"c",
"css",
"lua",
"javascript",
"json",
"go",
"php",
"rust",
"scss",
"toml",
"vim",
"vue",
},
highlight = {
enable = true,
disable = { "vim" },
additional_vim_regex_highlighting = false,
}
}
EOF
" nvimtree
lua require'nvim-web-devicons'.setup()
lua require'nvim-tree'.setup()
" =================================================================
" keymaps
" =================================================================
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Nvim Tree Toggle
nnoremap <C-n> :NvimTreeToggle<CR>
nnoremap <leader>r :NvimTreeRefresh
nnoremap <leader>n :NvimTreeFindFile
" Telescope
" Find files using Telescope command-line sugar.
nnoremap <leader>ff <cmd>Telescope find_files<cr>
nnoremap <leader>fg <cmd>Telescope live_grep<cr>
nnoremap <leader>fb <cmd>Telescope buffers<cr>
nnoremap <leader>fh <cmd>Telescope help_tags<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment