dotfiles

<-- duh.
git clone https://hhvn.uk/dotfiles
git clone git://hhvn.uk/dotfiles
Log | Files | Refs | Submodules | LICENSE

init.vim (4342B)


      1 "
      2 " .config/nvim/init.vim
      3 " Copyright (c) 2019-2022 hhvn <dev@hhvn.uk>
      4 "
      5 "
      6 
      7 "GRRRRRR.
      8 set mouse=
      9 
     10 "Persistant undo
     11 set undodir=~/.local/share/nvim/undo
     12 set undofile
     13 set undolevels=1000
     14 set undoreload=10000
     15 set backup
     16 set backupdir=~/.local/share/nvim/backup
     17 
     18 "Leader
     19 let mapleader=";"
     20 let maplocalleader=","
     21 
     22 "Cursor
     23 let &t_SI.="\033[6 q" "SI = INSERT mode
     24 let &t_SR.="\033[4 q" "SR = REPLACE mode
     25 let &t_EI.="\033[2 q" "EI = NORMAL mode (ELSE)
     26 
     27 "Tab completion
     28 set path+=**
     29 
     30 set encoding=utf-8
     31 set title
     32 syntax on
     33 colo hhvn
     34 set background=dark
     35 set relativenumber
     36 set number
     37 set hlsearch
     38 filetype plugin on
     39 set noshowmode
     40 set so=4
     41 set lcs=tab:._
     42 set gdefault
     43 
     44 function! ReopenFile()
     45 	let curfile=expand('%:p')
     46 	echom curfile
     47 	execute 'write' . curfile
     48 	execute 'edit' . curfile
     49 endfunction
     50 
     51 noremap <leader>vs :source ~/.config/nvim/init.vim<CR>
     52 noremap <leader>r :call ReopenFile()<CR>
     53 noremap <leader>m :make
     54 noremap <leader>sc :setlocal spell! spelllang=en_gb \| set linebreak<CR>
     55 noremap <leader>sf mm[sz=`m
     56 noremap <leader>bd :bdelete<CR>
     57 noremap <leader>bn :bn<CR>
     58 noremap <leader>bp :bp<CR>
     59 noremap <leader>8 :set colorcolumn=80<CR>:set tw=80<CR>:set fo+=t<CR>
     60 noremap <leader>g :!git 
     61 noremap <leader>nn :setlocal number! relativenumber!<CR>
     62 noremap <leader>cs :let @/=''<CR>
     63 noremap <silent> <c-s> :silent !plumb <cfile><CR>
     64 
     65 nmap <c-o> 0/<++><Enter>"_c4l
     66 imap <c-o> <Esc>0/<++><Enter>"_c4l
     67 
     68 "Preprocessor comments
     69 function! PreprocComment()
     70   mark y
     71   let saved_wrapscan=&wrapscan
     72   set nowrapscan
     73   let elsecomment=""
     74   let endcomment=""
     75   try
     76     " Find the last #if in the buffer
     77     $?^\s*#if
     78     while 1
     79       " Build the comments for later use, based on current line
     80       let content=getline('.')
     81       let endcomment=BuildEndComment(content,endcomment)
     82       " Change # into ## so we know we've already processed this one
     83       " and don't find it again
     84       s/^\s*\zs#/##
     85       " Find the next #else, #elif, #endif which must belong to this #if
     86       /^\s*#endif
     87       let content=getline('.')
     88       call setline('.',ReplaceComment(getline('.'),endcomment))
     89       s/^\s*\zs#/##
     90       " Find the previous #if
     91       ?^\s*#if
     92     endwhile
     93   catch /search hit TOP/
     94     " Once we have an error (pattern not found, i.e. no more left)
     95     " Change all our ## markers back to #
     96     silent! %s/^\s*\zs##/#
     97   endtry
     98   let &wrapscan=saved_wrapscan
     99   normal `y
    100 endfunc
    101 
    102 let s:PreProcCommentMatcher = '#\a\+\s\+\zs.\{-}\ze\(\s*\/\*.\{-}\*\/\)\?\s*$'
    103 
    104 function! BuildEndComment(content,previous)
    105   let expression=escape(matchstr(a:content,s:PreProcCommentMatcher), '\~&')
    106   if match(a:content,'#ifdef') != -1
    107     return "/* ".expression." */"
    108   elseif match(a:content,'#ifndef') != -1
    109     return "/* not ".expression." */"
    110   elseif match(a:content,'#if') != -1
    111     return "/* ".expression." */"
    112   else
    113     return ""
    114   endif
    115 endfunc
    116 
    117 function! ReplaceComment(content,comment)
    118   let existing=escape(matchstr(a:content,'#\a\+\s\+\zs.\{-}\s*$'), '\~&')
    119   if existing == ""
    120     return substitute(a:content,'^\s*#\a\+\zs.*'," ".a:comment,'')
    121   elseif existing != a:comment && match(existing,'XXX') == -1
    122     return a:content." /* XXX */"
    123   else
    124     return a:content
    125   endif
    126 endfunc
    127 command PreprocComment call PreprocComment()
    128 nnoremap <leader>ppc :PreprocComment<CR>
    129 
    130 nnoremap <leader>x :!chmod +x %s<CR>
    131 
    132 "General stuff
    133 noremap dw diw
    134 noremap dew dw
    135 noremap cw ciw
    136 noremap cew cw
    137 noremap dl 0d$
    138 
    139 noremap md ddp
    140 noremap mu ddkkp
    141 noremap <c-U> viwU
    142 noremap <c-i> viwu
    143 
    144 "Fold
    145 set foldmethod=marker
    146 nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
    147 vnoremap <Space> zf
    148 
    149 "Remove arrow keys
    150 no <Up> <Nop>
    151 no <Down> <Nop>
    152 no <Left> <Nop>
    153 no <Right> <Nop>
    154 ino <Up> <Nop>
    155 ino <Down> <Nop>
    156 ino <Left> <Nop>
    157 ino <Right> <Nop>
    158 
    159 "Registers
    160 set clipboard=unnamed
    161 
    162 "Modules
    163 source ~/.config/nvim/modules/statusline.vim
    164 source ~/.config/nvim/modules/filetype.vim
    165 source ~/.config/nvim/modules/textmanipulation.vim
    166 
    167 " quick-scope
    168 let g:qs_highlight_on_keys = ['f', 'F', 't', 'T']
    169 
    170 " Shell on BSD
    171 let b:is_posix = 1
    172 
    173 " Splitting
    174 set splitbelow splitright
    175 noremap <leader>z :vsplit 
    176 noremap <leader>Z :split 
    177 
    178 noremap <C-h> <C-w>h
    179 noremap <C-j> <C-w>j
    180 noremap <C-k> <C-w>k
    181 noremap <C-l> <C-w>l
    182 noremap <C-c> <C-w>c
    183 noremap <A-j> <C-w>+
    184 noremap <A-k> <C-w>-
    185 noremap <A-h> <C-w>>
    186 noremap <A-l> <C-w><
    187 
    188 " Hide startup information
    189 set shortmess+=I