dotfiles/home/dot_config/nvim/init.vim.tmpl

520 lines
14 KiB
Cheetah
Raw Normal View History

2023-02-25 16:18:35 +00:00
"*****************************************************************************
""" 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 'ray-x/lsp_signature.nvim'
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 'godlygeek/tabular'
Plug 'plasticboy/vim-markdown'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plug 'junegunn/fzf.vim'
Plug 'kyazdani42/nvim-web-devicons' " for file icons
Plug 'kyazdani42/nvim-tree.lua'
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'
Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
2023-03-04 07:36:06 +00:00
Plug 'codota/tabnine-nvim', { 'do': './dl_binaries.sh' }
2023-03-29 17:48:14 +00:00
Plug 'rafamadriz/neon'
2023-02-25 16:18:35 +00:00
" 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'
call plug#end()
syntax on
set number
set tabstop=2
set shiftwidth=2
set expandtab
set nofoldenable
set pastetoggle=<F2>
" always show status
set laststatus=2
" show cursor position
set ruler
set cursorline
2023-03-29 17:48:14 +00:00
" set cursorcolumn
2023-02-25 16:18:35 +00:00
set hlsearch
" no wrap line
set nowrap
" enable backspace
set backspace=indent,eol,start
set encoding=utf-8
set completeopt=menu,menuone,noselect
set noswapfile
set mouse=
" 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
2023-03-29 17:48:14 +00:00
" colorscheme afterglow
2023-02-25 16:18:35 +00:00
" define leader key
let mapleader=";"
filetype indent on
" 開啟檔案類型偵測
filetype on
" 根據檔案類型載入plugin
filetype plugin on
" split window
nmap <leader>sw <c-w>
nmap <leader>sww <c-w>k
nmap <leader>sws <c-w>j
nmap <leader>swa <c-w>h
nmap <leader>swd <c-w>l
nnoremap <leader>fl :Lines
nnoremap <leader>fb :BLines
nnoremap <leader>ff :Files
nnoremap <leader>fg :GFiles
nnoremap <leader>f? :GFiles?
nnoremap <leader>ft :Tags<cr>
nnoremap <leader>fa :Ag
nnoremap <leader>fc :Commits
nmap <leader>aa gT
nmap <leader>dd gt
nnoremap <leader>me :NvimTreeToggle<CR>
nnoremap <F3> :NvimTreeToggle<CR>
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('<bang>')
command! -bang Tabcloseleft call TabCloseLeft('<bang>')
" 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)
nmap <Leader>f <Plug>(easymotion-overwin-f)
" s{char}{char} to move to {char}{char}
nmap s <Plug>(easymotion-overwin-f2)
" Move to line
map <Leader>L <Plug>(easymotion-bd-jk)
nmap <Leader>L <Plug>(easymotion-overwin-line)
" Move to word
map <Leader>w <Plug>(easymotion-bd-w)
nmap <Leader>w <Plug>(easymotion-overwin-w)
" lint
let g:ale_linters = {
\ 'javascript': ["{{ if .nvim.js_linter }}{{- .nvim.js_linter }}{{ else }}standard{{ end }}"],
\ 'go': ['gopls'],
\ 'rust': ['analyzer'],
\}
let g:ale_fixers = {'javascript': ["{{ if .nvim.js_fixer }}{{- .nvim.js_fixer }}{{ else }}standard{{ end }}"]}
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)
" 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'
\ }
" copilot setup
imap <silent><script><expr> <C-J> copilot#Accept("\<CR>")
let g:copilot_no_tab_map = v:true
" vim-go setting
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'
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 = "<C-n>"
let g:multi_cursor_select_all_word_key = '<A-n>'
let g:multi_cursor_start_key = "g<C-n>"
let g:multi_cursor_select_all_key = 'g<A-n>'
let g:multi_cursor_next_key = "<C-n>"
" let g:multi_cursor_prev_key = '<C-p>'
let g:multi_cursor_skip_key = '<C-x>'
let g:multi_cursor_quit_key = '<Esc>'
let g:javascript_plugin_jsdoc = 1
" fzf settings
" This is the default extra key bindings
let g:fzf_action = {
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
" Default fzf layout
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" Customize fzf colors to match your color scheme
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Enable per-command history.
" CTRL-N and CTRL-P will be automatically bound to next-history and
" previous-history instead of down and up. If you don't like the change,
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
let g:fzf_history_dir = '~/.local/share/fzf-history'
lua << EOF
2023-03-29 17:48:14 +00:00
vim.g.neon_style = "dark"
vim.g.neon_transparent = true
vim.cmd[[colorscheme neon]]
2023-03-04 07:36:06 +00:00
require('tabnine').setup({
disable_auto_comment=true,
2023-03-06 15:52:02 +00:00
accept_keymap="<C-J>",
2023-03-04 07:36:06 +00:00
dismiss_keymap = "<C-]>",
debounce_ms = 600,
suggestion_color = {gui = "#808080", cterm = 244},
exclude_filetypes = {"TelescopePrompt"}
})
2023-02-25 16:18:35 +00:00
vim.opt.list = true
vim.opt.listchars:append "eol:↴"
require("indent_blankline").setup {
show_end_of_line = true,
show_current_context = true,
show_current_context_start = true,
}
local nvlsp = require'lspconfig'
local lspSig = require'lsp_signature'
lspSig.setup{
hint_enable = true,
}
-- Add additional capabilities supported by nvim-cmp
local capabilities = require('cmp_nvim_lsp').default_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
lspSig.on_attach()
-- 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', '<leader>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,
}
nvlsp['bashls'].setup{
capabilities = capabilities,
on_attach = on_attach,
}
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({
-- behavior = cmp.ConfirmBehavior.Insert,
select = true,
}),
['<C-e>'] = cmp.mapping.abort(),
-- ['<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'},
}),
}
require'nvim-tree'.setup {
auto_reload_on_write = true,
disable_netrw = false,
hijack_cursor = false,
hijack_netrw = true,
hijack_unnamed_buffer_when_opening = false,
ignore_buffer_on_setup = false,
open_on_setup = false,
open_on_setup_file = false,
open_on_tab = false,
sort_by = "name",
update_cwd = false,
view = {
width = 40,
side = "left",
preserve_window_proportions = false,
number = false,
relativenumber = false,
signcolumn = "yes",
mappings = {
custom_only = false,
list = {
-- user mappings go here
},
},
},
renderer = {
indent_markers = {
enable = false,
icons = {
corner = "└ ",
edge = "│ ",
none = " ",
},
},
},
hijack_directories = {
enable = true,
auto_open = true,
},
update_focused_file = {
enable = false,
update_cwd = false,
ignore_list = {},
},
ignore_ft_on_setup = {},
system_open = {
cmd = nil,
args = {},
},
filters = {
dotfiles = false,
custom = {},
exclude = {},
},
git = {
enable = true,
ignore = true,
timeout = 400,
},
actions = {
use_system_clipboard = true,
change_dir = {
enable = true,
global = false,
},
open_file = {
quit_on_open = false,
resize_window = false,
window_picker = {
enable = true,
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
exclude = {
filetype = { "notify", "packer", "qf", "diff", "fugitive", "fugitiveblame" },
buftype = { "nofile", "terminal", "help" },
},
},
},
},
}
EOF