vimrc

set runtimepath^=~/.vim
call plug#begin('~/.vim/plugged')
Plug 'rbgrouleff/bclose.vim'
Plug 'skywind3000/asyncrun.vim'
Plug 'Yggdroot/LeaderF'
if exists("g:neovide")
"Plug 'neoclide/coc.nvim', {'branch': 'release'}
Plug 'nvim-treesitter/nvim-treesitter', { 'do': ':TSInstallSync all' }
Plug 'nvim-treesitter/nvim-treesitter-context'
endif
Plug 'folke/tokyonight.nvim'

Plug 'vim-scripts/taglist.vim'
Plug 'tomasr/molokai'
Plug 'preservim/nerdtree'

Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'

Plug 'easymotion/vim-easymotion'
Plug 'haya14busa/incsearch-easymotion.vim'

Plug 'git@github.com:vim-scripts/c.vim.git'
Plug 'vim-scripts/c.vim'

Plug 'voldikss/vim-floaterm'
Plug 'francoiscabrol/ranger.vim'

Plug 'matze/vim-move'

Plug 'tpope/vim-fugitive'
Plug 'airblade/vim-gitgutter'
Plug 'junegunn/gv.vim'

Plug 'terryma/vim-multiple-cursors'
Plug 'mg979/vim-visual-multi'

Plug 'preservim/tagbar'
Plug 'kshenoy/vim-signature'
Plug 'terryma/vim-expand-region'
call plug#end()

filetype indent off
syntax on

if exists("g:neovide")
colorscheme tokyonight-night
else
colorscheme molokai
endif

set foldcolumn=0
set wrapscan
set history=500
set notermguicolors
set t_Co=256
set mouse=a
set hlsearch
set cindent
set linebreak
set nocompatible
set sidescroll=5
set encoding=utf-8
set showcmd
set ruler
set cursorline
set showtabline=0

if has('nvim')
set cursorlineopt=number
endif

set incsearch
set showmatch
set matchtime=50
set helplang=cn
set langmenu=zh_CN.UTF-8
set noswapfile
set nowb
set mousemodel=extend
set sm
set smartcase
set smarttab
set signcolumn=yes
set title
set tabstop=4
set shiftwidth=4
set nowritebackup
set nobackup
set noautowrite
set copyindent
set ttyfast
set report=0
set synmaxcol=1000
set autoread
set foldcolumn=0
"set lazyredraw
set lbr
set tw=500
set ai "Auto indent
set nu
set relativenumber
set si "Smart indent
set nowrap "Wrap lines
set switchbuf+=useopen
set switchbuf+=usetab
set wildmenu
set wildignore+=.*
set mousemodel=popup
set foldenable
set foldmethod=manual
set sessionoptions-=options
set completeopt=longest,menu
set list
set listchars=tab:›\ ,trail:.,extends:#,nbsp:.
set dictionary+=~/.vim/words
set fileencodings=utf-8,gbk,gb18030,gb2312,ucs-bom,cp936,latin1
set hid
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
set laststatus=2
set complete+=k
inoremap <silent> <C-i> <C-x><C-k>
set dictionary+=~/.vim/dict/my_dict.txt
set statusline=%#StatusLinePath#%{getcwd()}/%m%{fugitive#statusline()}/%#StatusLineFileName#%t/%{get(b:,'current_func','')}

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
iab xdate <C-r>=strftime("20%y-%m-%d %H:%M:%S")<cr>

"=====================================================begin func====================================
function! UpdateCurrentFunc()
let lnum = line('.')
let fname = ''
let reserved = ['if', 'else', 'elseif', 'return']
for i in reverse(range(1, lnum))
let line_text = getline(i)
if line_text =~# '^\s*\(if\|else\>\)'
continue
endif
if line_text =~ '^\s*\%(\w\+\s\+\)\+\w\+\s*('
let fname = matchstr(line_text, '\v\w+\ze\s*\(')
if index(reserved, fname) != -1
continue
endif
break
endif
endfor
let b:current_func = fname
endfunction
autocmd CursorMoved,CursorMovedI * call UpdateCurrentFunc()
"=====================================================end func====================================


