Mercurial > dotfiles
annotate .chezmoitemplates/config.vim @ 648:c5ed13440614
Set and optionally create backup and undo dirs
author | zegervdv <zegervdv@me.com> |
---|---|
date | Fri, 02 Sep 2022 07:37:49 +0200 |
parents | a2a5862a3bd3 |
children | 0bea9fd463b5 |
rev | line source |
---|---|
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
1 " vim:fdm=marker:ts=2:sw=2 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
2 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
3 let s:darwin = has('mac') |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
4 let s:windows = has('win32') |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
5 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
6 |
460 | 7 " Mappings |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
8 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
9 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
10 |
627 | 11 " if has('nvim') |
12 " tnoremap <C-h> <C-\><C-n><C-w>h | |
13 " tnoremap <C-j> <C-\><C-n><C-w>j | |
14 " tnoremap <C-k> <C-\><C-n><C-w>k | |
15 " tnoremap <C-l> <C-\><C-n><C-w>l | |
16 " augroup enter_term | |
17 " au! | |
18 " autocmd TermOpen * startinsert! | |
19 " autocmd BufEnter * if &buftype ==# 'terminal' | :startinsert! | endif | |
20 " autocmd BufLeave * if &buftype ==# 'terminal' | :stopinsert! | endif | |
21 " augroup END | |
22 " let $GIT_EDITOR = 'nvr -cc split --remote-wait' | |
23 " endif | |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
24 |
460 | 25 " |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
26 |
460 | 27 " Functions |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
28 " When editing a file, always jump to the last known cursor position. |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
29 " Don't do it for commit messages, when the position is invalid, or when |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
30 " inside an event handler (happens when dropping a file on gvim). |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
31 autocmd BufReadPost * |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
32 \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
33 \ exe "normal g`\"" | |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
34 \ endif |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
35 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
36 |
460 | 37 " Detect Filetype from content if file has no extension |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
38 augroup newFileDetection |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
39 au! |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
40 autocmd CursorMovedI * call CheckFileType() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
41 augroup END |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
42 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
43 function! CheckFileType() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
44 if exists("b:countCheck") == 0 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
45 let b:countCheck = 0 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
46 endif |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
47 let b:countCheck += 1 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
48 if &filetype == "" && b:countCheck > 20 && b:countCheck < 200 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
49 filetype detect |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
50 " Delete the function if no filetype can be established, or the type has |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
51 " been found |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
52 elseif b:countCheck >= 200 || &filetype != "" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
53 autocmd! newFileDetection |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
54 endif |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
55 endfunction |
460 | 56 " |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
57 |
460 | 58 " Make list-like commands more intuitive |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
59 " Copied from https://gist.github.com/romainl/047aca21e338df7ccf771f96858edb86 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
60 function! CCR() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
61 let cmdline = getcmdline() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
62 if cmdline =~ '\v\C^(ls|files|buffers)' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
63 " like :ls but prompts for a buffer command |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
64 return "\<CR>:b" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
65 elseif cmdline =~ '\v\C/(#|nu|num|numb|numbe|number)$' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
66 " like :g//# but prompts for a command |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
67 return "\<CR>:" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
68 elseif cmdline =~ '\v\C^(dli|il)' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
69 " like :dlist or :ilist but prompts for a count for :djump or :ijump |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
70 return "\<CR>:" . cmdline[0] . "j " . split(cmdline, " ")[1] . "\<S-Left>\<Left>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
71 elseif cmdline =~ '\v\C^(cli|lli)' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
72 " like :clist or :llist but prompts for an error/location number |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
73 return "\<CR>:sil " . repeat(cmdline[0], 2) . "\<Space>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
74 elseif cmdline =~ '\C^old' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
75 " like :oldfiles but prompts for an old file to edit |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
76 set nomore |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
77 return "\<CR>:sil se more|e #<" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
78 elseif cmdline =~ '\C^changes' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
79 " like :changes but prompts for a change to jump to |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
80 set nomore |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
81 return "\<CR>:sil se more|norm! g;\<S-Left>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
82 elseif cmdline =~ '\C^ju' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
83 " like :jumps but prompts for a position to jump to |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
84 set nomore |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
85 return "\<CR>:sil se more|norm! \<C-o>\<S-Left>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
86 elseif cmdline =~ '\C^marks' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
87 " like :marks but prompts for a mark to jump to |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
88 return "\<CR>:norm! `" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
89 elseif cmdline =~ '\C^undol' |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
90 " like :undolist but prompts for a change to undo |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
91 return "\<CR>:u " |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
92 else |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
93 return "\<CR>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
94 endif |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
95 endfunction |
627 | 96 " cnoremap <expr> <CR> CCR() |
460 | 97 " |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
98 |
460 | 99 " Filetype specific settings |
100 " Text | |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
101 augroup ft_text |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
102 au! |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
103 " au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
104 au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
105 augroup END |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
106 augroup ft_report |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
107 au! |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
108 au BufNewFile,BufRead,BufEnter *.rpt setlocal nowrap |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
109 au BufNewFile,BufRead,BufEnter *.rpt call ColorRpt() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
110 au BufNewFile,BufRead,BufEnter *.log call ColorRpt() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
111 augroup END |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
112 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
113 function! ColorRpt() |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
114 " Color numbers based on length |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
115 syn match String "\v<\d{1,3}>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
116 syn match Number "\v<\d{4,6}>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
117 syn match Statement "\v<\d{7,9}>" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
118 |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
119 " Color errors |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
120 syn match Error "\v^ERROR:.*$" |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
121 endfunction |
460 | 122 " |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
123 |
460 | 124 " Plugin settings |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
125 |
460 | 126 " |
127 " Vinegar/NetRW | |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
128 autocmd FileType netrw setl bufhidden=delete |
460 | 129 " |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
130 augroup Chezmoi |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
131 autocmd! |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
132 autocmd BufWritePost ~/.local/share/chezmoi/* silent !chezmoi apply --source-path % |
472
d2b877b4ef8b
Automatically apply changes to templatefiles
zegervdv <zegervdv@me.com>
parents:
463
diff
changeset
|
133 autocmd BufWritePost ~/.local/share/chezmoi/.chezmoitemplates/init.lua silent !chezmoi apply --source-path ~/.local/share/chezmoi/dot_config/nvim/init.lua.tmpl |
d2b877b4ef8b
Automatically apply changes to templatefiles
zegervdv <zegervdv@me.com>
parents:
463
diff
changeset
|
134 autocmd BufWritePost ~/.local/share/chezmoi/.chezmoitemplates/config.vim silent !chezmoi apply --source-path ~/.local/share/chezmoi/dot_config/nvim/plugin/config.vim.tmpl |
451
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
135 autocmd BufWritePost ~/.local/share/chezmoi/dot_config/nvim/init.lua source <afile> | PackerCompile |
d99353d71702
Use common template for windows nvim config
zegervdv <zegervdv@me.com>
parents:
diff
changeset
|
136 augroup END |