123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266 |
- " vim: foldmethod=marker
- " Basic Settings {{{1
- filetype plugin indent on
- set encoding=utf-8
- set ff=unix
- syntax enable
- " Turn on relative line numbers except for current line and uses absolute line
- " numbers for insert mode.
- " set number
- " set relativenumber
- " au InsertEnter * :set number norelativenumber
- " au InsertLeave * :set number relativenumber
- " Enable mouse in all modes.
- set mouse=a
- set ruler
- " I normally have this, but it looks ugly using this without a proper
- " colorscheme or changing it's highlight. But I can't be bothered to do those
- " (yet), so I just don't turn it on. 🤷
- " set cursorline
- set showcmd
- set scrolloff=5
- " See `:help wildmode` for more.
- set wildmenu
- " To be able to remap as <down> in command mode.
- set wildcharm=<tab>
- set hidden
- set splitbelow
- set splitright
- set ignorecase
- set smartcase
- set incsearch
- set autoindent
- set backspace=2
- set expandtab
- set tabstop=2
- set shiftwidth=2
- set softtabstop=2
- set textwidth=80
- set colorcolumn=+1
- set nojoinspaces
- " Always show status line.
- set laststatus=2
- " Retains cursor (column) position across buffer switches.
- set nostartofline
- " As much as possible of the last line in a window will be displayed.
- set display+=lastline
- " See `:help fo-table`.
- " set formatoptions+=tc
- set formatoptions+=tcroqnj
- " Less delay when pressing escape.
- set timeoutlen=1000
- set ttimeoutlen=10
- " Vim info options:
- " '0 --> Marks will not be saved.
- " f0 -- Marks will not be saved.
- " @0 --> Input line history will not be saved.
- " No % --> Buffer list will not be saved.
- " No :0 --> Command line history will be saved.
- " No <0 --> Registers will be saved.
- " No / --> Search history will be saved.
- set viminfo='0,@0,f0
- " Main Mappings {{{1
- nnoremap <bslash> <c-^>
- let mapleader=" "
- " xnoremap means only map for visual mode. (vnoremap remaps for both visual and
- " select mode.)
- nnoremap ' :
- xnoremap ' :
- " Basically for allowing `vv` in normal mode to copy character under cursor.
- xnoremap v y<esc>
- nnoremap - +
- nnoremap + -
- xnoremap - +
- xnoremap + -
- nnoremap q; q:k
- xnoremap q; q:k
- nnoremap q/ q/k
- nnoremap gs :w<cr>
- nnoremap <silent> <leader>s :set<space>hlsearch!<cr>
- nnoremap <leader>k H
- nnoremap <leader>j L
- nnoremap H ^
- xnoremap H ^
- nnoremap L $
- xnoremap L $
- onoremap M %
- nnoremap M %
- xnoremap M %
- nnoremap Y y$
- nnoremap ZZ <nop>
- nnoremap ZQ <nop>
- nnoremap <c-n> :bn<cr>
- nnoremap <c-p> :bp<cr>
- nnoremap gl :ls<cr>:b<space>
- nnoremap <leader>f mmvipgq`m
- nnoremap <leader>wo :only<cr>
- nnoremap <leader>we <c-w>=
- nnoremap <leader>re <c-l>
- nnoremap <leader>ri <c-a>
- nnoremap <leader>rd <c-x>
- nnoremap <c-h> <c-w>h
- nnoremap <c-j> <c-w>j
- nnoremap <c-k> <c-w>k
- nnoremap <c-l> <c-w>l
- inoremap <c-l> <esc>l%%a
- " Allows opening files from the directory of the currently opened buffer
- " quickly.
- " From <http://vimcasts.org/episodes/the-edit-command/>.
- nnoremap <leader>ew :e <c-r>=fnameescape(expand('%:h')).'/'<cr>
- xnoremap <leader>cp "*y
- xnoremap <leader>co "+y
- nnoremap <leader>p "*p
- nnoremap <leader>o "+p
- nnoremap <leader>eh :edit $HISTFILE<cr>
- nnoremap <leader>vc :edit ~/.vimrc<cr>
- nnoremap <leader>vn :edit ~/dots/nixos/config.nix<cr>
- nnoremap <leader>vs :edit ~/dots/sxhkd/.config/sxhkd/sxhkdrc<cr>
- nnoremap <leader>vz :edit ~/.zshrc<cr>
- " Status Line {{{1
- set statusline=
- " Buffer number.
- set statusline+=%3.3n\ »\
- " Filename.
- set statusline+=%f\ «\
- " Status flags.
- set statusline+=%h%m%r%w
- " " File type.
- " set statusline+=\[%{strlen(&ft)?&ft:'none'}]
- " Right align the rest.
- set statusline+=%=
- " " Character value.
- " set statusline+=0x%-8B
- " Line, character.
- set statusline+=%-14(%l,%c%V%)
- " File position.
- set statusline+=%<%P
- " Folds {{{1
- set fillchars="fold: "
- set foldmethod=syntax
- set foldlevel=99
- set foldlevelstart=99
- function! FoldText()
- let line = ' ' . substitute(getline(v:foldstart),
- \ '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g')
- let lines_count = v:foldend - v:foldstart + 1
- let lines_count_text = printf("%10s", lines_count)
- let foldtextstart = '+' . repeat('-', v:foldlevel*2) . line
- let rightalignby = winwidth(0) - 79
- if rightalignby < 0
- let rightalignby = 1
- endif
- let foldtextend = lines_count_text . repeat(' ', rightalignby)
- let foldtextlength = strlen(substitute(foldtextstart .
- \ foldtextend, '.', 'x', 'g'))
- \ + &foldcolumn
- return foldtextstart . repeat(' ', winwidth(0)-foldtextlength) . foldtextend
- endfunction
- set foldtext=FoldText()
- " Filetype {{{1
- " Gitcommit {{{2
- function GitcommitOptions()
- setl tw=72 cc=73
- endfunction
- au filetype gitcommit call GitcommitOptions()
- " JavaScript {{{2
- if filereadable('./node_modules/.bin/prettier-standard')
- au filetype javascript nnoremap <buffer> <leader><leader> :%!./node_modules/.bin/prettier-standard<cr>
- au filetype typescript nnoremap <buffer> <leader><leader> :%!./node_modules/.bin/prettier-standard --parser typescript<cr>
- endif
- " Python {{{2
- function PythonOptions()
- setl ts=4 sw=4 sts=4
- endfunction
- au filetype python call PythonOptions()
- " Extra {{{1
- " Change cursor shape based on vim mode:
- "
- " - Block for normal mode.
- " - Bar for insert mode.
- if &term =~ "xterm\\|rxvt\\|st\\|alacritty"
- " Insert mode shape.
- let &t_SI = "\x1b[\x36 q"
- " Normal mode shape.
- let &t_EI = "\x1b[\x32 q"
- endif
- " Allows to `:q` when opening multiple files via the command line without
- " needing to open all buffers.
- au VimEnter * nested call VisitLastBuffer()
- fun! VisitLastBuffer()
- startinsert
- call feedkeys('')
- if (argc() > 1)
- last
- rew
- endif
- endfun
- " When switching buffers, preserve window view.
- " From <http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers>.
- au BufLeave * if !&diff | let b:winview = winsaveview() | endif
- au BufEnter * if exists('b:winview') && !&diff | call winrestview(b:winview) |
- \ unlet! b:winview | endif
- " Highlight group under cursor {{{2
- command! SynName echo synIDattr(synID(line("."), col("."), 1), "name")
- " Colors {{{1
- " source ~/dl/repos/disco.vim/colors/disco.vim
- hi cursorline cterm=NONE
- hi comment cterm=NONE
- hi colorcolumn ctermbg=NONE ctermfg=red
|