dot/config/vim/vimrc

401 lines
12 KiB
VimL
Raw Normal View History

" Basic settings {{{
set encoding=utf-8
set nocompatible
set autoread
set title
syntax enable
filetype plugin on
" better comand line completion
set wildmenu
set showcmd
" allow buffer switching without saving
set hidden
" yes we have got 256 colors even if you don't know st vim
set t_Co=256
" linenumbers and standardscheme
set number
set relativenumber
set tabstop=2
" To better see search results
set hlsearch
set incsearch
" Allow backspacing over autoindent, line breaks and start of insert action
set backspace=indent,eol,start
" }}}
2023-05-27 19:10:48 +02:00
" Kitty support {{{
" Mouse support
set mouse=a
set ttymouse=sgr
set balloonevalterm
set termguicolors
" Styled and colored underline support
let &t_AU = "\e[58:5:%dm"
let &t_8u = "\e[58:2:%lu:%lu:%lum"
let &t_Us = "\e[4:2m"
let &t_Cs = "\e[4:3m"
let &t_ds = "\e[4:4m"
let &t_Ds = "\e[4:5m"
let &t_Ce = "\e[4:0m"
" Strikethrough
let &t_Ts = "\e[9m"
let &t_Te = "\e[29m"
" Truecolor support
let &t_8f = "\e[38:2:%lu:%lu:%lum"
let &t_8b = "\e[48:2:%lu:%lu:%lum"
let &t_RF = "\e]10;?\e\\"
let &t_RB = "\e]11;?\e\\"
" Bracketed paste
let &t_BE = "\e[?2004h"
let &t_BD = "\e[?2004l"
let &t_PS = "\e[200~"
let &t_PE = "\e[201~"
" Cursor control
let &t_RC = "\e[?12$p"
let &t_SH = "\e[%d q"
let &t_RS = "\eP$q q\e\\"
let &t_SI = "\e[5 q"
let &t_SR = "\e[3 q"
let &t_EI = "\e[1 q"
let &t_VS = "\e[?12l"
" Focus tracking
let &t_fe = "\e[?1004h"
let &t_fd = "\e[?1004l"
execute "set <FocusGained>=\<Esc>[I"
execute "set <FocusLost>=\<Esc>[O"
" Window title
let &t_ST = "\e[22;2t"
let &t_RT = "\e[23;2t"
" vim hardcodes background color erase even if the terminfo file does
" not contain bce. This causes incorrect background rendering when
" using a color theme with a background color in terminals such as
" kitty that do not support background color erase.
let &t_ut=''
" }}}
" Mappings {{{
" set leader keys
let mapleader = ","
let maplocalleader = "."
" this has to be recursive to work
nmap <space> <leader>
" get out of insert mode without all the way to esc
inoremap jk <esc>
inoremap jl <esc>:w<cr>
noremap <leader>qq :qa!<cr>
noremap <leader>ww :w!<cr>
" move left and right in insert mode
inoremap <c-l> <right>
inoremap <c-h> <left>
" open terminal and get back out
nnoremap <leader>otl :below vert terminal zsh<CR>
nnoremap <leader>oth :vert terminal zsh<CR>
" window quit, only, revert
noremap <leader>wq <C-W>q
noremap <leader>wo <C-W>o
noremap <leader>wr <C-W>r
" window movement
noremap <silent> <leader>wj :call <SID>SplitOrMove("j")<cr>
noremap <silent> <leader>wk :call <SID>SplitOrMove("k")<cr>
noremap <silent> <leader>wh :call <SID>SplitOrMove("h")<cr>
noremap <silent> <leader>wl :call <SID>SplitOrMove("l")<cr>
" edit vimrc fast
nnoremap <leader>rv :source $MYVIMRC<CR> :let &ft=&ft<CR>
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" copy/paste from clipboard
2022-04-30 19:44:53 +02:00
xnoremap <leader>ytc y:call system('xclip -selection clipboard', @0)<CR>
nnoremap <leader>pfc !!xclip -out -selection clipboard<CR>
" }}}
" Search mappings {{{
"
" Search very magically! I don't know why I have ever added this. I mean, I
" know why I have added it because the guy in learn vimscript the hardware
" told me too, but it seriously makes finding stuff much harder.
nnoremap / /\v
nnoremap ? ?\v
" clear last search hl
nnoremap <leader>// :let @/ = ""<cr>
" highlight trailing whitespaces
nnoremap <leader>/t :execute "match Error " . '/\v\s+$/'<cr>
nnoremap <leader>/T :execute "match Error //"<cr>
" grep for word with range of motion
nnoremap <leader>g :silent execute ":grep! -R " . shellescape(expand("<cword>")) . " ."<cr>:copen<cr>
" }}}
" Operator pending mapping {{{
" edit inside next/last parantheses/curly bracket
onoremap in( :<c-u>normal! f(vi(<cr>
onoremap il( :<c-u>normal! F)vi(<cr>
onoremap in{ :<c-u>normal! f{vi{<cr>
onoremap il{ :<c-u>normal! F}vi{<cr>
" change insided &
onoremap i& :<c-u>normal! t&vT&<cr>
" around next/last parantheses/curly bracket
onoremap an( :normal! f(0vt(<cr>
onoremap al( :<c-u>normal! F(0vt(<cr>
" inside next search
onoremap ins :<c-u>execute "normal! gn"<cr>
" }}}
2022-04-30 19:44:53 +02:00
" netrw {{{
2023-05-27 19:10:48 +02:00
let g:netrw_dirhistmax = 0 " do not create netrwhist
2022-04-30 19:44:53 +02:00
let g:netrw_banner = 0
2023-05-27 19:10:48 +02:00
let g:netrw_browse_split = 0 " 0 = re-using, 1 h split, 2 v split, 3 new tab, 4 like P
2022-04-30 19:44:53 +02:00
let g:netrw_browsex_viewer= "xdg-open"
2023-05-27 19:10:48 +02:00
let g:netrw_keepdir = 0
let g:netrw_list_hide = '\(^\|\s\s\)\zs\.\S\+'
let g:netrw_liststyle = 0 " 3 = tree; 0 = flat
let g:netrw_preview = 1
let g:netrw_winsize = 25
noremap <leader>t :Lexplore<CR> " open nerdtree
2022-04-30 19:44:53 +02:00
" }}}
" Random mappings {{{
" surround current word by quotes
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
vnoremap <leader>" <esc>`<i"<esc>`>la"<esc>he
" uppercase current word in insert mode
inoremap <leader>u <Esc>viwUea
" uppercase current word in normal mode
nnoremap <leader>u viwU
" move current line down and up in normal mode
nnoremap <leader>- ddp
nnoremap <leader>_ ddkP
" clear current line
nnoremap <leader>d 0d$
nnoremap <leader>cn :cnext<cr>
nnoremap <leader>cp :cprevious<cr>
" remove windows line endings
nnoremap <leader>rw :%s/<C-V><C-M>//g<CR>
" remove trailing spaces
nnoremap <leader>rt mb:%s/\s\+$//<CR>:let @/ = ""<CR>'b:w<cr>
" Show syntax highlighting groups for word under cursor
nmap <leader>z :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" }}}
" Filetype python {{{
augroup filetype_python
autocmd!
" autocmd FileType python packadd custom-python
autocmd FileType python inoremap <buffer> <F5> <esc>:w<CR>:!pypy3 "%:p"<CR>
autocmd FileType python nnoremap <buffer> <F5> :w<CR>:!pypy3 "%:p"<CR>
augroup END
" }}}
" Filetype javascript {{{
augroup filetype_javascript
autocmd!
autocmd FileType javascript setlocal tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
augroup END
" }}}
" Filetype css {{{
augroup filetype_css
autocmd!
autocmd FileType css setlocal tabstop=2 softtabstop=0 expandtab shiftwidth=2 smarttab
autocmd FileType css setlocal foldmethod=marker
autocmd FileType css setlocal foldmarker=/begin,/end
augroup END
" }}}
" Filetype c {{{
augroup filetype_c
autocmd!
autocmd FileType c setlocal tabstop=4 shiftwidth=4 expandtab autoindent smarttab formatoptions=croql nu
autocmd FileType c nnoremap <buffer> <localleader>c I//<esc>0
autocmd FileType c vnoremap <buffer> <localleader>c <esc>`>a*/<esc>`<i/*<esc>
augroup END
augroup filetype_cpp
autocmd!
autocmd FileType cpp setlocal tabstop=4 shiftwidth=4 expandtab autoindent smarttab formatoptions=croql nu
augroup END
" }}}
" Filetype html {{{
augroup filetype_html
autocmd!
autocmd FileType html setlocal tabstop=4 softtabstop=0 expandtab shiftwidth=4 smarttab
autocmd FileType html nnoremap <buffer> <localleader>c 0i<!--<esc>A--><esc>0
autocmd FileType html nnoremap <buffer> <localleader>f Vatzf
augroup END
" }}}
" Filetype htmldjango {{{
augroup filetype_htmldjango
autocmd!
autocmd FileType htmldjango setlocal tabstop=2 softtabstop=0 expandtab shiftwidth=2 smarttab
augroup END
" }}}
" Filetype vimscript {{{
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal tabstop=2
autocmd FileType vim setlocal shiftwidth=2
autocmd FileType vim setlocal expandtab
autocmd FileType vim setlocal autoindent
autocmd FileType vim setlocal foldmethod=marker
augroup END
" }}}
" Filetype lua {{{
augroup filetype_lua
autocmd!
augroup END
" }}}
" Filetype tex {{{
augroup filetype_tex
autocmd!
autocmd FileType tex setlocal tabstop=2
autocmd FileType tex setlocal shiftwidth=2
autocmd FileType tex setlocal expandtab
autocmd FileType tex setlocal autoindent
augroup END
augroup filetype_cpp
autocmd!
autocmd FileType cpp setlocal tabstop=4 shiftwidth=4 expandtab autoindent smarttab formatoptions=croql nu
augroup END
" }}}
" Filetype xml {{{
augroup filetype_xml
autocmd!
autocmd FileType xml com! FormatXML :%!python3 -c "import xml.dom.minidom, sys; print(xml.dom.minidom.parse(sys.stdin).toprettyxml())"
autocmd FileType xml nnoremap = :FormatXML<Cr>
augroup END
" }}}
" Filetype json {{{
augroup filetype_json
autocmd!
autocmd FileType json com! FormatJSON :%!python3 -m "json.tool"
autocmd FileType json nnoremap = :FormatJSON<Cr>
autocmd FileType json setlocal autoindent
autocmd FileType json setlocal formatoptions=tcq2l
autocmd FileType json setlocal textwidth=78 shiftwidth=2
autocmd FileType json setlocal softtabstop=2 tabstop=8
autocmd FileType json setlocal expandtab
autocmd FileType json setlocal foldmethod=syntax
autocmd FileType json setlocal nowrap
augroup END
" }}}
" Filetype scheme {{{
augroup filetype_scheme
autocmd!
autocmd FileType scheme noremap <buffer> <leader>b :w<CR> :!mit-scheme < "%:p" --quiet<CR>
autocmd FileType scheme inoremap <buffer> <c-r> <esc>:w<CR>:!mit-scheme < "%:p" --quiet<CR>
autocmd FileType scheme setlocal autoindent
autocmd FileType scheme setlocal shiftwidth=2
autocmd FileType scheme setlocal softtabstop=2 tabstop=2
autocmd FileType scheme setlocal expandtab
autocmd FileType scheme setlocal nowrap
autocmd FileType scheme setlocal foldmethod=indent
augroup END
" }}}
" Filetype rust {{{
augroup filetype_rust
autocmd!
autocmd FileType rust noremap <buffer> <c-F5> :w<CR> :!cargo run --release<CR>
autocmd FileType rust inoremap <buffer> <c-F5> <esc>:w<CR>:!cargo run --release<CR>
autocmd FileType rust setlocal autoindent
autocmd FileType rust setlocal expandtab
autocmd FileType rust setlocal nowrap
" For use with
autocmd FileType rust nmap <F5> <Plug>(lcn-menu)
autocmd FileType rust nmap <silent> gd <Plug>(lcn-definition)
autocmd FileType rust nmap <silent>K <Plug>(lcn-hover)
augroup END
" }}}
" Votion {{{
let g:votion_dir = "~/owc"
nnoremap <leader>vo :RgVotion<CR>
nnoremap <leader>vt :RgVotionTitle<CR>
nnoremap <leader>vid :call votion#votion#GrepFiles()<CR>
let votion_dir = get(g:, 'votion_dir', '')
command! -bang -nargs=* RgVotion
\ call fzf#vim#grep(
\ 'rg --column --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>) .. ' ' .. votion_dir, 1,
\ fzf#vim#with_preview(), <bang>0)
command! -bang -nargs=* RgVotionTitle
\ call fzf#vim#grep(
\ 'rg -i --column --line-number --no-heading --color=always --smart-case -- ^title: ' .. shellescape(<q-args>) .. ' ' .. votion_dir, 1,
\ fzf#vim#with_preview({'options': ['--with-nth', '5..']}), <bang>0)
" }}}
" SplitOrMove function {{{
function! s:SplitOrMove(direction)
if winnr() !=# winnr(a:direction)
execute("normal \<c-w>" . a:direction)
else
if a:direction ==# 'l'
execute ":below vnew"
elseif a:direction ==# 'h'
execute ":vnew"
elseif a:direction ==# 'j'
execute ":below new"
elseif a:direction ==# 'k'
execute ":new"
endif
endif
endfunction
" }}}
2022-06-18 21:44:37 +02:00
" fzf {{{
noremap <leader>ob :Buffers<CR>
noremap <leader>of :Files<CR>
noremap <leader>gf :GFiles<CR>
noremap <leader>rg :Rg<CR>
2022-06-18 21:44:37 +02:00
command! -bang -nargs=? -complete=dir Files
2023-04-15 20:17:12 +02:00
\ call fzf#vim#files(<q-args>, {'options': ['--layout=reverse', '--info=inline', '--preview', 'bat --style=numbers --color=always --line-range :100 {}']}, <bang>0)
" }}}
" {{{ buffer handling
" buffer close
nnoremap <leader>bq :bp\|bd #<CR>
" buffer write
nnoremap <leader>bw :w<CR>
" buffer write and close
nnoremap <leader>bx :w<CR>:bd<CR>
" previous/next buffer
nnoremap <leader>bp :bprevious<CR>
nnoremap <leader>bn :bnext<CR>
" fuzzy search open buffers
noremap <leader>bo :Buffers<CR>
" }}}
" {{{ plugged
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf.vim'
Plug 'vim-airline/vim-airline'
Plug 'godlygeek/tabular'
Plug 'felixio@git.felixm.de:felixm/votion.git', {'for': 'markdown'}
2023-05-27 19:10:48 +02:00
Plug 'https://github.com/tpope/vim-vinegar'
" Plug 'flazz/vim-colorschemes'
2023-05-27 19:10:48 +02:00
Plug 'catppuccin/vim', { 'as': 'catppuccin' }
Plug 'autozimu/LanguageClient-neovim', {
\ 'branch': 'next',
\ 'do': 'bash install.sh',
\ 'for': 'rust',
\ }
call plug#end()
let g:LanguageClient_serverCommands = {
2023-01-25 22:48:31 +01:00
\ 'rust': ['rustup', 'run', 'stable', 'rust-analyzer'],
\ }
" }}}
2023-05-27 19:10:48 +02:00
" Statusline {{{
let g:airline_powerline_fonts = 1
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#enabled = 0
let g:airline_theme = 'catppuccin_latte'
" let g:airline_extensions = []
" }}}
colorscheme catppuccin_frappe