代码拉取完成,页面将自动刷新
" *************************************************************************
" presettings
" *************************************************************************
set encoding=utf8
set nocompatible
if has('win32')
let DATA_DIR = $HOME.'/vimfiles'
else
let DATA_DIR = $HOME.'/.vim'
endif
" *************************************************************************
" vim plugins
" *************************************************************************
let GITHUB_SITE = 'https://ghproxy.com/https://github.com/'
"let GITHUB_SITE = 'https://hub.fastgit.xyz/'
"let GITHUB_SITE = 'https://github.com/'
let GITHUB_RAW = 'https://raw.fastgit.org/'
"let GITHUB_RAW = 'https://ghproxy.com/https://raw.githubusercontent.com/'
"let GITHUB_RAW = 'https://raw.githubusercontent.com/'
" download the plugin manager if not installed
let AUTOLOAD_DIR = DATA_DIR.'/autoload'
let PLUGIN_MANAGER_PATH = AUTOLOAD_DIR.'/plug.vim'
let PLUGIN_MANAGER_URL = GITHUB_RAW.'/junegunn/vim-plug/master/plug.vim'
if empty(glob(PLUGIN_MANAGER_PATH))
echo 'Downloading plugin manager ...'
if has('win32') && executable('powershell')
silent execute '!powershell "iwr -useb '.PLUGIN_MANAGER_URL.' |`'
\ 'ni '.PLUGIN_MANAGER_PATH.' -Force"'
elseif executable('wget')
silent execute '!mkdir -p '.AUTOLOAD_DIR.' '
\ .'&& wget -O '.PLUGIN_MANAGER_PATH.' '.PLUGIN_MANAGER_URL.' '
\ .'&& echo "Download successful." || echo "Download failed." '
elseif executable('curl')
silent execute '!curl -fLo '.PLUGIN_MANAGER_PATH
\ .' --create-dirs '.PLUGIN_MANAGER_URL.' '
\ .'&& echo "Download successful." || echo "Download failed." '
else
echo 'Please download the plugin manager from '.PLUGIN_MANAGER_URL
\ .' and place it in '.PLUGIN_MANAGER_PATH
endif
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
call plug#begin()
" --------------------
" color schemes
" --------------------
Plug GITHUB_SITE.'flazz/vim-colorschemes'
" --------------------
" mostly used
" --------------------
Plug GITHUB_SITE.'preservim/nerdtree', { 'on': 'NERDTreeToggle' }
Plug GITHUB_SITE.'rbong/vim-crystalline', { 'branch': 'vim-7' }
Plug GITHUB_SITE.'mbbill/undotree'
Plug GITHUB_SITE.'preservim/tagbar', { 'on': 'TagbarToggle' }
Plug GITHUB_SITE.'mileszs/ack.vim'
Plug GITHUB_SITE.'vim-scripts/YankRing.vim'
" --------------------
" more convenience
" --------------------
if has('timers')
Plug GITHUB_SITE.'delphinus/vim-auto-cursorline'
endif
Plug GITHUB_SITE.'luochen1990/rainbow'
Plug GITHUB_SITE.'gosukiwi/vim-smartpairs'
Plug GITHUB_SITE.'airblade/vim-rooter'
Plug GITHUB_SITE.'junegunn/vim-peekaboo'
Plug GITHUB_SITE.'tpope/vim-commentary'
Plug GITHUB_SITE.'farmergreg/vim-lastplace'
" system clipboard
Plug GITHUB_SITE.'ojroques/vim-oscyank', { 'branch': 'main' }
Plug GITHUB_SITE.'christoomey/vim-system-copy'
" vim performance
if has('timers') && has ('terminal')
Plug GITHUB_SITE.'dstein64/vim-startuptime'
else
Plug GITHUB_SITE.'NewComer00/startuptime.vim', { 'branch': 'patch-1' }
endif
call plug#end()
" *************************************************************************
" plugin configs
" *************************************************************************
" flazz/vim-colorschemes
syntax on
colorscheme molokai
" rbong/vim-crystalline
function! StatusLine(...)
return crystalline#mode() . crystalline#right_mode_sep('Line')
\ . ' %f%h%w%m%r ' . crystalline#right_sep('Line', 'Fill') . '%='
\ . crystalline#left_sep('Line', 'Fill')
\ . ' %{&ft} [%{&fenc!=#""?&fenc:&enc}] [%{&ff}] Line:%l/%L Col:%c%V %P '
endfunction
let g:crystalline_statusline_fn = 'StatusLine'
let g:crystalline_theme = 'jellybeans'
" preservim/nerdtree
let NERDTreeWinPos="right"
let NERDTreeShowHidden=1
let NERDTreeMouseMode=2
" disable the original file explorer
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
" lazy load nerdtree when open a directory
" https://github.com/junegunn/vim-plug/issues/424#issuecomment-189343357
augroup nerd_loader
autocmd!
autocmd VimEnter * silent! autocmd! FileExplorer
autocmd BufEnter,BufNew *
\ if isdirectory(expand('<amatch>'))
\| call plug#load('nerdtree')
\| execute 'autocmd! nerd_loader'
\| endif
augroup END
" preservim/tagbar
let g:tagbar_position = 'vertical leftabove'
let g:tagbar_width = max([25, winwidth(0) / 5])
" mileszs/ack.vim
if executable('ag')
let g:ackprg = 'ag --vimgrep --hidden --ignore .git'
endif
" rainbow/luochen1990
let g:rainbow_active = 1
let g:rainbow_conf = {
\ 'separately': {
\ 'nerdtree': 0,
\ }
\}
" vim-scripts/YankRing.vim
" to avoid <C-p> collision with the ctrlp plugin
let g:yankring_replace_n_pkey = '<m-p>'
let g:yankring_replace_n_nkey = '<m-n>'
" save yankring history in this dir
let s:yankring_dir = DATA_DIR.'/yankring-dir'
if !isdirectory(s:yankring_dir)
call mkdir(s:yankring_dir)
endif
let g:yankring_history_dir = s:yankring_dir
" christoomey/vim-system-copy
let g:system_copy_enable_osc52 = 1
if has('win32') && executable('powershell')
" force cmd.exe to use utf-8 encoding
" https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window
call system('chcp 65001')
" https://github.com/christoomey/vim-system-copy/pull/35#issue-557371087
let g:system_copy#paste_command='powershell "Get-Clipboard"'
endif
" *************************************************************************
" my scripts
" *************************************************************************
" speed up vim scrolling
" https://stackoverflow.com/questions/307148/vim-scrolling-slowly
set ttyfast
set lazyredraw
" speed up syntax highlighting & regex performance
" https://vi.stackexchange.com/a/21641
" https://gist.github.com/glts/5646749
if exists('®expengine')
set regexpengine=1
endif
" to enable backspace key
" https://vi.stackexchange.com/a/2163
set backspace=indent,eol,start
set novisualbell
" to deal with REPLACE MODE problem on windows cmd or windows terminal
" https://superuser.com/a/1525060
set t_u7=
set t_Co=256
set hlsearch
set incsearch
set number
set relativenumber
set nowrap
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set wildmode=longest,full
set wildmenu
set mouse=a
" mouse will still work beyond the 223rd col if vim supports mouse-sgr
" https://stackoverflow.com/a/19253251/15283141
if has("mouse_sgr")
set ttymouse=sgr
else
set ttymouse=xterm2
end
set laststatus=2
set splitbelow
set splitright
set dictionary+=/usr/share/dict/words
set complete+=k
" to be compatable with older version
" https://stackoverflow.com/a/36374234/15283141
if has("patch-7.4.710")
set listchars=eol:↵,tab:\|\|,trail:~,extends:>,precedes:<,space:·
else
set listchars=eol:↵,tab:\|\|,trail:~,extends:>,precedes:<
endif
set list
" Let's save undo info!
" from https://vi.stackexchange.com/a/53
let s:undo_dir = DATA_DIR.'/undo-dir'
if !isdirectory(s:undo_dir)
call mkdir(s:undo_dir, "", 0700)
endif
let &undodir = s:undo_dir
set undofile
" *************************************************************************
" my functions
" *************************************************************************
" function to run a shell
" https://stackoverflow.com/questions/1236563/how-do-i-run-a-terminal-inside-of-vim
function! OpenShell()
if v:version < 801
echo "Press any key to open a shell..."
echo "After the shell opened, press <C-d> or type 'exit' to quit the shell."
call getchar()
sh
else
bo 10sp | term ++curwin
" enable the shortcut to close the shell
if has('win32')
tnoremap <silent> <F3> <C-End><C-Home>exit<CR>
else
tnoremap <silent> <F3> <C-a><C-k><C-d>
endif
endif
endfunction
" allow toggling between local and default mode
" https://vim.fandom.com/wiki/Toggle_between_tabs_and_spaces
function! TabToggle()
if &expandtab
set noexpandtab
else
set expandtab
endif
endfunction
" test the startup time of Vim
function! TimingVimStartup(sorted)
let l:cmd = ''
if has('timers') && has ('terminal')
let l:cmd = 'StartupTime --tries 10'
if a:sorted == 0
let l:cmd .= ' --no-sort'
endif
else
let l:cmd = 'StartupTime'
endif
execute(l:cmd)
endfunction
" *************************************************************************
" hotkeys
" *************************************************************************
" functional hotkeys for plugins
nnoremap <silent> <F2> :NERDTreeToggle<CR>
nnoremap <silent> <F3> :call OpenShell()<CR>
nnoremap <silent> <F4> :UndotreeToggle<CR>
nnoremap <silent> <F7> :YRShow<CR>
nnoremap <silent> <F8> :TagbarToggle<CR>
nnoremap <F9> :AckFile!<Space>
inoremap <silent> <F2> <Esc>:NERDTreeToggle<CR>
inoremap <silent> <F3> <Esc>:call OpenShell()<CR>
inoremap <silent> <F4> <Esc>:UndotreeToggle<CR>
inoremap <silent> <F7> <Esc>:YRShow<CR>
inoremap <silent> <F8> <Esc>:TagbarToggle<CR>
inoremap <F9> <Esc>:AckFile!<Space>
cnoremap <silent> <F9> <C-c>
" quickly edit this config file
nnoremap <leader>ve :tabnew $MYVIMRC<CR>
" quickly save and source this config file
nnoremap <leader>vs :wa<Bar>so $MYVIMRC<CR>
" plugin manager shortcuts
nnoremap <leader>vi :wa<Bar>silent! so $MYVIMRC<CR>:PlugInstall<CR>
nnoremap <leader>vc :wa<Bar>silent! so $MYVIMRC<CR>:PlugClean<CR>
nnoremap <leader>vu :wa<Bar>silent! so $MYVIMRC<CR>:PlugUpdate<CR>
" test vim startup time
nnoremap <leader>vt :call TimingVimStartup(1)<CR>
nnoremap <leader>vT :call TimingVimStartup(0)<CR>
" toggle paste mode
nnoremap <leader>p :set paste!<CR>
" toggle list char
nnoremap <leader>l :set list!<CR>
" toggle tab/spaces
nnoremap <leader>t :call TabToggle()<CR>
" strip trailing whitespaces
" https://vi.stackexchange.com/a/2285
nnoremap <leader>s :let _s=@/<Bar>:%s/\s\+$//e<Bar>:let @/=_s<Bar><CR>
" search the word under the cursor
nnoremap <leader>a :Ack!<CR>
" search the given word
nnoremap <leader>A :Ack!<Space>
" christoomey/vim-system-copy
nmap cy <Plug>SystemCopy
xmap cy <Plug>SystemCopy
nmap cY <Plug>SystemCopyLine
nmap cp <Plug>SystemPaste
xmap cp <Plug>SystemPaste
nmap cP <Plug>SystemPasteLine
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。