Rev. | 47c92fa04bdfe749611ef22e077bc691c162a827 |
---|---|
大小 | 11,238 字节 |
时间 | 2023-05-09 15:34:22 |
作者 | Markus Prepens |
Log Message | latest files from Mercurial
|
" platform dependent path seperator
let g:slash = exists('&shellslash') ? '\' : '/'
set termguicolors
set clipboard=unnamed
set mouse=a
set mousemodel=popup
set expandtab
set noswapfile
set report=0
set ruler
set showmatch
set matchtime=1
set nowrap
set nofoldenable
set relativenumber
set sessionoptions=buffers,curdir,tabpages,winsize,globals
" work more intuitive on visual selection
set selection=exclusive
" use g$ to move behind last word in current line
set virtualedit=onemore,block
" long form for file info
set shortmess-=f
" limit number of suggestions of z =
set spellsuggest=best,10
set spelllang=en_us
set spelloptions=camel
" Read changed files automatically if they are changed in the
" background. read more here :help :checktime
set autoread
" set behavior for commands ':cc', ':cn', 'cp', etc.
set switchbuf=useopen,uselast
" keep cursor line away from the upper and lower window border
set scrolloff=2
set scrolljump=1
" make vertical scrolling more smooth
set sidescroll=8
set sidescrolloff=3
" Write all files before any ':make' command
set autowrite
" timer configuration for key sequences
set notimeout
set nottimeout
" backspace and cursor keys wrap to previous/next line
" keep indent level when Ctrl-U is pressed
set backspace=eol,start,indent
" backspace and cursor keys wrap to previous/next line
set backspace=indent,eol,start
set whichwrap+=<,>,[,]
set jumpoptions=stack,view
" Search: Some configuration for the search behavior.
set ignorecase
set smartcase
" backups
let backup_dir=stdpath('data') .. g:slash .. 'backup'
if isdirectory(backup_dir)
set backup
execute "set backupdir="..backup_dir
set wildignore+=*/backup/*
end
" persistent undo
let undo_dir=stdpath('data') .. g:slash .. 'undo'
if isdirectory(undo_dir)
set undofile
execute "set undodir="..undo_dir
set wildignore+=*/undo/*
end
" Insert mode completion
set complete=.,w
set noshowfulltag
set completeopt=menu
set pumheight=7
set pumblend=6
" Command line completion
set wildmenu
set wildoptions=pum,tagfile
set wildmode=full
set nowildignorecase
set wildignore+=*.*~,*.o,TAGS
set wildcharm=<C-n>
" How to handle search for tags
set tagcase=followscs
" Tune the diff feature for my needs.
set diffopt=internal,algorithm:minimal,context:8,vertical,iwhite,filler,closeoff
command! ShowChanges vert new | set bt=nofile | r ++edit # | 0d_ | diffthis | wincmd p | diffthis
" Living with QWERTZ keyboards
execute "set langmap+=\<Char-246>["
execute "set langmap+=\<Char-228>]"
execute "set langmap+=\<Char-214>{"
execute "set langmap+=\<Char-196>}"
execute "set langmap+=\<Char-252>/"
execute "set langmap+=\<Char-220>?"
" Avoid other keyboard/terminal problems
nnoremap <C-CR> g<C-]>
inoremap <C-x><C-CR> <C-x><C-]>
inoremap <C-CR> <C-]>
" Switch to normal mode with special keys
inoremap <k0> <Esc>
imap <C-Space> <Esc>
" Resizing window
let GrowWin = { -> "3wincmd + | 5wincmd >" }
let ShrinkWin = { -> winnr("j")==winnr() ? "5wincmd <" : "3wincmd - | 5wincmd <" }
nnoremap <A-+> :<C-r>=GrowWin()<CR><CR>
nnoremap <A--> :<C-r>=ShrinkWin()<CR><CR>
" Consistent cursor movement
noremap! <A-Left> <Home>
noremap! <A-Right> <End>
nnoremap <A-Left> <Home>
nnoremap <A-Right> <End>
xnoremap <A-Left> 0
xnoremap <A-Right> $
" Alternative keys to delete words
inoremap <C-BS> <C-o>db
cnoremap <C-BS> <C-w>
inoremap <C-Del> <C-o>de
" Next/prev match,expand fold and recenter
nnoremap n nzzzv
nnoremap N Nzzzv
" Yank to and paste from clipboard
nnoremap <C-Insert> "*yiw
vnoremap <C-Insert> "*y
inoremap <C-Insert> <C-o>"*yiw
nnoremap <S-Insert> "*P
inoremap <S-Insert> <C-o>"*P
cnoremap <S-Insert> <C-r>*
" increment/decrement numbers blockwise
vnoremap <C-x> <C-x>gv
vnoremap <C-a> <C-a>gv
" Shift left/right highlighted lines/block [count] 'shiftwidth' and reselect
" visual region
vnoremap > >gv
vnoremap < <gv
" To map <Esc> to exit terminal-mode: >
tnoremap <Esc> <C-\><C-n>
tnoremap <LeftMouse> <C-\><C-n>
nnoremap <expr> <CR> &modifiable ? "o\<Esc>" : "\<CR>"
nnoremap <S-CR> O<Esc>
" Line bubbling, key mapping leant to scrolling keys C-e C-y
nnoremap <A-e> :move .-2<CR>==
vnoremap <A-e> :move '<-2<CR>==gv=gv
nnoremap <A-y> :move .+1<CR>==
vnoremap <A-y> :move '>+1<CR>==gv=gv
cnoremap <C-r>, <C-r>=stdpath("config") .. g:slash<CR>
cnoremap <C-r>. <C-r>=((expand("%:h") == "") ? "." : expand("%:h") ) .. g:slash<CR>
cnoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>"
cnoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
cnoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
cnoreabbrev <expr> vimgrep (getcmdtype() ==# ':' && getcmdline() =~# '^vimgrep') ? 'silent vimgrep' : 'vimgrep'
cnoreabbrev <expr> grep (getcmdtype() ==# ':' && getcmdline() =~# '^grep') ? 'silent grep' : 'grep'
cnoreabbrev <expr> make (getcmdtype() ==# ':' && getcmdline() =~# '^make') ? 'silent make' : 'make'
"
" Kill whitespace after abbrev expansion
" Example: iabbrev () ()<Left><C-r>=Killer(getchar(0))<CR>
let Killer = { c -> nr2char(c) =~ '\s' ? '' : nr2char(c) }
" Window movement {{{
nnoremap <A-h> <C-w>h
nnoremap <A-l> <C-w>l
nnoremap <A-k> <C-w>k
nnoremap <A-j> <C-w>j
inoremap <A-h> <Esc><C-w>h
inoremap <A-l> <Esc><C-w>l
inoremap <A-k> <Esc><C-w>k
inoremap <A-j> <Esc><C-w>j
noremap <S-Right> <C-w>l
noremap <S-Left> <C-w>h
noremap <S-Down> <C-w>j
noremap <S-Up> <C-w>k
imap <S-Right> <Esc><S-Right>
imap <S-Left> <Esc><S-Left>
imap <S-Down> <Esc><S-Down>
imap <S-Up> <Esc><S-Up>
tmap <C-w> <C-\><C-n><C-w>
tnoremap <S-Right> <C-\><C-n><C-w>l
tnoremap <S-Left> <C-\><C-n><C-w>h
tnoremap <S-Down> <C-\><C-n><C-w>j
tnoremap <S-Up> <C-\><C-n><C-w>k
" }}}
" Type a word, press below key sequence and "Enclose" `current` (word) {bang}!
inoremap <C-s>" <C-o>b"<Esc>ea"
inoremap <C-s>' <C-o>b'<Esc>ea'
inoremap <C-s>`` <C-o>b`<Esc>ea`
inoremap <C-s>) <C-o>b(<Esc>ea)
inoremap <C-s>] <C-o>b[<Esc>ea]
inoremap <C-s>} <C-o>b{<Esc>ea}
" Leader key mappings {{{
let mapleader = " "
let maplocalleader = "!"
" Edit files
nnoremap <Leader>, :edit <C-r>=stdpath("config") .. g:slash<CR>
nnoremap <Leader>. :edit <C-r>=((expand("%:h") == "") ? "." : expand("%:h") ) .. g:slash<CR>
" Leader-t space
nnoremap <Leader>tt <Cmd>tab split<CR>
nnoremap <Leader>tn <Cmd>tabnew<CR>
nnoremap <Leader>tc <Cmd>tabclose<CR>
" Leader-c space
nnoremap <Leader>c- <Cmd>colder<CR>
nnoremap <Leader>c+ <Cmd>cnewer<CR>
nnoremap <Leader>cn <Cmd>cnext<CR>
nnoremap <Leader>cp <Cmd>cprevious<CR>
nnoremap <Leader>cc <Cmd>cc<CR>
nnoremap <Leader>cf <Cmd>cfirst<CR>
nnoremap <Leader>cl <Cmd>clast<CR>
""" Toggle options
nnoremap <Leader>oh :set hlsearch! hlsearch?<CR>
nnoremap <Leader>os :setlocal spell! spell? spelllang?<CR>
nnoremap <Leader>op :setlocal paste! paste?<CR>
nnoremap <Leader>ow :setlocal wrap! wrap?<CR>
nnoremap <Leader>og :set grepprg=<C-r>=escape(&grepprg, ' ')<CR>
""" Replace command
nnoremap <Leader>s :%s/<C-r><C-w>//gI<Left><Left><Left>
vnoremap <Leader>s :s///gI<Left><Left><Left><Left>
""" Vimgrep
let g:ft2glob = #{ c:'*.[ch]$', vim:'*.vim', py:'*.py$', lua: '*.lua', cmake:'*cmake*' }
let LsFilter = { ft -> has_key(g:ft2glob, ft) ? g:ft2glob[ft] : '*.*'}
nnoremap <expr> <Leader>v ':silent vimgrep /' .. expand("<cword>") .. '/ ' .. expand("%:h") .. g:slash .. LsFilter(&ft)
" commands
nnoremap <Leader>e :edit <C-r>=((expand("%:h") == "") ? "." : expand("%:h") ) .. g:slash<CR>
nnoremap <Leader>q <Cmd>call <SID>ToggleQuickfix()<CR><Cmd>cc<CR>
nnoremap <Leader>f :find<Space>*
nnoremap <Leader>b :buffer<Space>
nnoremap <Leader>d <cmd>bdelete<CR>
" Leader-t space
nnoremap <Leader>tt <Cmd>tab split<CR>
nnoremap <Leader>tn <Cmd>tabnew<CR>
nnoremap <Leader>tc <Cmd>tabclose<CR>
" Leader-c space
nnoremap <silent> <Leader>c- <Cmd>colder<CR>
nnoremap <silent> <Leader>c+ <Cmd>cnewer<CR>
nnoremap <Leader>cn <Cmd>cnext<CR>
nnoremap <Leader>cN <Cmd>cprevious<CR>
nnoremap <Leader>cc <Cmd>cc<CR>
nnoremap <Leader>cf <Cmd>cfirst<CR>
nnoremap <Leader>cl <Cmd>clast<CR>
nnoremap <Leader>h <Cmd>ToggleHlWord<CR>
""" Call Wordnik
nnoremap <silent> <Leader>W :silent !start https://www.wordnik.com/words/<C-r>=tolower(expand("<cword>"))<CR><CR>
""" Toggle quickfix {{{
function! s:ToggleQuickfix()
let is_open = v:false
windo if &buftype== "quickfix" | let is_open = v:true | endif
if is_open == v:false
let qf = getqflist()
execute "botright" "copen" min([&lines/3, max([1, len(qf)])])
wincmd p
else
if (winnr("$") == 1) && (&buftype=="quickfix")
buffer #
else
cclose
wincmd p
endif
endif
endfunction
" }}}
" }}}
" Function keys {{{
nmap <F2> <Leader>e
imap <F2> <Esc><F1>
nmap <F3> <Leader>f
imap <F3> <Esc><F2>
nmap <F1> <Leader>b
imap <F1> <Esc><F3>
nnoremap <F5> <Cmd>call OpenTermHere()<CR>
imap <F5> <Esc><F5>
" }}}
command! -nargs=0 IC :set ignorecase nosmartcase
command! -nargs=0 CS :set noignorecase nosmartcase
command! -nargs=0 SC :set ignorecase smartcase
augroup GroupInit " {{{
autocmd!
autocmd WinEnter * checktime
autocmd BufEnter * if &pvw | setlocal nonu nornu | endif
autocmd BufNewFile .vimrc execute "0read" g:vim_home.."\\templates\\local_vimrc"
autocmd VimEnter * execute "colorscheme " .. (exists("g:GuiLoaded") ? "twotone" : "apollo")
autocmd FocusLost * silent wall
autocmd TextYankPost * silent! lua vim.highlight.on_yank {higroup="Visual", timeout=350}
autocmd TermOpen * setlocal winhighlight=Normal:CursorLine,NormalNC:CursorLine nonumber norelativenumber
augroup END
" }}}
inoremap <expr> <Tab> v:lua.smart_tab('<C-n>')
inoremap <expr> <S-Tab> v:lua.smart_tab('<C-p>')
" My custom statusline {{{
set statusline=%!BuildStatusline()
set laststatus=2
let g:mode_translation = {
\ 'n' : 'NORMAL',
\ 'v' : 'VISUAL',
\ 'V' : 'V·LINE',
\ "\<C-V>" : 'V·BLK',
\ 'i' : 'INSERT',
\ 'R' : 'R',
\ 'Rv' : 'V·REPLACS',
\ 'c' : 'CMD',
\ 't' : 'TERM',
\}
function! GetMode()
let m = mode()
if has_key(g:mode_translation, m)
return g:mode_translation[m]
endif
return m
endfunction
let GetSearchMode = { -> v:lua.get_search_mode() }
let GetUniqueName = { -> v:lua.get_unique_path() }
function! BuildStatusline()
let sl = ""
if win_getid() == g:statusline_winid
let sl .= "%1* %{GetMode()} %*"
endif
let sl .= " %y%w[%{GetSearchMode()}]%*"
let sl .= "%=%{GetUniqueName()}%t%m"
let sl .= "%=%l:%c "
return sl
endfunction
" }}}
function! OpenTermHere()
execute "cd" expand("%:h")
split +terminal
startinsert
execute "cd -"
endfunction
" Compact mouse menu {{{
try
aunmenu PopUp.How-to\ disable\ mouse
"aunmenu PopUp.-1-
catch /E329.*/
endtry
" }}}
let g:term = &term
syntax on
" vim:foldmethod=marker:foldenable: