set background=dark
set termguicolors
-set t_Co=256 "terminal color
-set t_ut=""
-"set term=xterm-256color
"In order to display chinese in GBK
-"let &termencoding=&encoding
set fileencodings=utf-8,gbk
set fileformat=unix
set foldmethod=indent
-set encoding=utf-8 "required for ycm
+set foldlevelstart=99
+set foldlevel=99
+set encoding=utf-8
set tabstop=4
set softtabstop=4
call plug#begin()
Plug 'morhetz/gruvbox'
- Plug 'Yggdroot/indentLine'
+ Plug 'lukas-reineke/indent-blankline.nvim'
Plug 'christoomey/vim-tmux-navigator'
Plug 'vim-airline/vim-airline'
Plug 'majutsushi/tagbar'
Plug 'MeanderingProgrammer/render-markdown.nvim'
- Plug 'plasticboy/vim-markdown'
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app && npx --yes yarn install' }
Plug 'tpope/vim-fugitive'
- Plug 'airblade/vim-gitgutter'
+ Plug 'lewis6991/gitsigns.nvim'
Plug 'kdheepak/lazygit.nvim'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" fzf.vim setting
"----------------------
if has_key(plugs, 'fzf.vim')
- "mapping for fzf.vim
+ function! s:ProjectRg(query) abort
+ let dir = expand('%:p:h')
+ let dir = isdirectory(dir) ? dir : getcwd()
+ let root = systemlist('git -C ' . shellescape(dir) . ' rev-parse --show-toplevel 2>/dev/null')
+ if v:shell_error || empty(root)
+ echoerr 'Not in a Git repository'
+ return
+ endif
+ call fzf#vim#grep2(
+ \ 'rg --hidden --glob "!.git" --column --line-number --no-heading --color=always --smart-case -- ',
+ \ a:query, fzf#vim#with_preview({'dir': root[0]}))
+ endfunction
+
+ command! -nargs=* ProjectRg call <SID>ProjectRg(<q-args>)
nnoremap <C-p> :GFiles<CR>
- "as default <C-f>/<C-b> pair used to page down/up entire page
- nnoremap <C-f> :Tags<CR>
+ nnoremap <C-f> :ProjectRg<CR>
endif
"----------------------
"----------------------
if has_key(plugs, 'nvim-treesitter')
lua require('plugin-config/nvim-treesitter')
+endif
+
+if has_key(plugs, 'indent-blankline.nvim')
+ lua require('ibl').setup({ scope = { enabled = false } })
+endif
+
+if has_key(plugs, 'gitsigns.nvim')
+ lua require('plugin-config/gitsigns')
+endif
- "set foldmethod=expr
- set foldmethod=indent
- set foldexpr=nvim_treesitter#foldexpr()
- set foldlevel=99
+if has_key(plugs, 'lazygit.nvim')
+ nnoremap <silent> <leader>lg :LazyGit<CR>
endif
"----------------------
nnoremap K :tabnext<CR>
nnoremap <leader>J :tabmove -1<CR>
nnoremap <leader>K :tabmove +1<CR>
-nnoremap <C-h> <C-w>h
-nnoremap <C-j> <C-w>j
-nnoremap <C-k> <C-w>k
-nnoremap <C-l> <C-w>l
nnoremap <leader>" viw<esc>a"<esc>bi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>bi'<esc>lel
nnoremap <silent> <Leader>+ :resize +5<CR>
"HighLight trailing whitespace"
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
-
-"use powerline-vim for normal use
-"instead of installing for both user and root
-"run to install lib: pip3 install --user powerline-status
-"python3 from powerline.vim import setup as powerline_setup
-"python3 powerline_setup()
-"python3 del powerline_setup
--- /dev/null
+require('gitsigns').setup({
+ on_attach = function(bufnr)
+ local gs = require('gitsigns')
+ local function map(mode, lhs, rhs)
+ vim.keymap.set(mode, lhs, rhs, { buffer = bufnr, silent = true })
+ end
+
+ map('n', ']c', function()
+ if vim.wo.diff then
+ vim.cmd.normal({ ']c', bang = true })
+ else
+ gs.nav_hunk('next')
+ end
+ end)
+ map('n', '[c', function()
+ if vim.wo.diff then
+ vim.cmd.normal({ '[c', bang = true })
+ else
+ gs.nav_hunk('prev')
+ end
+ end)
+
+ map('n', '<leader>hp', gs.preview_hunk)
+ map('n', '<leader>hs', gs.stage_hunk)
+ map('n', '<leader>hr', gs.reset_hunk)
+ map('n', '<leader>hb', function() gs.blame_line({ full = true }) end)
+ map('x', '<leader>hs', function()
+ gs.stage_hunk({ vim.fn.line('.'), vim.fn.line('v') })
+ end)
+ map('x', '<leader>hr', function()
+ gs.reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })
+ end)
+ end,
+})
-require'nvim-treesitter'.setup {
- -- A list of parser names, or "all"
- ensure_installed = { "c", "lua", "vim", "vimdoc", "query" },
+require('nvim-treesitter').setup {
+ install_dir = vim.fn.stdpath('data') .. '/site',
+}
- -- Automatically install missing parsers when entering buffer
- -- Recommendation: set to false if you don't have `tree-sitter` CLI installed locally
- auto_install = true,
+local function enable(buf)
+ if not pcall(vim.treesitter.start, buf) then
+ return
+ end
- highlight = {
- enable = true,
+ vim.wo[0][0].foldexpr = 'v:lua.vim.treesitter.foldexpr()'
+ vim.wo[0][0].foldmethod = 'expr'
+end
- -- to disable slow treesitter highlight for large files
- disable = function(lang, buf)
- local max_filesize = 100 * 1024 -- 100 KB
- local ok, stats = pcall(vim.uv.fs_stat, vim.api.nvim_buf_get_name(buf))
- if ok and stats and stats.size > max_filesize then
- return true
- end
- end,
- additional_vim_regex_highlighting = false,
- },
-}
+vim.api.nvim_create_autocmd('FileType', {
+ callback = function(args) enable(args.buf) end,
+})
+
+-- Startup filetype detection can precede this config being sourced.
+if vim.bo.filetype ~= '' then
+ enable(0)
+end