change init.vim

This commit is contained in:
Jay 2021-11-24 20:35:29 +08:00
parent 80486f764b
commit b7781f1ba7

View File

@ -1,15 +1,39 @@
" Specify a directory for plugins
" - For Neovim: stdpath('data') . '/plugged'
" - Avoid using standard Vim directory names like 'plugin'
call plug#begin(stdpath('data').'/plugged')
"*****************************************************************************
""" Vim-Plug core
"*****************************************************************************
let vimplug_exists=expand('~/.config/nvim/autoload/plug.vim')
let curl_exists=expand('curl')
if !filereadable(vimplug_exists)
if !executable(curl_exists)
echoerr "You have to install curl or first install vim-plug yourself!"
execute "q!"
endif
echo "Installing Vim-Plug..."
echo ""
silent exec "!"curl_exists" -fLo " . shellescape(vimplug_exists) . " --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
let g:not_finish_vimplug = "yes"
autocmd VimEnter * PlugInstall
endif
" Required:
call plug#begin(expand('~/.config/nvim/plugged'))
" Make sure you use single quotes
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-lua/completion-nvim'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
" For vsnip users.
Plug 'hrsh7th/cmp-vsnip'
Plug 'hrsh7th/vim-vsnip'
Plug 'tomasr/molokai'
Plug 'scrooloose/nerdcommenter'
Plug 'vim-scripts/DrawIt'
Plug 'easymotion/vim-easymotion'
Plug 'mattn/emmet-vim'
Plug 'fatih/vim-go', { 'do': ':GoUpdateBinaries' }
@ -18,10 +42,23 @@ Plug 'pangloss/vim-javascript'
" golang install go get -u github.com/jstemmer/gotags
Plug 'majutsushi/tagbar'
Plug 'w0rp/ale'
Plug 'connorholyday/vim-snazzy'
Plug 'hzchirs/vim-material'
Plug 'kadekillary/Turtles'
Plug 'phanviet/vim-monokai-pro'
Plug 'sickill/vim-monokai'
Plug 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'kien/tabman.vim'
" defx file explorer
" require python package pynvim
" install `pip3 install --user pynvim`
Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
Plug 'vim-airline/vim-airline'
Plug 'kien/tabman.vim'
" for git
Plug 'tpope/vim-fugitive'
Plug 'christoomey/vim-conflicted'
@ -32,23 +69,19 @@ Plug 'inkarkat/vim-mark'
Plug 'rking/ag.vim'
Plug 'terryma/vim-multiple-cursors'
Plug 'vim-scripts/TaskList.vim'
Plug 'rust-lang/rust.vim'
" temp plugin
Plug 'tpope/vim-surround'
Plug 'buoto/gotests-vim'
" color scheme
Plug 'chr4/nginx.vim'
Plug 'cespare/vim-toml'
Plug 'zah/nim.vim'
Plug 'rust-lang/rust.vim'
Plug 'danilo-augusto/vim-afterglow'
Plug 'vim-scripts/TaskList.vim'
Plug 'google/vim-jsonnet'
Plug 'github/copilot.vim'
" defx explorer
if has('nvim')
Plug 'Shougo/defx.nvim', { 'do': ':UpdateRemotePlugins' }
else
Plug 'Shougo/defx.nvim'
Plug 'roxma/nvim-yarp'
Plug 'roxma/vim-hug-neovim-rpc'
endif
" Initialize plugin system
call plug#end()
syntax on
@ -57,7 +90,6 @@ set tabstop=2
set shiftwidth=2
set expandtab
set nofoldenable
set pastetoggle=<F2>
" always show status
set laststatus=2
@ -71,7 +103,8 @@ set nowrap
" enable backspace
set backspace=indent,eol,start
set encoding=utf-8
" set font
set completeopt=menu,menuone,noselect
" set guifont=Hack\ Nerd\ Font:h11
set background=dark
@ -87,8 +120,11 @@ function! AdaptColorscheme()
highlight SignColumn ctermbg=none
endfunction
autocmd ColorScheme * call AdaptColorscheme()
" colorscheme turtles
colorscheme afterglow
" define leader key
let mapleader=";"
filetype indent on
@ -96,7 +132,6 @@ filetype indent on
filetype on
" 根據檔案類型載入plugin
filetype plugin on
autocmd BufWritePost $MYVIMRC source $MYVIMRC
" split window
nmap <leader>sw <c-w>
@ -104,49 +139,25 @@ nmap <leader>sww <c-w>k
nmap <leader>sws <c-w>j
nmap <leader>swa <c-w>h
nmap <leader>swd <c-w>l
nmap <leader>aa gT
nmap <leader>dd gt
nnoremap <silent> <leader>gd <cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <leader>gt <cmd>tab split<CR><cmd>lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <leader>p <cmd>lua vim.lsp.buf.hover()<CR>
nnoremap <silent> <leader>gr <cmd>lua vim.lsp.buf.references()<CR>
nnoremap <silent> <leader>i <cmd>lua vim.lsp.buf.implementation()<CR>
nnoremap <silent> <leader>gs <cmd>split \| lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <leader>gv <cmd>vsplit \| lua vim.lsp.buf.definition()<CR>
nnoremap <silent> <leader>grn <cmd>lua vim.lsp.buf.rename()<CR>
" initialize lsp
lua require'lspconfig'.gopls.setup{on_attach=require'completion'.on_attach}
lua require'lspconfig'.rust_analyzer.setup{on_attach=require'completion'.on_attach}
lua require'lspconfig'.tsserver.setup{on_attach=require'completion'.on_attach}
" autocomplete setting
" --------------------
let g:completion_enable_auto_popup = 0
let g:completion_trigger_character = ['.', '::']
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
function! TabCloseRight(bang)
let cur=tabpagenr()
while cur < tabpagenr('$')
exe 'tabclose' . a:bang . ' ' . (cur + 1)
endwhile
endfunction
" Use <Tab> and <S-Tab> to navigate through popup menu
inoremap <expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Set completeopt to have a better completion experience
set completeopt=menuone,noinsert,noselect
function! TabCloseLeft(bang)
while tabpagenr() > 1
exe 'tabclose' . a:bang . ' 1'
endwhile
endfunction
" Avoid showing message extra message when using completion
set shortmess+=c
imap <silent> <c-p> <Plug>(completion_trigger)
imap <tab> <Plug>(completion_smart_tab)
imap <s-tab> <Plug>(completion_smart_s_tab)
" --------------------
command! -bang Tabcloseright call TabCloseRight('<bang>')
command! -bang Tabcloseleft call TabCloseLeft('<bang>')
" defx settings
call defx#custom#option('_', {
@ -225,6 +236,12 @@ endfunction
" tagbar
nmap <F8> :TagbarToggle<CR>
nmap <F9> :%!jq .<CR>
" NeoComplete
let g:neocomplete#enable_at_startup = 1
let g:airline_powerline_fonts = 1
" <Leader>f{char} to move to {char}
map <Leader>f <Plug>(easymotion-bd-f)
@ -240,11 +257,12 @@ nmap <Leader>w <Plug>(easymotion-overwin-w)
" lint
let g:ale_linters = {
\ 'javascript': ['standard'],
\ 'javascript': ['eslint'],
\ 'go': ['gopls'],
\ 'rust': ['analyzer'],
\}
let g:ale_fixers = {'javascript': ['standard']}
let g:ale_fixers = {'javascript': ['prettier']}
let g:ale_linters_explicit = 1
let g:ale_lint_on_save = 1
let g:ale_fix_on_save = 1
nmap <leader>= <Plug>(ale_fix)
@ -281,6 +299,9 @@ let g:tagbar_type_go = {
\ 'ctagsargs' : '-sort -silent'
\ }
" vim-go setting
autocmd FileType go nmap tgd <Plug>(go-def-tab)
autocmd FileType go nmap <leader>err <Plug>(go-iferr)
let g:go_fmt_fail_silently = 1
let g:go_fmt_command = "goimports"
let g:go_def_mode = 'godef'
@ -319,3 +340,87 @@ let g:multi_cursor_skip_key = '<C-x>'
let g:multi_cursor_quit_key = '<Esc>'
let g:javascript_plugin_jsdoc = 1
lua << EOF
local nvlsp = require'lspconfig'
-- Add additional capabilities supported by nvim-cmp
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- 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', '<leader>gd', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', '<leader>gt', '<cmd>tab split<CR><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', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts)
-- buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<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', '<leader>gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', '<leader>ge', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts)
-- buf_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
-- buf_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
-- buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts)
-- buf_set_keymap('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
end
nvlsp['gopls'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
nvlsp['tsserver'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
nvlsp['rust_analyzer'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
mapping = {
['<CR>'] = cmp.mapping.confirm({
-- behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
-- ['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
},
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.
-- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
-- require'snippy'.expand_snippet(args.body) -- For `snippy` users.
end,
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
}, {
{name = 'buffer'},
}),
}
EOF