137 lines
4.4 KiB
VimL
137 lines
4.4 KiB
VimL
" Plugins ######################################################################
|
|
" Auto completion
|
|
packadd! coc.nvim
|
|
source $XDG_CONFIG_HOME/vim/coc.nvim.vim
|
|
" Theme
|
|
packadd! onedark.vim
|
|
" Git information
|
|
packadd! vim-gitgutter
|
|
|
|
" Keybinds #####################################################################
|
|
" Set leader key
|
|
let mapleader = "\<Space>"
|
|
" Stop highlighting search result when pressing Return
|
|
nnoremap <silent> <CR> :nohlsearch<CR><CR>
|
|
|
|
" Indentation jump
|
|
" https://vim.fandom.com/wiki/Move_to_next/previous_line_with_same_indentation
|
|
noremap <silent> <C-k> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%<' . line('.') . 'l\S', 'be')<CR>
|
|
noremap <silent> <C-j> :call search('^'. matchstr(getline('.'), '\(^\s*\)') .'\%>' . line('.') . 'l\S', 'e')<CR>
|
|
|
|
" Split view navigation
|
|
nnoremap <leader>h <C-w><C-h>
|
|
nnoremap <leader>j <C-w><C-j>
|
|
nnoremap <leader>k <C-w><C-k>
|
|
nnoremap <leader>l <C-w><C-l>
|
|
|
|
" Settings #####################################################################
|
|
" hybrid linenumbers
|
|
set number relativenumber
|
|
" no timeout when exiting insert-mode
|
|
" (see https://www.johnhawthorn.com/2012/09/vi-escape-delays/)
|
|
set timeoutlen=1000 ttimeoutlen=0
|
|
" smart case insensitive search (insens: /copy /Copy\c; sens: /Copy /copy\C)
|
|
set ignorecase smartcase
|
|
" Tab size
|
|
set tabstop=4
|
|
" Shift the same amount as tabstop
|
|
set shiftwidth=0
|
|
" Highlight current line
|
|
set cursorline
|
|
" Automatically add leading comment (when pressing o/O or enter in Insert)
|
|
set formatoptions+=cro
|
|
" see :help persistent-undo
|
|
set undofile
|
|
" Update every 300ms for better experience with plugins like gitgutter and coc
|
|
set updatetime=300
|
|
" Check for spelling in comments and strings
|
|
set spell spelllang=en_us
|
|
" Show the effect of a command while typing (substitute)
|
|
if (has('nvim'))
|
|
set inccommand=nosplit
|
|
endif
|
|
" Put new window below/right of current
|
|
set splitbelow splitright
|
|
|
|
" Aesthetics ###################################################################
|
|
" Use 24-bit (true-color) mode
|
|
if (has('termguicolors'))
|
|
set termguicolors
|
|
" https://github.com/vim/vim/issues/993
|
|
if (&term != 'xterm-256color')
|
|
" set Vim-specific sequences for RGB colors
|
|
let &t_8f = "\e[38;2;%lu;%lu;%lum"
|
|
let &t_8b = "\e[48;2;%lu;%lu;%lum"
|
|
endif
|
|
endif
|
|
" use onedark as theme for syntax highlighting
|
|
syntax on
|
|
colorscheme onedark
|
|
|
|
" get transparent background of the terminal back
|
|
" (at least in nvim, i can't get it to work in vanilla)
|
|
if (has('nvim'))
|
|
highlight Normal guibg=NONE
|
|
highlight NonText guibg=NONE
|
|
endif
|
|
|
|
" zshOption is a huge regex that leads to massive lags when scrolling
|
|
" Be sure to disable it after activating syntax highlighting
|
|
autocmd filetype zsh syntax clear zshOption
|
|
|
|
" change cursor shape depending on mode
|
|
if (has('nvim'))
|
|
" Beam when exiting
|
|
autocmd VimLeave * silent !echo -ne "\e[5 q"
|
|
else
|
|
" https://vim.fandom.com/wiki/Change_cursor_shape_in_different_modes
|
|
" https://github.com/tmux/tmux/issues/1593
|
|
if exists('$TMUX')
|
|
" Start insert mode - vertical bar/beam
|
|
let &t_SI = "\ePtmux;\e\e[5 q\e\\"
|
|
" Start replace mode - horizontal bar/underline
|
|
let &t_SR = "\ePtmux;\e\e[3 q\e\\"
|
|
" End insert or replace mode - block
|
|
let &t_EI = "\ePtmux;\e\e[1 q\e\\"
|
|
|
|
" Block when entering
|
|
autocmd VimEnter * silent !echo -ne "\ePtmux;\e\e[1 q\e\\"
|
|
" Beam when exiting
|
|
autocmd VimLeave * silent !echo -ne "\ePtmux;\e\e[5 q\e\\"
|
|
else
|
|
" Start insert mode - vertical bar/beam
|
|
let &t_SI = "\e[5 q"
|
|
" Start replace mode - horizontal bar/underline
|
|
let &t_SR = "\e[3 q"
|
|
" End insert or replace mode - block
|
|
let &t_EI = "\e[1 q"
|
|
|
|
" Block when entering
|
|
autocmd VimEnter * silent !echo -ne "\e[1 q"
|
|
" Beam when exiting
|
|
autocmd VimLeave * silent !echo -ne "\e[5 q"
|
|
endif
|
|
endif
|
|
|
|
" Highlight trailing whitespaces
|
|
" (https://vim.fandom.com/wiki/Highlight_unwanted_spaces)
|
|
" Create highlight group
|
|
highlight ExtraWhitespace ctermbg=red guibg=red
|
|
" Associate with patter (trailing whitespaces)
|
|
match ExtraWhitespace /\s\+$/
|
|
" apply not only to the first window
|
|
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
|
|
" Do not match when typing at the end of a line
|
|
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
|
|
" Reset when leaving insert mode
|
|
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
|
|
" Clear all matches
|
|
autocmd BufWinLeave * call clearmatches()
|
|
|
|
" Show ruler at 80 and 100 columns
|
|
set colorcolumn=80,100
|
|
" Shorter lines in git commits
|
|
autocmd filetype gitcommit set colorcolumn=50,72
|
|
" Spell checking in git commits
|
|
autocmd filetype gitcommit set spell spelllang=en_us
|