395 lines
11 KiB
VimL
395 lines
11 KiB
VimL
" basic settings
|
|
let mapleader=";"
|
|
set ts=4
|
|
set sw=4
|
|
set cc=120
|
|
set expandtab
|
|
set nu
|
|
set hidden
|
|
set list
|
|
set autoindent
|
|
set confirm
|
|
set noundofile
|
|
set nobackup
|
|
set nowritebackup
|
|
set hlsearch
|
|
set noswapfile
|
|
set ignorecase
|
|
set smarttab
|
|
set smartindent
|
|
set smartcase
|
|
set cursorline
|
|
set incsearch
|
|
set signcolumn=yes
|
|
set laststatus=2
|
|
set fillchars=vert:\ ,fold:-
|
|
set clipboard=unnamedplus " system clipboard as default register. for vim to work need installing gvim package
|
|
set mouse=a
|
|
set spell
|
|
set scrolloff=8
|
|
filetype plugin indent on
|
|
syntax on
|
|
au! BufWritePost $MYVIMRC source %
|
|
|
|
cnoremap <C-a> <Home>
|
|
cnoremap <C-e> <End>
|
|
cnoremap <C-f> <Right>
|
|
cnoremap <C-b> <Left>
|
|
cnoremap <C-d> <Delete>
|
|
cnoremap <C-n> <Down>
|
|
cnoremap <C-p> <Up>
|
|
|
|
inoremap <C-a> <Home>
|
|
inoremap <C-e> <End>
|
|
inoremap <C-f> <Right>
|
|
inoremap <C-b> <Left>
|
|
inoremap <C-d> <Delete>
|
|
inoremap <C-n> <Down>
|
|
inoremap <C-p> <Up>
|
|
|
|
noremap <C-a> <Home>
|
|
noremap <C-e> <End>
|
|
noremap <C-f> <Right>
|
|
noremap <C-b> <Left>
|
|
|
|
vnoremap <leader>p pgvy
|
|
nnoremap Q :qall<CR>
|
|
nnoremap <leader>v <c-v>
|
|
nnoremap <leader>bb :b#<CR>
|
|
|
|
nnoremap <leader>1 :b1<CR>
|
|
nnoremap <leader>2 :b2<CR>
|
|
nnoremap <leader>3 :b3<CR>
|
|
nnoremap <leader>4 :b4<CR>
|
|
nnoremap <leader>5 :b5<CR>
|
|
nnoremap <leader>w :w<CR>
|
|
nnoremap <leader><Esc> :noh<return><esc>
|
|
|
|
nnoremap <leader>h <C-w>h
|
|
nnoremap <leader>j <C-w>j
|
|
nnoremap <leader>k <C-w>k
|
|
nnoremap <leader>l <C-w>l
|
|
nnoremap <leader>oo <C-w>o
|
|
nnoremap <leader>q <C-w>q
|
|
nnoremap <leader>x :!chmod +x %<Cr>
|
|
nnoremap <leader>X :!chmod -x %<Cr>
|
|
nnoremap <leader>scb :set scrollbind!<Cr>:set cursorbind!<Cr>
|
|
|
|
|
|
function! GetXCopyCmd()
|
|
let l:status = system("command -v termux-clipboard-set")
|
|
if len(l:status) > 0
|
|
return "termux-clipboard-set"
|
|
endif
|
|
return "xclip -selection clipboard"
|
|
endfunction
|
|
|
|
let g:xcopy = GetXCopyCmd()
|
|
|
|
function! XCopy()
|
|
" Why is this not a built-in Vim script function?!
|
|
let [line_start, column_start] = getpos("'<")[1:2]
|
|
let [line_end, column_end] = getpos("'>")[1:2]
|
|
let lines = getline(line_start, line_end)
|
|
if len(lines) == 0
|
|
return ''
|
|
endif
|
|
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
|
|
let lines[0] = lines[0][column_start - 1:]
|
|
call system(g:xcopy, join(lines, "\n"))
|
|
endfunction
|
|
|
|
function! YankFileLineNo()
|
|
let yl=expand("%") . ':' . line(".")
|
|
call system('tmux set-buffer "'.yl.'"')
|
|
call system(g:xcopy, yl)
|
|
endfunction
|
|
|
|
xnoremap <leader>y <esc>:call XCopy()<CR>
|
|
nnoremap <leader>yl <esc>:call YankFileLineNo()<Cr>
|
|
|
|
nmap <leader>"" ysiW"
|
|
nmap <leader>'' ysiW'
|
|
nmap <leader>" ysiw"
|
|
nmap <leader>' ysiw'
|
|
nmap <leader>`` ysiW`
|
|
nmap <leader>` ysiw`
|
|
|
|
nmap <leader>sb :windo set scrollbind<CR>:windo set cursorbind<CR>:set mouse=a<CR>
|
|
nmap <leader>nsb :windo set noscrollbind<CR>:windo set nocursorbind<CR>:set mouse=<CR>
|
|
|
|
inoremap <C-w> <esc><C-w>
|
|
nmap <silent> <leader>ss :syntax sync fromstart<CR>
|
|
|
|
" // to search highlighted text
|
|
vnoremap // y/\V<C-R>=escape(@",'/\')<CR><CR>
|
|
|
|
" trailing spaces
|
|
highlight ExtraWhitespace ctermbg=red guibg=red
|
|
au ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red
|
|
au Syntax * match ExtraWhitespace /\s\+$/
|
|
nnoremap <leader>es :%s/\s\+$//g<CR>
|
|
|
|
" location jumping
|
|
nnoremap <leader>n :cnext<CR>
|
|
nnoremap <leader>p :cprev<CR>
|
|
|
|
" cusorline
|
|
nnoremap <leader>c :set cursorcolumn!<CR>
|
|
|
|
" auto install vim-plug
|
|
if has('nvim')
|
|
if has('win32')
|
|
let vim_plug_path = $LOCALAPPDATA . "/nvim/autoload/plug.vim"
|
|
else
|
|
let vim_plug_path = expand("~/.config/nvim/autoload/plug.vim")
|
|
endif
|
|
else
|
|
set ttymouse=sgr
|
|
"map <ScrollWheelUp> <C-Y>
|
|
"map <ScrollWheelDown> <C-E>
|
|
let vim_plug_path = expand("~/.vim/autoload/plug.vim")
|
|
set listchars=eol:\ ,tab:>\ ,trail:~,extends:>,precedes:<
|
|
endif
|
|
let vim_plug_just_installed = 0
|
|
if !filereadable(vim_plug_path)
|
|
echo "Installing vim-plug..."
|
|
:exe "!curl -fLo \"" . vim_plug_path . "\" --create-dirs https://gitee.com/klesh/vim-plug/raw/master/plug.vim"
|
|
let vim_plug_just_installed = 1
|
|
echo "vim-plug installed"
|
|
endif
|
|
|
|
call plug#begin('~/.vim/plugged')
|
|
Plug 'editorconfig/editorconfig-vim'
|
|
Plug 'tpope/vim-surround'
|
|
Plug 'jiangmiao/auto-pairs'
|
|
Plug 'posva/vim-vue', { 'for': 'vue' }
|
|
Plug 'tpope/vim-repeat'
|
|
Plug 'liuchengxu/eleline.vim'
|
|
Plug 'tpope/vim-fugitive' " git 功能
|
|
Plug 'scrooloose/nerdcommenter'
|
|
Plug 'mhinz/vim-grepper', { 'on': ['Grepper', '<plug>(GrepperOperator)'] }
|
|
Plug 'morhetz/gruvbox'
|
|
Plug 'klesh/vim-fish', { 'for': 'fish' }
|
|
Plug 'alvan/vim-closetag'
|
|
"Plug 'francoiscabrol/ranger.vim'
|
|
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
|
|
Plug 'junegunn/fzf.vim'
|
|
Plug 'voldikss/vim-floaterm'
|
|
Plug 'preservim/nerdtree'
|
|
|
|
if $VIM_MODE == 'enhanced'
|
|
if !executable("node") || !executable("npm")
|
|
echo "nodejs/npm must be installed in order to use coc.nvim"
|
|
else
|
|
Plug 'neoclide/coc.nvim', {'branch': 'release'}
|
|
end
|
|
Plug 'chrisbra/Colorizer'
|
|
Plug 'tpope/vim-markdown', { 'for': 'markdown' }
|
|
Plug 'cespare/vim-toml', { 'for': 'toml' }
|
|
Plug 'vim-scripts/mom.vim'
|
|
else
|
|
Plug 'Vimjas/vim-python-pep8-indent', { 'for': 'python' }
|
|
endif
|
|
if has('win32')
|
|
Plug 'zigford/vim-powershell'
|
|
endif
|
|
call plug#end()
|
|
|
|
" ==== vim-markdown configuration ====
|
|
let g:vim_markdown_folding_disabled = 1
|
|
|
|
|
|
" ==== vim-closetag configuration ====
|
|
let g:closetag_filetypes = 'html,xhtml,phtml,vue,jsx'
|
|
|
|
|
|
if $VIM_MODE == 'enhanced'
|
|
" ==== coc configuration ====
|
|
let g:coc_global_extensions = [
|
|
\ 'coc-diagnostic',
|
|
\ 'coc-clangd'
|
|
\ ]
|
|
"let g:coc_disable_startup_warning = 1
|
|
set statusline^=%{coc#status()}
|
|
nmap <silent> gd <Plug>(coc-definition)
|
|
nmap <silent> gy <Plug>(coc-type-definition)
|
|
nmap <silent> gi <Plug>(coc-implementation)
|
|
nmap <silent> gr <Plug>(coc-references)
|
|
|
|
xmap <silent> <leader>fs <Plug>(coc-format-selected)
|
|
nmap <silent> <leader>fs <Plug>(coc-format-selected)
|
|
nmap <silent> <leader>fd <Plug>(coc-format)
|
|
nmap <silent> <leader>rn <Plug>(coc-rename)
|
|
nmap <silent> <leader>ne <Plug>(coc-diagnostic-next-error)
|
|
nmap <silent> <leader>pe <Plug>(coc-diagnostic-prev-error)
|
|
nmap <silent> <leader>oi :CocInfo<CR>
|
|
"nmap <silent> <leader>ol :<C-u>CocList<CR>
|
|
nmap <silent> <leader>olr :<C-u>CocListResume<CR>
|
|
nmap <silent> <leader>od :call CocAction('doHover')<CR>
|
|
nmap <silent> <leader>ol <Plug>(coc-openlink)
|
|
nmap <silent> <leader>oc :CocCommand<CR>
|
|
|
|
autocmd BufEnter,BufRead,BufNewFile *.js set syntax=typescript
|
|
|
|
" ==== vimspector configuration ====
|
|
let g:vimspector_enable_mappings = 'VISUAL_STUDIO'
|
|
let g:vimspector_install_gadgets = [ 'debugpy', 'vscode-cpptools' ]
|
|
endif
|
|
|
|
" ==== auto-pairs configuration ====
|
|
nmap <silent> <leader>ap :call AutoPairsToggle()<CR>
|
|
let g:AutoPairsShortcutToggle = ''
|
|
|
|
" ==== closetag configuration ====
|
|
nmap <silent> <leader>ct :CloseTagToggleBuffer<CR>
|
|
|
|
|
|
" ==== grepper configuration ====
|
|
"
|
|
nnoremap <leader>sg :Grepper -noquickfix -tool git<CR>
|
|
nnoremap <leader>sc :Grepper -noquickfix -tool grep<CR>
|
|
nnoremap <leader>sa :Grepper -noquickfix -tool ag<CR>
|
|
|
|
" ==== quickfix configuration ====
|
|
nnoremap <leader>cj :cn<CR>
|
|
nnoremap <leader>ck :cp<CR>
|
|
|
|
|
|
"" ==== NERDTree configuration ====
|
|
"nnoremap <leader>fe :NERDTreeToggle<CR>
|
|
|
|
|
|
" ==== Ranger configuration ====
|
|
let g:ranger_map_keys = 0
|
|
"nnoremap <C-t> :Ranger<CR>
|
|
|
|
|
|
" ==== netrw configuration ====
|
|
nnoremap <C-t> :Explore<CR>
|
|
|
|
autocmd BufEnter,BufRead nnoremap <leader>cg :<C-u>call OpenRangerIn(system("git rev-parse --show-toplevel >/dev/null || pwd"), 'edit ')<CR>
|
|
|
|
|
|
" ==== fugitive configuration ====
|
|
nnoremap <leader>gs :Git<CR>
|
|
nnoremap <leader>gc :Git commit<CR>
|
|
nnoremap <leader>gp :Git push<CR>
|
|
nnoremap <leader>gg :Git pull<CR>
|
|
nnoremap <leader>gd :Git diff<CR>
|
|
nnoremap <leader>gb :Git blame<CR>
|
|
nnoremap <leader>gl :Git log<CR>
|
|
nnoremap <leader>gms :Gvdiffsplit!<CR>
|
|
nnoremap <leader>gmh :diffget //2<CR>
|
|
nnoremap <leader>gml :diffget //3<CR>
|
|
nnoremap <leader>gsc :exec "!git switch -c " . input("Enter new branch name:")<CR>
|
|
|
|
" ==== functions ======
|
|
fu! SilentOK(cmd)
|
|
let l:output = system(substitute(a:cmd, "%", expand("%"), "g"))
|
|
if v:shell_error != 0
|
|
echo l:output
|
|
endif
|
|
endfu
|
|
|
|
fu! SystemOr(cmd, default)
|
|
let l:output = system(substitute(a:cmd, "%", expand("%"), "g"))
|
|
if v:shell_error != 0
|
|
return a:default
|
|
endif
|
|
return trim(l:output)
|
|
endfu
|
|
|
|
|
|
|
|
" ==== ctrlp configuration ====
|
|
"let g:ctrlp_user_command = ['.git', 'git ls-files -co --exclude-standard']
|
|
|
|
" ==== fzf configuration ====
|
|
" enable <C-p> for fzf
|
|
let g:fugitive_no_maps=1
|
|
let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git -l -g ""'
|
|
|
|
nnoremap <C-p> :call fzf#vim#files(SystemOr("git rev-parse --show-toplevel", "."))<Cr>
|
|
nnoremap <leader>gco :call fzf#run({'source': 'git branch \| cut -c 3-; git tag -l', 'sink': '!git checkout'})<CR>
|
|
nnoremap <leader>gm :call fzf#run({'source': 'git branch \| cut -c 3-', 'sink': '!git merge'})<CR>
|
|
nnoremap <leader>b :Buffers<CR>
|
|
|
|
|
|
" ==== gruvbox configuration ====
|
|
color gruvbox
|
|
set background=dark
|
|
" for background transparence to work
|
|
highlight Normal ctermbg=None
|
|
highlight CursorLine ctermbg=240
|
|
|
|
" ==== NERDCommenter for vue ====
|
|
let g:ft = ''
|
|
fu! NERDCommenter_before()
|
|
if &ft == 'vue'
|
|
let g:ft = 'vue'
|
|
let stack = synstack(line('.'), col('.'))
|
|
if len(stack) > 0
|
|
let syn = synIDattr((stack)[0], 'name')
|
|
if len(syn) > 0
|
|
let syn = tolower(syn)
|
|
exe 'setf '.syn
|
|
endif
|
|
endif
|
|
endif
|
|
endfu
|
|
fu! NERDCommenter_after()
|
|
if g:ft == 'vue'
|
|
setf vue
|
|
g:ft
|
|
endif
|
|
endfu
|
|
|
|
" ==== groff ====
|
|
|
|
fu! ToggleGroffMomAutoCompilation()
|
|
let g:GroffMomAutoCompilation = !get(g:, "GroffMomAutoCompilation", 0)
|
|
|
|
augroup GroffPdf
|
|
autocmd!
|
|
augroup END
|
|
|
|
if g:GroffMomAutoCompilation
|
|
augroup GroffPdf
|
|
autocmd BufWritePost,FileWritePost *.mom :call SilentOK("groff -Kutf8 -mom % > /tmp/tmp.ps && ps2pdf /tmp/tmp.ps %.pdf")
|
|
augroup END
|
|
echo "Auto compilation for groff_mom enabled"
|
|
else
|
|
echo "Auto compilation for groff_mom disabled"
|
|
endif
|
|
endfu
|
|
nnoremap <leader>ac :call ToggleGroffMomAutoCompilation()<CR>
|
|
autocmd BufEnter,BufRead *.mom :set ft=mom
|
|
|
|
" spell highlight
|
|
highlight clear SpellBad
|
|
highlight SpellBad cterm=underline
|
|
highlight SpellBad gui=undercurl
|
|
|
|
" commitmsg
|
|
autocmd BufEnter,BufRead commitmsg.md :set colorcolumn=100
|
|
|
|
" ==== nerdtree ====
|
|
nnoremap <leader>t :NERDTreeToggle<CR>
|
|
|
|
" go organize import on save
|
|
" ==== golang ====
|
|
command! -nargs=0 OR :call CocAction('runCommand', 'editor.action.organizeImport')
|
|
autocmd BufWritePre *.go :OR
|
|
|
|
" ==== floaterm ====
|
|
nnoremap <leader>tt :FloatermNew nnn<CR>
|
|
let g:floaterm_autohide=1
|
|
let g:floaterm_autoclose=1
|
|
let g:floaterm_shell='fish'
|
|
let g:floaterm_opener='edit'
|
|
let g:floaterm_keymap_new = '<F7>'
|
|
let g:floaterm_keymap_prev = '<F8>'
|
|
let g:floaterm_keymap_next = '<F9>'
|
|
let g:floaterm_keymap_toggle = '<F12>'
|