# My NVIM ``` rc lua require('plugins') set clipboard+=unnamedplus set nu syntax on set mouse=a noremap <F2> :set list!<CR> noremap <F3> :set nonu!<CR> " 4個空白鍵取代 Tab set tabstop=4 " 程式縮排所需要的 Space 個數 set shiftwidth=4 set expandtab " Run :GoBuild or :GoTestCompile based on the go file function! s:build_go_files() let l:file = expand('%') if l:file =~# '^\f\+_test\.go$' call go#test#Test(0, 1) elseif l:file =~# '^\f\+\.go$' call go#cmd#Build(0) endif endfunction " Map keys for most used commands. " Ex: `\b` for building, `\r` for running and `\b` for running test. autocmd FileType go nmap <buffer> <leader>b :<C-u>call <SID>build_go_files()<CR> autocmd FileType go nmap <buffer> <leader>r <Plug>(go-run) autocmd FileType go nmap <buffer> <leader>t <Plug>(go-test) noremap <silent> <Leader>a :GoAlternate<CR> set completeopt-=preview set virtualedit=block set signcolumn=yes:1 highlight clear SignColumn lua require('plugin-config/nvim-treesitter') lua require('dap-go').setup() ``` ``` lua local install_path = vim.fn.stdpath('data')..'/site/pack/packer/start/packer.nvim' if vim.fn.empty(vim.fn.glob(install_path)) > 0 then vim.fn.system({'git', 'clone', 'https://github.com/wbthomason/packer.nvim', install_path}) vim.api.nvim_command 'packadd packer.nvim' end vim.cmd [[packadd packer.nvim]] vim.cmd [[packadd vimball]] return require('packer').startup(function() -- Packer can manage itself use 'wbthomason/packer.nvim' use { 'nvim-treesitter/nvim-treesitter', run = ':TSUpdate' } -- Debugger use 'mfussenegger/nvim-dap' use { "rcarriga/nvim-dap-ui", requires = {"mfussenegger/nvim-dap"}, config = function() require("dapui").setup({ icons = { expanded = "▾", collapsed = "▸" }, mappings = { -- Use a table to apply multiple mappings expand = { "<CR>", "<2-LeftMouse>" }, open = "o", remove = "d", edit = "e", repl = "r", }, sidebar = { -- You can change the order of elements in the sidebar elements = { -- Provide as ID strings or tables with "id" and "size" keys { id = "repl", size = 0.5, -- Can be float or integer > 1 }, { id = "breakpoints", size = 0.25 }, { id = "stacks", size = 0.25 }, }, size = 40, position = "left", -- Can be "left", "right", "top", "bottom" }, tray = { elements = { "scopes" }, size = 10, position = "bottom", -- Can be "left", "right", "top", "bottom" }, floating = { max_height = 0.2, -- These can be integers or a float between 0 and 1. max_width = 1, -- Floats will be treated as percentage of your screen. border = "single", -- Border style. Can be "single", "double" or "rounded" mappings = { close = { "q", "<Esc>" }, }, }, windows = { indent = 1 }, }) end } use { 'leoluz/nvim-dap-go', setup = function() local opts = {noremap = true} vim.api.nvim_set_keymap('n', '<F5>', "<cmd>lua require'dap'.continue()<cr>", opts) vim.api.nvim_set_keymap('n', '<F6>', "<cmd>lua require'dap'.toggle_breakpoint()<cr>", opts) vim.api.nvim_set_keymap('n', '<F8>', "<cmd>lua require'dapui'.toggle()<cr>", opts) end } use { "akinsho/toggleterm.nvim", setup = function() local opts = {noremap = true} vim.api.nvim_set_keymap('n', '<F12>', "<cmd>ToggleTerm direction=\"float\"<cr>", opts) vim.api.nvim_set_keymap('t', '<F12>', "<cmd>ToggleTerm direction=\"float\"<cr>", opts) vim.api.nvim_set_keymap('t', '<Esc>', "<C-\\><C-n>", opts) end } use { 'preservim/nerdtree', setup = function() vim.api.nvim_set_keymap("n", "<F4>", "<cmd>NERDTreeToggle<cr>" ,{silent = true, noremap = true}) end } use { 'fatih/vim-go', run = ':GoUpdateBinaries', ft = 'go', setup = function() vim.g.go_diagnostics_enabled = 1 vim.g.go_highlight_fields = 1 vim.g.go_highlight_functions = 1 vim.g.go_highlight_function_calls = 1 vim.g.go_highlight_extra_types = 1 vim.g.go_highlight_operators = 1 vim.g.go_fmt_autosave = 1 vim.g.go_fmt_command = "goimports" vim.g.go_auto_type_info = 1 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 t "<C-x><C-o>" end end _G.s_tab_complete = function() if vim.fn.pumvisible() == 1 then return t "<C-p>" else return t "<C-h>" end end _G.enter_key = function() if vim.fn.pumvisible() == 1 then return t "<C-y>" else return t "<CR>" end end vim.api.nvim_set_keymap("i", "<tab>", "<C-R>=v:lua.tab_complete()<CR>" ,{silent = true, noremap = true}) vim.api.nvim_set_keymap("i", "<s-tab>", "<C-R>=v:lua.s_tab_complete()<CR>" ,{silent = true, noremap = true}) vim.api.nvim_set_keymap('i', '<enter>', '<C-R>=v:lua.enter_key()<CR>' ,{silent = true, noremap = true}) end } use { 'neovim/nvim-lspconfig', config = function() diagnostic_config = { -- Enable underline, use default values underline = true, -- Enable virtual text, override spacing to 2 virtual_text = { spacing = 2, prefix = '<', }, -- Use a function to dynamically turn signs off -- and on, using buffer local variables signs = function(bufnr, client_id) local ok, result = pcall(vim.api.nvim_buf_get_var, bufnr, 'show_signs') -- No buffer local variable set, so just enable by default if not ok then return true end return result end, -- Disable a feature update_in_insert = false, } vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( vim.lsp.diagnostic.on_publish_diagnostics, diagnostic_config) vim.api.nvim_set_keymap('n', '[d', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>',{silent = true, noremap = true}) vim.api.nvim_set_keymap('n', ']d', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>',{silent = true, noremap = true}) require('lspconfig').gopls.setup{} end } use { 'nvim-telescope/telescope.nvim', requires = {{'nvim-lua/popup.nvim'}, {'nvim-lua/plenary.nvim'}}, cmd = 'Telescope', setup = function() vim.api.nvim_set_keymap('n', '<leader>fg', "<cmd>Telescope live_grep<cr>", {noremap = true}) vim.api.nvim_set_keymap('n', '<leader>ff', "<cmd>Telescope find_files<cr>", {noremap = true}) end } use { 'preservim/tagbar', setup = function() vim.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.api.nvim_set_keymap("n", "<F1>", "<cmd>TagbarToggle<cr>" ,{silent = true, noremap = true}) end } end) ```