aboutsummaryrefslogtreecommitdiff
path: root/base/.vim/auto.vim
blob: 8066c25fb9935e1bd2000afbf7b6558e5fc8df8b (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
"Enable trailing space highlight
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
autocmd ColorScheme * highlight ExtraWhitespace ctermbg=red guibg=red

"Highlight current line
set cursorline
hi cursorline cterm=none term=none
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline
highlight CursorLine guibg=#313131 ctermbg=234

"Complete open bracket
inoremap {      {}<Left>
"Complete open and enter bracket
inoremap {<CR>  {<CR>}<Esc>O
inoremap {}     {}

set encoding=utf-8
scriptencoding utf-8
" Show invisible characters (tabs, spaces and EOF)
set listchars=tab:>.,space:.,eol:$
" set listchars=tab:\ \ ,eol:↵
set list

"Command to change default format of C# files
":command Csformat %s/\n *{\n/ {\r/g

" FZF integration supplied by the system fzf package, without vim-plug.
if executable('fzf')
    silent! runtime plugin/fzf.vim
endif

if executable('fzf') && exists('*fzf#run')
    function! s:FzfFiles(directory, fullscreen) abort
        let l:root = empty(a:directory) ? getcwd() : fnamemodify(a:directory, ':p')
        let l:source = 'find ' . shellescape(l:root)
                    \ . ' -path ' . shellescape('*/.git/*')
                    \ . ' -prune -o -type f -print'

        call fzf#run(fzf#wrap({
                    \ 'source': l:source,
                    \ 'sink': 'edit',
                    \ 'options': '--prompt=Files> '
                    \ }, a:fullscreen))
    endfunction

    function! s:FzfBufferSink(lines) abort
        let l:buffer = str2nr(matchstr(get(a:lines, 0, ''), '^\d\+'))
        if l:buffer > 0
            execute 'buffer ' . l:buffer
        endif
    endfunction

    function! s:FzfBuffers(fullscreen) abort
        let l:entries = []

        for l:number in range(1, bufnr('$'))
            if buflisted(l:number)
                let l:name = bufname(l:number)
                let l:label = empty(l:name) ? '[Sin nombre]' : fnamemodify(l:name, ':~:.')
                call add(l:entries, printf('%d\t%s', l:number, l:label))
            endif
        endfor

        call fzf#run(fzf#wrap({
                    \ 'source': l:entries,
                    \ 'sink*': function('s:FzfBufferSink'),
                    \ 'options': '--prompt=Buffers> --delimiter=\t --with-nth=2..'
                    \ }, a:fullscreen))
    endfunction

    command! -bang -nargs=? -complete=dir Files call s:FzfFiles(<q-args>, <bang>0)
    command! -bang Buffers call s:FzfBuffers(<bang>0)
endif