"=====================================================begin func====================================
function! DeleteVisualMatch()
" 获取可视模式下选中的内容
let [line_start, col_start] = getpos("'<")[1:2]
let [line_end, col_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return
endif
let lines[-1] = lines[-1][: col_end - 1]
let lines[0] = lines[0][col_start - 1:]
let selected_text = join(lines, "\n")

" 查找匹配 ID 并删除
for match in getmatches()
if match['pattern'] == selected_text
call matchdelete(match['id'])
echo "Deleted match ID: " . match['id']
return
endif
endfor
echo "No match found for selected text."
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! HighlightWithColorCode(color_code) range
let start_line = a:firstline
let end_line = a:lastline
let start_col = col("'<")
let end_col = col("'>")
let selected_text = getline(start_line)[start_col-1 : end_col-1]

if a:color_code == 999
echo "clear all"
call clearmatches()
return
endif

if a:color_code < 0 || a:color_code > 255
echo "Invalid color code: " . a:color_code
return
endif

let hl_group = 'MyColor' . a:color_code
try
execute 'highlight ' . hl_group . ' ctermbg=' . a:color_code . ' guibg=' . a:color_code
catch /E254/
echo "color:" . a:color_code
endtry

call matchadd(hl_group, selected_text)
endfunction
"=====================================================end func====================================

command! -range -nargs=1 HighlightWithColorCode call HighlightWithColorCode(<f-args>)


"=====================================================begin func====================================
function! LoadTags()
if exists("g:neovide")
execute "set tags=tags"
execute "set tags+=linux-master-tags"
else
call system("mv tags/* .")
let tags = ""
for tagfile in split(glob("tag_2025_Will_Rich_*"), "\n")
if stridx(&tags, tagfile) == -1
let tags .= tagfile . ","
endif
endfor

let tags = substitute(tags, ',$', '', '')
execute "set tags+=" . tags
endif
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! GenerateTags()
if exists("g:neovide")
execute 'AsyncRun ctags -R --exclude="linux-master*"'
else
call system("mkdir tags")
execute 'silent AsyncRun -mode=0 bash ~/.vim/tags.sh'
endif
autocmd User AsyncRunStop silent! call LoadTags()
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! Togglefunc1()
execute g:param1 ? "set nu relativenumber list" : "set nonu norelativenumber nolist"
let g:param1 = !g:param1
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! s:config_easyfuzzymotion(...) abort
return extend(copy({
\ 'converters': [incsearch#config#fuzzyword#converter()],
\ 'modules': [incsearch#config#easymotion#module({'overwin': 1})],
\ 'keymap': {"\<CR>": '<Over>(easymotion)'},
\ 'is_expr': 0,
\ 'is_stay': 1
\ }), get(a:, 1, {}))
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! s:execute_selected_command(command)
execute a:command
endfunction
"=====================================================end func====================================

"=====================================================begin func====================================
function! s:execute_command()
let g:command_list = [
\ ':BLines',
\ ':Git blame',
\ ':LeaderfLine',
\ ':Lines',
\ ':BCommits',
\ ':Commits',
\ ':Rg',
\ ]
call fzf#run(fzf#wrap({
\ 'source': g:command_list,
\ 'sink': function('s:execute_selected_command')
\ }))
endfunction
"=====================================================end func====================================

command! -bang -nargs=* Rg
\ call fzf#vim#grep(
\ 'rg --threads 79 -L --column --line-number --no-heading --color=always --smart-case '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)

let g:fzf_preview_window = ['up:65%', 'ctrl-f']
let g:fzf_vim = {}
let g:fzf_follow_links = 1
let g:fzf_vim_dir = expand('%:p:h')
let $FZF_DEFAULT_OPTS='--height 100% --layout=reverse'
let g:fzf_buffers_jump = 1
let g:fzf_action = {
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit',
\ 'ctrl-t': 'tabnew' }
let g:fzf_layout = {
\ 'window': {
\ 'width': 1,
\ 'height': 1,
\ 'border': 'rounded'
\ },
\ }

let mapleader = " "
let g:Lf_FollowLinks = 1
let NERDTreeOpenOnStartup=0
let NERDTreeWinPos="left"
let g:param1= 0
let g:initial_directory_set = 0

let g:tagbar_position = 'left'
let Tlist_WinWidth = 50
let Tlist_Use_SingleClick = 1
let Tlist_Use_Right_Window = 0
let Tlist_WinWidth = 50

let g:tagbar_singleclick = 1
let g:tagbar_autoclose = 0

let g:EasyMotion_do_mapping = 0
let g:EasyMotion_smartcase = 1
let g:EasyMotion_use_smartsign_us = 1 " US layout
let g:move_key_modifier_visualmode = 'S'
let loaded_matchparen=1
let g:ranger_map_keys = 0

