require'nvim-treesitter.configs'.setup { -- 安装 language parser -- :TSInstallInfo 命令查看支持的语言 ensure_installed = {"vim", "lua", "javascript", "go", "php"}, -- 启用代码高亮功能 highlight = { enable = true, additional_vim_regex_highlighting = false }, -- 启用增量选择 incremental_selection = { enable = true, keymaps = { init_selection = '', node_incremental = '', node_decremental = '', scope_incremental = '', } }, -- 启用基于Treesitter的代码格式化(=) . NOTE: This is an experimental feature. indent = { enable = true } } -- 开启 Folding vim.wo.foldmethod = 'expr' vim.wo.foldexpr = 'nvim_treesitter#foldexpr()' -- 默认不要折叠 -- https://stackoverflow.com/questions/8316139/how-to-set-the-default-to-unfolded-when-you-open-a-file vim.wo.foldlevel = 99 -- Some servers have issues with backup files, see #649 vim.opt.backup = false vim.opt.writebackup = false -- Having longer updatetime (default is 4000 ms = 4s) leads to noticeable -- delays and poor user experience vim.opt.updatetime = 300 -- Always show the signcolumn, otherwise it would shift the text each time -- diagnostics appeared/became resolved vim.opt.signcolumn = "yes" local keyset = vim.keymap.set -- Autocomplete function _G.check_back_space() local col = vim.fn.col('.') - 1 return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil end -- Use Tab for trigger completion with characters ahead and navigate -- NOTE: There's always a completion item selected by default, you may want to enable -- no select by setting `"suggest.noselect": true` in your configuration file -- NOTE: Use command ':verbose imap ' to make sure Tab is not mapped by -- other plugins before putting this into your config local opts = {silent = true, noremap = true, expr = true, replace_keycodes = false} keyset("i", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts) keyset("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) keyset("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], opts) -- GoTo code navigation keyset("n", "", "(coc-definition)", {silent = true}) keyset("n", "", "(coc-type-definition)", {silent = true}) keyset("n", "gi", "(coc-implementation)", {silent = true}) keyset("n", "gr", "(coc-references)", {silent = true}) -- Use K to show documentation in preview window function _G.show_docs() local cw = vim.fn.expand('') if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then vim.api.nvim_command('h ' .. cw) elseif vim.api.nvim_eval('coc#rpc#ready()') then vim.fn.CocActionAsync('doHover') else vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw) end end keyset("n", "K", 'lua _G.show_docs()', {silent = true}) -- Use to trigger snippets keyset("i", "", "(coc-snippets-expand-jump)") -- Use to trigger completion keyset("i", "", "coc#refresh()", {silent = true, expr = true}) require("formatter").setup({ filetype = { php = { function() return { exe = "php-cs-fixer", args = { "fix", "--config=/home/www/php/php-cs-fixer/config.php --allow-risky=yes" }, stdin = false, ignore_exitcode = true, } end, } }, }) -- format on save vim.api.nvim_exec( [[ augroup FormatAutogroup autocmd! autocmd BufWritePost *.php FormatWrite augroup END ]], true )