aboutsummaryrefslogtreecommitdiff
path: root/.vim/vimrc
blob: d98bb5fc403f70a735ea72cf6333e860b852816e (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
" ===========
" VARIABLES
" ===========
runtime bundle/vim-pathogen/autoload/pathogen.vim
execute pathogen#infect('bundle-active/{}')

set nocompatible
"Disable bell
set vb
set t_vb=

set ttimeoutlen=10
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#whitespace#enabled = 1
let g:airline_powerline_fonts = 1

"All things cursor
set guicursor+=a:blinkon0 "disable blinking
if &term =~ "xterm\\|rxvt"
	" 1 or 0 -> blinking block
	" 2 -> solid block
	" 3 -> blinking underscore
	" 4 -> solid underscore
	" 5 -> blinking vertical bar
	" 6 -> solid vertical bar
	let &t_SI .= "\<Esc>[6 q" " Normal
	let &t_EI .= "\<Esc>[2 q" " Insert
endif

"show line endings and tabs
set listchars=tab:>\ ,trail:~,extends:>,precedes:<
set list

" Use todo#Complete as the omni complete function for todo files
au filetype todo setlocal omnifunc=todo#Complete

" Auto complete projects
au filetype todo imap <buffer> + +<C-X><C-O>

" Auto complete contexts
au filetype todo imap <buffer> @ @<C-X><C-O>

" leader
let mapleader = "-"
let leader = "-"
let maplocalleader = "-"

syntax on
filetype plugin indent on

"Line number Highlight
set nu rnu
highlight LineNr term=bold cterm=NONE ctermfg=DarkGrey ctermbg=NONE gui=NONE guifg=DarkGrey guibg=NONE

set foldmethod=syntax

" ==============
" SHORTCUTS
" ==============

"Switch windows with keys
"nmap <silent> <C-w-k> :wincmd k<CR>
"nmap <silent> <C-w-j> :wincmd j<CR>
"nmap <silent> <C-w-h> :wincmd h<CR>
"nmap <silent> <C-w-l> :wincmd l<CR>

nmap <silent> <C-s> :vsplit<CR>:e .<CR>
nmap <silent> <C-e> :e .<CR>

nnoremap <silent> <Space> @=(foldlevel('.')?'za':"\<Space>")<CR>
vnoremap <Space> zf

au filetype c* nmap <silent> <F4> :Make<CR>
au filetype sh nmap <silent> <F4> :Runbuffer<CR>
au filetype python nmap <silent> <F4> :Runbuffer<CR>
au filetype *tex nmap <silent> <F4> :Makelatex<CR>
au filetype *tex nmap <silent> <F2> :Openpdf<CR>

nmap <silent> <F3> :Newterm<CR>

nmap <silent> <F5> :NERDTreeToggle<CR>
nmap <silent> <F6> :TlistToggle<CR>

"Tab mgmt
nmap <silent> gc :tabclose<CR>
nmap <silent> gn :tabnew<CR>:e .<CR>

"tmap <silent> <Esc> <C-\><C-n>

" Smart brackets
inoremap "" ""<left>
inoremap '' ''<left>
inoremap () ()<left>
inoremap [] []<left>
inoremap {} {}<left>
inoremap {<CR> {<CR>}<ESC>O
inoremap {;<CR> {<CR>};<ESC>O

" ===========
" COMMANDS
" ===========

command -bar Suw :w !SUDO_ASKPASS="/usr/lib/ssh/ssh-askpass" sudo -A  tee %

" Command HEXMODE 
command -bar Hexmode call ToggleHex()

"^] Jump to tag, ^t jump back
command! MakeTags !ctags -R .

command -bar Newterm call Run_in_terminal("")
command -bar Runbuffer call Run_in_terminal(expand("%:p"))
command -bar Make call Run_in_terminal("make run")
command -bar Fileheader call Insert_Header(expand("%"))

command -bar Makelatex silent! execute "!(pdflatex % > /dev/null 2>&1 && killall -s SIGHUP mupdf)&" | redraw!
command Openpdf silent! execute "!mupdf " . (join(split(expand("%"), '\.')[:-2], ".") . ".pdf") . " > /dev/null 2>&1 &" | redraw!

" ===========
" FUNCTIONS
" ===========

function Insert_Header(name)
	let l:name=systemlist("git config --global --get user.name")[0]
	let l:mail=systemlist("git config --global --get user.email")[0]
	call append("0", ["/*", " * ".a:name, " * (c) ".strftime("%Y")." ".l:name." <".l:mail.">", " * License: All rights reserved.", " */"])
	startinsert
endfunction

function Run_in_terminal(prog)
	if !has('terminal')
		return
	endif

	tabnew
	execute "terminal ++curwin " . a:prog
	startinsert
endfunction

" helper function to toggle hex mode
function ToggleHex()
  " hex mode should be considered a read-only operation
  " save values for modified and read-only for restoration later,
  " and clear the read-only flag for now
  let l:modified=&mod
  let l:oldreadonly=&readonly
  let &readonly=0
  let l:oldmodifiable=&modifiable
  let &modifiable=1
  if !exists("b:editHex") || !b:editHex
    " save old options
    let b:oldft=&ft
    let b:oldbin=&bin
    " set new options
    setlocal binary " make sure it overrides any textwidth, etc.
    silent :e " this will reload the file without trickeries 
              "(DOS line endings will be shown entirely )
    let &ft="xxd"
    " set status
    let b:editHex=1
    " switch to hex editor
    %!xxd
  else
    " restore old options
    let &ft=b:oldft
    if !b:oldbin
      setlocal nobinary
    endif
    " set status
    let b:editHex=0
    " return to normal editing
    %!xxd -r
  endif
  " restore values for modified and read only state
  let &mod=l:modified
  let &readonly=l:oldreadonly
  let &modifiable=l:oldmodifiable
endfunction