let g:floaterm_width = 0.99 " 宽度为屏幕的 80%
let g:floaterm_height = 0.99 " 高度为屏幕的 60%
let g:floaterm_autoinsert = 1
let g:floaterm_autohide = 1
let g:floaterm_autoclose = 2
let current_file_dir = expand('%:p:h')
let current_working_dir = getcwd()
let g:ranger_replace_netrw = 1

if exists("g:neovide")
let g:python3_host_prog = '~/venv/bin/python3'
else
"let g:python3_host_prog = '/opt6/ranxuefeng/.venv/bin/python3'
let g:python3_host_prog = '~/venv/bin/python3'
endif

cabbrev rg Rg
cabbre git Git

nnoremap <leader><leader> :BTags<CR>
nnoremap <leader>f :Files<CR>
nnoremap <leader>r :Buffers<CR>

nnoremap <C-h> :tabprevious<CR>
nnoremap <C-l> :tabnext<CR>
vnoremap <C-h> :tabprevious<CR>
vnoremap <C-l> :tabnext<CR>

nnoremap <C-@> :
nnoremap <C-w> <C-w>w
if !exists("g:neovide")
nnoremap u :u<cr>:w<cr>
endif
vnoremap < <gv
vnoremap > >gv
vnoremap $ $h

nnoremap Z ZZ
inoremap jj <Esc>

if exists("g:neovide")
vnoremap y "+y
vnoremap p "+p
nnoremap p "+p
map yy Ey
else
vnoremap y "ay
vnoremap p "ap
nnoremap p "ap
endif
vnoremap <Rightmouse> "ay
nnoremap <Rightmouse> <Leftmouse>#N

inoremap <C-h> <left>
inoremap <C-j> <down>
inoremap <C-k> <up>
inoremap <C-l> <right>

nnoremap <C-Space> :
inoremap <C-Space> <C-n>

nnoremap <S-h> :vertical resize -3<CR>
nnoremap <S-l> :vertical resize +3<CR>
nnoremap <S-j> :resize +3<CR>
nnoremap <S-k> :resize -3<CR>
nnoremap <silent> <leader>no :call Togglefunc1()<CR>
if exists("g:neovide")
vnoremap<C-c> :w! ~/.vim/cvbuf.c<CR>
nnoremap<C-v> :r ~/.vim/cvbuf.c<CR>
else
vnoremap<C-c> :w! ~/.vim/cvbuf.c<CR>
nnoremap<C-v> :r ~/.vim/cvbuf.c<CR>
endif

" Close all the buffers
map <leader>ba :bufdo bd<cr>

nnoremap a <C-]>zz
nnoremap # #N
if !exists("g:neovide")
nnoremap n nzz
nnoremap N Nzz
nnoremap j jzz
nnoremap k kzz
nnoremap w wzz
endif
nmap <leader>w :w!<cr>

