Last active
January 10, 2022 01:58
-
-
Save tan86/98d6d9727d95dc1cbb7439cc05e7f57f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
----[[ Helpers ]]---- | |
vim.cmd 'packadd paq-nvim' | |
local lsp = require 'lspconfig' | |
local paq = require 'paq-nvim'.paq | |
local scopes = {o = vim.o, b = vim.bo, w = vim.wo} | |
local function map(mode, lhs, rhs, opts) | |
local options = {noremap = true, silent = true} | |
if opts then options = vim.tbl_extend('force', options, opts) end | |
vim.api.nvim_set_keymap(mode, lhs, rhs, options) | |
end | |
local function opt(scope, key, value) | |
scopes[scope][key] = value | |
if scope ~= 'o' then scopes['o'][key] = value end | |
end | |
local t = function(str) | |
return vim.api.nvim_replace_termcodes(str, true, true, true) | |
end | |
local check_back_space = function() | |
local col = vim.fn.col('.') - 1 | |
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then | |
return true | |
else | |
return false | |
end | |
end | |
_G.tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-n>" | |
elseif check_back_space() then | |
return t "<Tab>" | |
else | |
return vim.fn['compe#complete']() | |
end | |
end | |
_G.s_tab_complete = function() | |
if vim.fn.pumvisible() == 1 then | |
return t "<C-p>" | |
else | |
return t "<S-Tab>" | |
end | |
end | |
-- General Settings | |
vim.g.mapleader = ',' | |
local indent = 4 | |
-- vim.cmd([[colorscheme gruvbox]]) -- Set colorscheme | |
-- opt('b', 'expandtab', true) -- Use spaces instead of tabs | |
opt('b', 'shiftwidth', indent) -- Size of an indent | |
opt('b', 'smartindent', true) -- Smart indent | |
opt('b', 'autoindent', true) -- Auto indent | |
opt('b', 'tabstop', indent) -- No. of spaces for tabs | |
opt('o', 'completeopt', 'menuone,noinsert,noselect') -- Completion options | |
opt('o', 'showtabline', 2) -- | |
opt('o', 'tabline', '%m %t') -- | |
opt('o', 'encoding', 'utf-8') -- | |
opt('o', 'fileencoding', 'utf-8') -- | |
opt('o', 'hidden', true) -- Enable modified buffers in BG | |
opt('o', 'ignorecase', true) -- Ignore case | |
opt('o', 'joinspaces', false) -- No double spaces with join after a '.','?','!' | |
opt('o', 'scrolloff', 4) -- Lines of context | |
opt('o', 'sidescrolloff', 8) -- Columns of context | |
opt('o', 'shiftround', true) -- Round indent | |
opt('o', 'smartcase', true) -- Don't ignore case with capitals | |
opt('o', 'splitbelow', true) -- new window below current | |
opt('o', 'splitright', true) -- new window right current | |
opt('o', 'termguicolors', true) -- True color support | |
opt('o', 'wildmode', 'list:longest') -- Command-line completion mode | |
opt('o', 'autochdir', true) -- Vim's working dir will be the same as your working dir | |
opt('o', 'clipboard', 'unnamedplus') -- Use systems clipboard | |
opt('o', 'background', 'dark') -- Set background dark | |
opt('w', 'list', true) -- Show invisible characters (tabs ...) | |
opt('w', 'number', true) -- Print line number | |
opt('w', 'relativenumber', true) -- Relative line number | |
opt('w', 'wrap', false) -- Disable line wrap | |
opt('w', 'signcolumn', 'yes:2') -- | |
-- Plugins | |
paq {'savq/paq-nvim', opt=true} | |
paq {'neovim/nvim-lspconfig'} | |
paq {'hrsh7th/vim-vsnip'} | |
paq {'hrsh7th/nvim-compe'} | |
paq {'morhetz/gruvbox'} | |
paq {'jiangmiao/auto-pairs'} | |
paq {'chrisbra/unicode.vim'} | |
paq {'folke/which-key.nvim'} | |
paq {'vim-airline/vim-airline'} | |
require("which-key").setup {} | |
-- Mappings | |
map('n', '<Space>', '<NOP>') -- Unmap space key | |
map('n', '<Leader>h', ':noh<CR>') -- Clear search highlights | |
map('n', '<Leader>e', ':NvimTreeToggle<CR>') -- NvimTreeToggle | |
-- Tab Completion | |
map('i', '<Tab>', 'v:lua.tab_complete()', {expr = true}) | |
map('s', '<Tab>', 'v:lua.tab_complete()', {expr = true}) | |
map('i', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true}) | |
map('s', '<S-Tab>', 'v:lua.s_tab_complete()', {expr = true}) | |
-- for better Movement between Windows | |
map('n', '<C-h>', '<C-w>h') | |
map('n', '<C-l>', '<C-w>l') | |
map('n', '<C-j>', '<C-w>j') | |
map('n', '<C-k>', '<C-w>k') | |
-- for better Movement between Buffers | |
map('n', '<Tab>', ':bnext<CR>') | |
map('n', '<S-Tab>', ':bprevious<CR>') | |
-- Resize Windows | |
map('n', '<M-j>', ':res -2<CR>') | |
map('n', '<M-k>', ':res +2<CR>') | |
map('n', '<M-h>', ':vertical res +2<CR>') | |
map('n', '<M-l>', ':vertical res -2<CR>') | |
-- Compe | |
map('i', '<C-Space>', 'compe#complete()', {expr = true}) | |
map('i', '<CR>', 'compe#confirm(\'<CR>\')', {expr = true}) | |
map('i', '<C-e>', 'compe#close(\'<C-e>\')', {expr = true}) | |
-- LSP | |
local on_attach = function(client, bufnr) | |
local function buf_map(mode, lhs, rhs, opts) | |
local options = {noremap = true, silent = true} | |
if opts then options = vim.tbl_extend('force', options, opts) end | |
vim.api.nvim_buf_set_keymap(bufnr, mode, lhs, rhs, options) | |
end | |
buf_map('n', 'gd', ':lua vim.lsp.buf.declaration()<CR>') | |
buf_map('n', 'gi', ':lua vim.lsp.buf.implementation()<CR>') -- Go to implementation | |
buf_map('n', 'gr', ':lua vim.lsp.buf.references()<CR>') -- Go to references | |
buf_map('n', '[d', ':lua vim.lsp.diagnostic.goto_prev()<CR>') -- Go to | |
buf_map('n', ']d', ':lua vim.lsp.diagnostic.goto_next()<CR>') -- Go to | |
buf_map('n', '<Leader>er', ':lua vim.lsp.diagnostic.show_line_diagnostics()<CR>') | |
buf_map('n', '<Leader>q', ':lua vim.lsp.diagnostic.set_loclist()<CR>') | |
buf_map('n', '<Leader>k', ':lua vim.lsp.buf.hover()<CR>') | |
buf_map('n', '<C-k>', ':lua vim.lsp.buf.signature_help()<CR>') | |
buf_map('n', '<Leader>rn', ':lua vim.lsp.buf.rename()<CR>') | |
buf_map('n', '<Leader>ca', ':lua vim.lsp.buf.code_action()<CR>') | |
-- Formatting | |
if client.resolved_capabilities.document_formatting then | |
buf_map('n', '<Leader>f', ':lua vim.lsp.buf.formatting()<CR>') | |
end | |
if client.resolved_capabilities.document_range_formatting then | |
buf_map('v', '<Leader>f', ':lua vim.lsp.buf.range_formatting()<CR>') | |
end | |
-- autocmds highlighting | |
if client.resolved_capabilities.document_highlight then | |
vim.api.nvim_exec([[ | |
hi LspReferenceRead cterm=bold ctermbg=red guibg=LightYellow | |
hi LspReferenceText cterm=bold ctermbg=red guibg=LightYellow | |
hi LspReferenceWrite cterm=bold ctermbg=red guibg=LightYellow | |
augroup lsp_doc_highlight | |
autocmd! * <buffer> | |
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight() | |
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references() | |
augroup END | |
]], false) | |
end | |
end | |
--- LSP-config | |
local capabilities = vim.lsp.protocol.make_client_capabilities() | |
capabilities.textDocument.completion.completionItem.snippetSupport = true | |
capabilities.textDocument.completion.completionItem.resolveSupport = { | |
properties = { | |
'documentation', | |
'detail', | |
'additionalTextEdits', | |
} | |
} | |
local servers = { "cmake", "pyls", "html", "cssls", "rust_analyzer" } | |
for _, ls in ipairs(servers) do | |
lsp[ls].setup { | |
on_attach = on_attach, | |
capabilities = capabilities, | |
} | |
end | |
-- C, C++ | |
lsp.clangd.setup { | |
on_attach = on_attach, | |
capabilities = capabilities, | |
cmd ={ | |
"clangd" | |
,"--background-index" | |
,"--pch-storage=memory" | |
,"--suggest-missing-includes" | |
,"--clang-tidy" | |
,"--all-scopes-completion" | |
,"--completion-style=detailed" | |
,"--header-insertion=iwyu" | |
}, | |
} | |
--Compe-config | |
require'compe'.setup { | |
autocomplete = true; | |
debug = false; | |
documentation = true; | |
enabled = true; | |
incomplete_delay = 400; | |
max_abbr_width = 100; | |
max_kind_width = 100; | |
max_menu_width = 100; | |
min_length = 1; | |
preselect = 'enable'; | |
source_timeout = 200; | |
throttle_time = 80; | |
source = { | |
buffer = true; | |
calc = true; | |
nvim_lsp = true; | |
nvim_lua = true; | |
path = true; | |
spell = true; | |
tags = true; | |
vsnip = true; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment