summaryrefslogtreecommitdiff
path: root/src/vi/_vimrc
blob: 31036e5d21237fd8a7a7fc12b05dc485c1ac683e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
" Source: https://git.hiddenalpha.ch/dotfiles.git/tree/src/vi/_vimrc

if has("win32")

    set diffexpr=MyDiff()
    function MyDiff()
        let opt = '-a --binary '
        if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
        if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
        let arg1 = v:fname_in
        if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
        let arg2 = v:fname_new
        if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
        let arg3 = v:fname_out
        if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
        if $VIMRUNTIME =~ ' '
            if &sh =~ '\<cmd'
                if empty(&shellxquote)
                    let l:shxq_sav = ''
                    set shellxquote&
                endif
                let cmd = '"' . $VIMRUNTIME . '\diff"'
            else
                let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
            endif
        else
            let cmd = $VIMRUNTIME . '\diff'
        endif
        silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
        if exists('l:shxq_sav')
            let &shellxquote=l:shxq_sav
        endif
    endfunction

    function Formatxml()
        " @author hiddenalpha.ch
        if !empty( glob($USERPROFILE."/bin/xmllint.exe") )
            echo "xmllint --format"
            silent %!set xmllint_indent="  " & \%userprofile\%/bin/xmllint --format -
        else
            echo "vimscript --format (WARNING: values trimmed)"
            %j!            " ganze Datei auf eine Zeile
            %s~>\s*<~><~g  " Trim content und zwischenraum
            %s~<~\r<~g     " Jeden Tag auf eine neue Zeile
            %g~^\s*$~d     " alle leerZeilen entfernen
            %g!~>$~j!      " überall, wo text (also kein Tag) am ende Steht mach join
            if line('$') < 500
                " einrückung erstellen (filetype muss auf xml sein)
                " nur bis 500 Zeilen. sonst wirds langsam.
                norm gg=G
            endif
         endif
    endfunction

else " NOT win32

    function Formatxml()
        " @author hiddenalpha.ch
        if !empty( glob("/usr/bin/xmllint") )
            echo "xmllint --format"
            silent %!XMLLINT_INDENT="  " /usr/bin/xmllint --format -
        else
            echo "vimscript --format"
            %j!            " ganze Datei auf eine Zeile
            %s~>\s*<~><~g  " Trim content und zwischenraum
            %s~<~\r<~g     " Jeden Tag auf eine neue Zeile
            %g~^\s*$~d     " alle leerZeilen entfernen
            %g!~>$~j!      " überall, wo text (also kein Tag) am ende Steht mach join
            if line('$') < 500
                " einrückung erstellen (filetype muss auf xml sein)
                norm gg=G
            endif
        endif
    endfunction

endif


colorscheme koehler
set autoindent
set clipboard=
set backspace=2
set encoding=utf-8
set fileformat=unix
set fileformats=unix, dos
set linebreak
set nobackup
set nowritebackup
set noswapfile
set fo=jlnroq fo-=t
set textwidth=72
set number
set hidden " <- Allow to switch buffer even it is not saved.
set ruler
set hlsearch
set scrolloff=1 " <- Keep free lines top/bottom before/after cursor
set showcmd
set listchars=eol:$,tab:>-
set showbreak=↳\ 
"set wildmenu
"set laststatus=2  " 2: Always display filename
"set statusline+=%F " '- With full path
set spelllang=en,de
set sidescroll=8
syntax on


" indent ----------------------------------------------------------------------

set expandtab
set tabstop=4
set shiftwidth=4
set autoindent
set nosmartindent
vnoremap > >gv
vnoremap <Tab> >gv
vnoremap < <gv
vnoremap <S-Tab> <gv
inoremap <S-Tab> <Esc><<i

function Indenting(indent, what, cols)
    let spccol = repeat(' ', a:cols)
    let result = substitute(a:indent, spccol, '\t', 'g')
    let result = substitute(result, ' \+\ze\t', '', 'g')
    if a:what == 1
        let result = substitute(result, '\t', spccol, 'g')
    endif
    return result
endfunction
function IndentConvert(line1, line2, what, cols)
    let savepos = getpos('.')
    let cols = empty(a:cols) ? &tabstop : a:cols
    execute a:line1 . ',' . a:line2 . 's/^\s\+/\=Indenting(submatch(0), a:what, cols)/e'
    call histdel('search', -1)
    call setpos('.', savepos)
endfunction
command -nargs=? -range=% Space2Tab call IndentConvert(<line1>,<line2>,0,<q-args>)
command -nargs=? -range=% Tab2Space call IndentConvert(<line1>,<line2>,1,<q-args>)


" misc ------------------------------------------------------------------------

" Quickly switch windows
nnoremap <c-j> <c-w>j
nnoremap <c-k> <c-w>k
nnoremap <c-h> <c-w>h
nnoremap <c-l> <c-w>l

" Set window title
nnoremap <F2> :set titlestring=
nnoremap <C-S-F2> :set titlestring=

" close buffer
nnoremap <F4> :bp<CR>:bd#<CR>

" change pwd to current file
nnoremap cdc :cd %:p:h<CR>:pwd<CR>

" Execute previous one now
:cd %:p:h

" Not searchNext. Do only highlight word under cursor.
"nmap * *N
nnoremap * viw"9yb/9<CR>

" save with ctrl-s
nmap <C-s> :up<CR>


" NERDTree --------------------------------------------------------------------
" Setup instructions see: "https://hiddenalpha.ch/slnk/id/1:6185e48"

"set rtp+=/opt/nerdtree
"source /opt/nerdtree/plugin/NERD_tree.vim
"nnoremap ° :NERDTreeToggle<CR>


" OS integration --------------------------------------------------------------

if has("win32")

    " insert current TS
    inoremap <F5> <C-R>=strftime('%Y%m%d%H%M%S')<CR>
    "inoremap <S-F5> <C-R>=strftime('%Y-%m-%d_%H:%M:%S%z')<CR><Esc>

    command  OsTerminal  !start cmd.exe
    command  OsFileExplorer  !start explorer.exe .

else

    " Insert a hash
    inoremap <F5> <C-R>=system("head -c32 /dev/urandom\|base64\|tr -d '\n=+/'\|head -c16")<CR>
    " insert current TS
    inoremap <S-F5> <C-R>=strftime('%Y-%m-%d_%H:%M:%S%z')<CR>

    command  OsTerminal  !x-terminal-emulator &
    command  OsFileExplorer  !x-file-manager `pwd` &
    command  OsFirefox  !firefox `pwd` &
    command  OsChromium  !chromium `pwd` &

endif


" filetype specific -----------------------------------------------------------

autocmd FileType html setl sw=2 ts=2
autocmd FileType xml  setl sw=2 ts=2
autocmd BufNewFile,BufRead Makefile setl noexpandtab list
autocmd FileType c setl colorcolumn=101
autocmd FileType java setl colorcolumn=101
autocmd FileType lua setl colorcolumn=101
autocmd FileType js setl colorcolumn=101

autocmd FileType text setl ft=awk
autocmd BufNew,BufRead *.gnuplot setl ft=gnuplot
autocmd BufNew,BufRead *.yaml,*.yml setl ts=2 sw=2
autocmd BufNew,BufRead *.json, setl ts=2 sw=2
autocmd BufNewFile,BufRead *.ts  setl ft=javascript
autocmd BufNewFile,BufRead *.pom setl ft=xml