nnoremap <silent><expr> <Space>/ incsearch#go(<SID>config_easyfuzzymotion())
nmap s <Plug>(easymotion-overwin-f2)
nnoremap<leader>t :FloatermToggle<CR>
vnoremap <S-j> :m '>+1<CR>gv=gv
vnoremap <S-k> :m '<-2<CR>gv=gv
nnoremap f <C-o>zz
nnoremap a <C-]>zz
nnoremap F [[k2wzz
nnoremap ; :
vnoremap ; :

nnoremap <leader>s :Rg <C-r><C-w> = <CR>
vnoremap <leader>s y:Rg <C-r>" = <CR>
vnoremap R y:Rg <C-r>"<CR>
nnoremap R :Rg <C-r><C-w><CR>

vnoremap . :<C-u>call HighlightWithColorCode(input('Enter color code (0-255): '))<CR>
vnoremap <silent> # y/<C-r>"<CR>Nzz
nnoremap <F1> 15zh
nnoremap <F2> 15zl
vnoremap <F1> 15zh
vnoremap <F2> 15zl
inoremap <F1> 15zh
inoremap <F2> 15zl
nnoremap <S-ScrollWheelRight> 15zl
nnoremap <S-ScrollWheelLeft> 15zh
vnoremap <Leader>dm :call DeleteVisualMatch()<CR>

inoremap $1 ()<esc>i
inoremap $2 []<esc>i
inoremap $3 {}<esc>i
inoremap $4 {<esc>o}<esc>O
inoremap $q ''<esc>i
inoremap $e ""<esc>i
inoremap $l ->


vnoremap $1 <esc>`>a)<esc>`<i(<esc>
vnoremap $2 <esc>`>a]<esc>`<i[<esc>
vnoremap $3 <esc>`>a}<esc>`<i{<esc>
vnoremap $e <esc>`>a"<esc>`<i"<esc>
vnoremap $q <esc>`>a'<esc>`<i'<esc>

nnoremap t :call <SID>execute_command_cd()<CR>
nnoremap q :call <SID>execute_command()<CR>

map ce :Rg<cr>
map cf :NERDTreeFind<cr>
map cc :TagbarToggle<cr>
map cs :sp<cr>
map cv :vsp<cr>
map ca :Ranger<cr>
map cq :copen 20<cr>
map cL :call system('rm -rf *2025_Will_Rich_* tags \n')<cr>
map cl :colorscheme default<bar>syntax off<cr>
map co :colorscheme molokai<bar>syntax on<cr>
map ct :call GenerateTags()<cr>
map E <Plug>(expand_region_expand)
map 0 ^
map <leader>cd :cd %:p:h<cr>:pwd<cr>

autocmd BufWritePost * GitGutter
autocmd InsertLeave * silent! write
autocmd FocusGained,BufEnter * silent! checktime
autocmd BufRead,BufNewFile * source ~/.vim/plugged/c.vim/ftplugin/c.vim
autocmd BufRead,BufNewFile * source ~/.vim/plugged/c.vim/ftplugin/make.vim
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
autocmd InsertLeave * if pumvisible() == 0|pclose|endif
autocmd vimEnter * execute 'cd' expand('%:p:h')
autocmd VimLeave * call system("mv *_2025_Will_Rich_* tags/")
autocmd BufRead * silent! call LoadTags()
autocmd Syntax * source ~/.vim/plugged/c.vim/ftplugin/c.vim
autocmd User FloatermExit :FloatermNew --autoclose=0 exit 0
autocmd BufRead,BufNewFile * hi clear SignColumn
autocmd BufRead,BufNewFile * hi clear LineNr
autocmd BufEnter * if !g:initial_directory_set | silent! lcd %:p:h | let g:initial_directory_set = 1 | endif

hi TabLine ctermfg=2 ctermbg=233
hi TabLineSel ctermfg=118
hi TabLineFill ctermfg=233
hi ModeMsg ctermbg=233 ctermfg=2
hi MoreMsg ctermbg=233 ctermfg=2
hi Question ctermbg=233 ctermfg=2
hi CursorLineNr ctermfg=2

hi Search ctermbg=white ctermfg=black
hi Visual ctermbg=235 ctermfg=none

hi StatusLinePath ctermbg=2 ctermfg=233
hi StatusLineFileName ctermfg=233

nnoremap <leader>bd :bufdo bd<cr>
nnoremap <leader>pp :setlocal paste!<cr>

" ======================= NEVIDIA 专属配置 =======================
if exists("g:neovide")
set linespace=8
set cmdheight=0
cnoremap <C-V> <C-R>+
let g:neovide_cursor_trail_size = 0.7 " 光标拖尾长度(0-1)
let g:neovide_floating_blur = 1 " 浮动窗口模糊效果
let g:neovide_multigrid = v:true " 启用多网格渲染(提升性能)
"let g:neovide_refresh_rate = 60
let g:neovide_underline_automatic_scaling = v:true " 下划线自动缩放
let g:neovide_fullscreen = v:true

let g:neovide_cursor_animation_length = 0.1
"let g:neovide_cursor_vfx_mode = "railgun" " 粒子特效(可选:wireframe/torpedo/railgun/pixiedust)
let g:neovide_font_face = "FiraCode Nerd Font"
let g:neovide_font_size = 10
let g:neovide_padding_top = 1 " 窗口顶部留白
let g:neovide_remember_window_size = v:true " 记忆窗口尺寸
let g:neovide_power_save_mode = v:true
let g:neovide_scale_factor = 1.1
let g:neovide_cursor_antialiasing = v:true
let g:neovide_scroll_animation_length = 0.6

let g:neovide_cursor_trail_length= 0
let g:neovide_cursor_vfx_particle_speed=10.0
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'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
"""""""""""""""""""""""""""""""COC.NVIM"""""""""""""""""""""""""""""""""""
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
inoremap <silent><expr> <C-@> coc#refresh()
inoremap <silent><expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
inoremap <silent><expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <silent><expr> <CR> pumvisible() ? coc#_select_confirm() : "\<CR>"
"""""""""""""""""""""""""""""""COC.NVIM"""""""""""""""""""""""""""""""""""
endif "neovide config
" ======================= NEVIDIA 专属配置 =======================

posted @ 2024-03-26 21:13  ranxuefeng  阅读(27)  评论(0)    收藏  举报