"***************************************************************************** """ 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')) Plug 'neovim/nvim-lspconfig' 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' } Plug 'pangloss/vim-javascript' " tagbar " 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' " 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' " for mark Plug 'inkarkat/vim-ingo-library' Plug 'inkarkat/vim-mark' Plug 'rking/ag.vim' Plug 'terryma/vim-multiple-cursors' " temp plugin Plug 'tpope/vim-surround' Plug 'buoto/gotests-vim' 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' call plug#end() syntax on set number set tabstop=2 set shiftwidth=2 set expandtab set nofoldenable set pastetoggle= " always show status set laststatus=2 " show cursor position set ruler set cursorline set cursorcolumn set hlsearch " no wrap line set nowrap " enable backspace set backspace=indent,eol,start set encoding=utf-8 set completeopt=menu,menuone,noselect " set guifont=Hack\ Nerd\ Font:h11 set background=dark function! AdaptColorscheme() highlight clear CursorLine highlight Normal ctermbg=none highlight LineNr ctermbg=none highlight Folded ctermbg=none highlight NonText ctermbg=none highlight SpecialKey ctermbg=none highlight VertSplit ctermbg=none highlight SignColumn ctermbg=none endfunction autocmd ColorScheme * call AdaptColorscheme() " colorscheme turtles colorscheme afterglow " define leader key let mapleader=";" filetype indent on " 開啟檔案類型偵測 filetype on " 根據檔案類型載入plugin filetype plugin on " split window nmap sw nmap sww k nmap sws j nmap swa h nmap swd l nmap aa gT nmap dd gt function! TabCloseRight(bang) let cur=tabpagenr() while cur < tabpagenr('$') exe 'tabclose' . a:bang . ' ' . (cur + 1) endwhile endfunction function! TabCloseLeft(bang) while tabpagenr() > 1 exe 'tabclose' . a:bang . ' 1' endwhile endfunction command! -bang Tabcloseright call TabCloseRight('') command! -bang Tabcloseleft call TabCloseLeft('') " defx settings call defx#custom#option('_', { \ 'winwidth': 40, \ 'split': 'vertical', \ 'direction': 'topleft', \ 'buffer_name': '', \ 'toggle': 1, \ 'resume': 1, \ }) nmap :Defx nmap me :Defx autocmd FileType defx call s:defx_my_settings() function! s:defx_my_settings() abort " Define mappings nnoremap \ defx#is_directory() ? \ defx#do_action('open_tree', 'toggle') : \ defx#do_action('drop') nnoremap T \ defx#do_action('open', 'tabe') nnoremap s \ defx#do_action('drop', 'vsplit') nnoremap mc \ defx#do_action('copy') nnoremap mm \ defx#do_action('move') nnoremap mp \ defx#do_action('paste') nnoremap P \ defx#do_action('preview') nnoremap o \ defx#do_action('open_tree', 'toggle') nnoremap ma \ defx#do_action('new_file') nnoremap C \ defx#do_action('toggle_columns', \ 'mark:indent:icon:filename:type:size:time') nnoremap S \ defx#do_action('toggle_sort', 'time') nnoremap md \ defx#do_action('remove') nnoremap mr \ defx#do_action('rename') nnoremap ! \ defx#do_action('execute_command') nnoremap x \ defx#do_action('execute_system') nnoremap yy \ defx#do_action('yank_path') nnoremap . \ defx#do_action('toggle_ignored_files') nnoremap ; \ defx#do_action('repeat') nnoremap h \ defx#do_action('cd', ['..']) nnoremap ~ \ defx#do_action('cd') nnoremap q \ defx#do_action('quit') nnoremap \ defx#do_action('toggle_select') . 'j' nnoremap * \ defx#do_action('toggle_select_all') nnoremap j \ line('.') == line('$') ? 'gg' : 'j' nnoremap k \ line('.') == 1 ? 'G' : 'k' nnoremap r \ defx#do_action('redraw') nnoremap \ defx#do_action('print') nnoremap cd \ defx#do_action('change_vim_cwd') endfunction " tagbar nmap :TagbarToggle nmap :%!jq . " NeoComplete let g:neocomplete#enable_at_startup = 1 let g:airline_powerline_fonts = 1 " f{char} to move to {char} map f (easymotion-bd-f) nmap f (easymotion-overwin-f) " s{char}{char} to move to {char}{char} nmap s (easymotion-overwin-f2) " Move to line map L (easymotion-bd-jk) nmap L (easymotion-overwin-line) " Move to word map w (easymotion-bd-w) nmap w (easymotion-overwin-w) " lint let g:ale_linters = { \ 'javascript': ['eslint'], \ 'go': ['gopls'], \ 'rust': ['analyzer'], \} 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 = (ale_fix) " NERDCommenter let g:NERDSpaceDelims=1 let g:NERDDefaultAlign='left' let g:tagbar_type_go = { \ 'ctagstype' : 'go', \ 'kinds' : [ \ 'p:package', \ 'i:imports:1', \ 'c:constants', \ 'v:variables', \ 't:types', \ 'n:interfaces', \ 'w:fields', \ 'e:embedded', \ 'm:methods', \ 'r:constructor', \ 'f:functions' \ ], \ 'sro' : '.', \ 'kind2scope' : { \ 't' : 'ctype', \ 'n' : 'ntype' \ }, \ 'scope2kind' : { \ 'ctype' : 't', \ 'ntype' : 'n' \ }, \ 'ctagsbin' : 'gotags', \ 'ctagsargs' : '-sort -silent' \ } " vim-go setting autocmd FileType go nmap tgd (go-def-tab) autocmd FileType go nmap err (go-iferr) let g:go_fmt_fail_silently = 1 let g:go_fmt_command = "goimports" let g:go_def_mode = 'godef' let g:go_decls_includes = "func,type" let g:go_highlight_types = 1 let g:go_highlight_fields = 1 let g:go_highlight_functions = 1 let g:go_highlight_function_calls = 1 let g:go_highlight_operators = 1 let g:go_highlight_extra_types = 1 " for rust-vim let g:rust_recommended_style = 0 let g:rustfmt_autosave = 1 let g:syntastic_rust_checkers = ['cargo'] let g:airline#extensions#tabline#enabled = 1 let g:airline#extensions#tabline#show_buffers = 0 let g:airline#extensions#tabline#show_splits = 0 let g:airline#extensions#tabline#show_tabs = 1 let g:airline#extensions#tabline#show_tab_nr = 0 let g:airline#extensions#tabline#show_tab_type = 0 let g:airline#extensions#tabline#close_symbol = '×' let g:airline#extensions#tabline#show_close_button = 0 let g:multi_cursor_use_default_mapping=0 " Default mapping let g:multi_cursor_start_word_key = "" let g:multi_cursor_select_all_word_key = '' let g:multi_cursor_start_key = "g" let g:multi_cursor_select_all_key = 'g' let g:multi_cursor_next_key = "" " let g:multi_cursor_prev_key = '' let g:multi_cursor_skip_key = '' let g:multi_cursor_quit_key = '' 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 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', 'lua vim.lsp.buf.declaration()', opts) buf_set_keymap('n', 'gd', 'lua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'gt', 'tab splitlua vim.lsp.buf.definition()', opts) buf_set_keymap('n', 'K', 'lua vim.lsp.buf.hover()', opts) -- buf_set_keymap('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) buf_set_keymap('n', '', 'lua vim.lsp.buf.signature_help()', opts) -- buf_set_keymap('n', 'wa', 'lua vim.lsp.buf.add_workspace_folder()', opts) -- buf_set_keymap('n', 'wr', 'lua vim.lsp.buf.remove_workspace_folder()', opts) -- buf_set_keymap('n', 'wl', 'lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))', opts) buf_set_keymap('n', 'D', 'lua vim.lsp.buf.type_definition()', opts) buf_set_keymap('n', 'rn', 'lua vim.lsp.buf.rename()', opts) buf_set_keymap('n', 'ca', 'lua vim.lsp.buf.code_action()', opts) buf_set_keymap('n', 'gr', 'lua vim.lsp.buf.references()', opts) buf_set_keymap('n', 'ge', 'lua vim.lsp.diagnostic.show_line_diagnostics()', opts) -- buf_set_keymap('n', '[d', 'lua vim.lsp.diagnostic.goto_prev()', opts) -- buf_set_keymap('n', ']d', 'lua vim.lsp.diagnostic.goto_next()', opts) -- buf_set_keymap('n', 'q', 'lua vim.lsp.diagnostic.set_loclist()', opts) -- buf_set_keymap('n', 'f', 'lua vim.lsp.buf.formatting()', 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 = { [''] = cmp.mapping.confirm({ -- behavior = cmp.ConfirmBehavior.Insert, select = true, }), -- [''] = 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