196 lines
5.6 KiB
Lua
196 lines
5.6 KiB
Lua
---- Aliases ----
|
|
local cmd = vim.cmd
|
|
local g = vim.g
|
|
local opt = vim.opt
|
|
local o = vim.o
|
|
|
|
---- General Config ----
|
|
opt.mouse = 'a'
|
|
opt.tabstop = 4
|
|
opt.shiftwidth = 4
|
|
opt.number = true
|
|
opt.breakindent = true
|
|
--vim.o.inccomand = 'nosplit'
|
|
opt.showmatch = true
|
|
opt.ignorecase = true
|
|
opt.smartcase = true
|
|
opt.joinspaces = false
|
|
opt.showmode = false
|
|
opt.hidden = true
|
|
opt.backup = false
|
|
opt.writebackup = false
|
|
opt.swapfile = false
|
|
opt.shortmess:append({ I = true })
|
|
-- whichwrap -- left/right keys can traverse up/down
|
|
--opt.whichwrap = {'<','>','[',']'}
|
|
opt.cmdheight = 2
|
|
opt.showcmd = true
|
|
opt.showcmd = true
|
|
g.mapleader = ' '
|
|
|
|
---- Terminal ----
|
|
cmd 'autocmd TermOpen * setlocal nonumber'
|
|
|
|
---- Theming ----
|
|
opt.termguicolors = true
|
|
opt.background = 'dark'
|
|
g.gruvbox_italic = true
|
|
cmd 'colorscheme gruvbox'
|
|
opt.listchars = {
|
|
eol = '↲' ,
|
|
tab = '▶▹',
|
|
nbsp = '␣',
|
|
extends = '…',
|
|
trail = '•'}
|
|
-- vim-airline config ---
|
|
g.airline_powerline_fonts = true
|
|
g.airline_theme = 'powerlineish'
|
|
g['airline#extensions#tabline#enabled'] = 1
|
|
g['airline#extensions#tabline#left_sep'] = ' '
|
|
g['airline#extensions#tabline#left_alt_sep'] = '|'
|
|
|
|
---- Maps ----
|
|
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
|
|
map('!','<C-BS>','<C-w>')
|
|
map('v','>','>gv')
|
|
map('v','<','<gv')
|
|
map('n','<C-L>',':nohlsearch<CR>')
|
|
|
|
---- Treesitter ----
|
|
local ts = require 'nvim-treesitter.configs'
|
|
ts.setup {
|
|
ensure_installed = {
|
|
'bash',
|
|
'c',
|
|
'cpp',
|
|
'css',
|
|
'dockerfile',
|
|
'dot',
|
|
'go',
|
|
'html',
|
|
'http',
|
|
'javascript',
|
|
'json',
|
|
'latex',
|
|
'markdown',
|
|
'perl',
|
|
'php',
|
|
'python',
|
|
'rust',
|
|
'scss',
|
|
'toml',
|
|
'typescript',
|
|
'vim',
|
|
'yaml',
|
|
},
|
|
highlight = {enable = true, indent = true}}
|
|
|
|
---- LSP ----
|
|
local lsp = require 'lspconfig'
|
|
|
|
-- 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)
|
|
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
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
-- Mappings.
|
|
local opts = { noremap=true, silent=true }
|
|
|
|
-- 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', '<Leader>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
|
buf_set_keymap('n', '<Leader>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
|
buf_set_keymap('n', '<Leader>ca', '<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', '<Leader>e', '<cmd>lua vim.diagnostic.open_float()<CR>', opts)
|
|
buf_set_keymap('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', opts)
|
|
buf_set_keymap('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', opts)
|
|
buf_set_keymap('n', '<Leader>q', '<cmd>lua vim.diagnostic.setloclist()<CR>', opts)
|
|
buf_set_keymap('n', '<F3>', '<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 = { 'gopls', 'rust_analyzer', 'pylsp' }
|
|
for _, server in ipairs(servers) do
|
|
lsp[server].setup {
|
|
on_attach = on_attach,
|
|
flags = {
|
|
debounce_text_changes = 150,
|
|
}
|
|
}
|
|
end
|
|
|
|
-- Auto format on save
|
|
vim.cmd [[autocmd BufWritePre * lua vim.lsp.buf.formatting_sync()]]
|
|
|
|
---- Plugins ----
|
|
---- ale
|
|
g.ale_linters = {
|
|
bash = {'shellcheck'},
|
|
c = {},
|
|
cpp = {},
|
|
css = {'stylelint'},
|
|
go = {'gobuild', 'golangci-lint'},
|
|
html = {'tidy'},
|
|
javascript = {'eslint'},
|
|
python = {'flake8'},
|
|
tex = {'texlab'},
|
|
vim = {'vint'},
|
|
zsh = {'shell', 'shellcheck'},
|
|
}
|
|
g.ale_sign_error = '✘'
|
|
g.ale_sign_warning = '▲'
|
|
g.ale_set_highlights = 1
|
|
-- Go
|
|
g.ale_go_golangci_lint_options = ''
|
|
g.ale_go_golangci_lint_package = 1
|
|
map('n', '[W', '<Plug>(ale_first)')
|
|
map('n', '[w', '<Plug>(ale_previous_wrap)')
|
|
map('n', ']w', '<Plug>(ale_next_wrap)')
|
|
map('n', ']W', '<Plug>(ale_last)')
|
|
---- completion-nvim
|
|
-- Use completion-nvim in every buffer
|
|
g.completion_enable_snippet = 'UltiSnips'
|
|
opt.completeopt = {'menuone', 'noinsert', 'noselect'}
|
|
g.completion_chain_complete_list = {
|
|
default = {
|
|
{ complete_items = { 'lsp', 'snippet', 'buffer' } },
|
|
{ mode = { '<c-p>' } },
|
|
{ mode = { '<c-n>' } }
|
|
},
|
|
}
|
|
cmd [[autocmd FileType *\(TelescopePrompt\)\@<! lua require'completion'.on_attach()]]
|
|
---- Ultisnips
|
|
g.UltiSnipsSnippetDirectories = {'UltiSnips', 'mysnippets'}
|
|
---- vim-signify
|
|
g.signify_vcs_list = {'git'}
|
|
---- vim-markdown
|
|
g.vim_markdown_no_default_key_mappings = 1
|
|
g.vim_markdown_folding_disabled = 1
|
|
g.vim_markdown_toml_frontmatter = 1
|
|
---- Telescope
|
|
require('telescope').setup{
|
|
defaults = {
|
|
file_sorter = require'telescope.sorters'.get_fzy_sorter,
|
|
file_ignore_patterns = {"%.avif", "%.jpg", "%.pdf", "%.png", "%.webp"},
|
|
}
|
|
}
|
|
map('n', '<Leader>f', ':Telescope fd<CR>')
|
|
map('n', '<Leader>b', ':Telescope buffers<CR>')
|
|
map('n', '<Leader>/', ':Telescope current_buffer_fuzzy_find<CR>')
|
|
--map('n', '<Leader>*', ':Telescope grep_string<CR>')
|
|
map('n', '<Leader>g', ':Telescope live_grep<CR>')
|
|
map('n', '<Leader>cg', ':Telescope grep_string<CR>')
|