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

set nocompatible
"Disable bell
set vb
set t_vb=

"Search in all of the project tree
set path+=**
set wildmenu

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

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>

" 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")
command -bar Fileheader call Insert_Header(expand("%"))

" ===========
" 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: ", " */"])
	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