aboutsummaryrefslogtreecommitdiffstats
path: root/vim/.vim/vimrc
blob: 3e4076f13604f7b78d192a4af59d1b6fc1ee98e2 (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
call plug#begin('~/.local/share/vim/plugged')

Plug 'bling/vim-airline'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'edkolev/tmuxline.vim'
" Plug 'ervandew/supertab'
Plug 'mhinz/vim-janah'
Plug 'mhinz/vim-signify'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'scrooloose/syntastic'
Plug 'tpope/vim-fugitive'
Plug 'unblevable/quick-scope'
Plug 'vim-airline/vim-airline-themes'

if executable('ansible')
    Plug 'chase/vim-ansible-yaml'
endif

if has('python') || has('python3')
    let g:ycm_install_command = './install.py --clang-completer'

    if executable('node') && executable('npm')
        let g:ycm_install_command .= ' --tern-completer'
    endif

    if executable('go')
        let g:ycm_install_command .= ' --gocode-completer'
    endif

    if executable('rustc')
        let g:ycm_install_command .= ' --rust-completer'
    endif

    Plug 'Valloric/YouCompleteMe', {'do': g:ycm_install_command}
endif

call plug#end()

""" DEFAULT VIM SETTINGS

" Reload vimrc on save
augroup reload_vimrc " {
    autocmd!
    autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END " }

let mapleader=" "

syntax on
filetype plugin indent on

" Some vim settings
set number
set relativenumber
set list
set modeline
set background=dark
set foldmethod=indent
set listchars=trail:·,tab:▸\ ,eolset scrolloff=1
set backspace=indent,eol,start
set cursorline

" Set colorscheme when the terminal has 256 color support
try
    if (&t_Co == 256) && match($TERM, "256color") >= 0
        " autocmd ColorScheme janah highlight Normal ctermbg=235
        colorscheme janah
    else
        throw "nocolor"
    endif
catch
    colorscheme desert
endtry

" Search-related things
set hlsearch "highlight search result
set incsearch " incremental search
set ignorecase
set smartcase " capital letters = case sensitive

" Disable ex mode
nnoremap Q <Nop>

" Save as sudo
cnoremap w!! w !sudo tee > /dev/null %

" Remove training spaces on save
autocmd BufWritePre * :%s/\s\+$//e

" Switch windows with <C-W>[direction]
nnoremap <C-J> <C-W>j
nnoremap <C-K> <C-W>k
nnoremap <C-H> <C-W>h
nnoremap <C-L> <C-W>l

" Never use the arrow keys
inoremap  <Up> <Nop>
inoremap  <Down> <Nop>
inoremap  <Left> <Nop>
inoremap  <Right> <Nop>
noremap  <Up> <Nop>
noremap  <Down> <Nop>
noremap  <Left> <Nop>
noremap  <Right> <Nop>

" Append modeline when pressing <leader> ml
function! AppendModeline()
    let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
        \ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
    let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
    call append(line("$"), l:modeline)
endfunction
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>

" NeoVIM specifics
if has('nvim')
    nmap <BS> <C-W>h
    tnoremap <Esc> <C-\><C-n>
    autocmd TermOpen * setlocal nolist
endif

""" PLUGIN SPECIFIC SETTINGS
if exists("g:plug_home")

    " NERDTree:
    " Open NERDTree when no file is specified
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif
    autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

    " NERDCommenter:
    " Pretty comments
    let g:NERDSpaceDelims = 1
    let g:NERDCompactSexyComs = 1
    let g:NERDDefaultAlign = 'left'
    let g:NERDCommentEmptyLines = 1
    let g:NERDTrimTrailingWhitespace = 1


    " Airline:
    " On arch linux install the following:
    " otf-powerline-symbols-git
    " powerline-fonts-git
    let g:airline_powerline_fonts = 1
    let g:airline#extensions#tabline#enabled = 1

    if !exists('g:airline_symbols')
        let g:airline_symbols = {}
    endif

    let g:airline_symbols.space = "\ua0"
    set laststatus=2

    if exists('g:ycm_install_command')
        let g:ycm_autoclose_preview_window_after_completion = 1
        let g:ycm_autoclose_preview_window_after_insertion = 1
    endif
endif

" vim: set ts=8 sw=4 tw=0 et :