aboutsummaryrefslogtreecommitdiffstats
path: root/vim/.vim/vimrc
blob: 99158fbb3269daa4cde75a07fcf0ea9d3e5dca24 (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
""" 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:loaded_pathogen")

    " 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
endif

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