forked from 4lgn/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
170 lines (139 loc) · 5.55 KB
/
.vimrc
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
" --- Auto-install vim-plug if not already installed --- "
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source ~/.vimrc
endif
" --- Plugin section --- "
call plug#begin('~/.vim/plugged')
" --- Status line --- "
Plug 'vim-airline/vim-airline'
" --- Theming --- "
Plug 'morhetz/gruvbox'
Plug 'vim-airline/vim-airline-themes'
" --- Completion and syntax --- "
" Editing and usability
Plug 'jiangmiao/auto-pairs'
" --- Programming Languages ---
Plug 'sheerun/vim-polyglot'
"Plug 'davidhalter/jedi-vim'
" Initialize plugin system
call plug#end()
filetype plugin indent on " required
syntax on
" gruvbox italic fix (must appear before colorscheme)
let g:gruvbox_italic = 1
colorscheme gruvbox
" Airline powerline fonts fix
let g:airline_powerline_fonts = 1
" Airline theme
let g:airline_theme = 'gruvbox'
" User-specific Settings.
" ---Sets---
"
set encoding=utf-8 " UTF-8 Support
set tabstop=4 " 4 spaces will do
set shiftwidth=4 " control indentation for >> bind
set expandtab " spaces instead of tabs
set autoindent " always set autoindenting on
set relativenumber " relative line numbers
set number " hybrid numbering with both rnu and number
set hidden " hide buffers instead of closing them
set ignorecase " ignore case when searching
set smartcase " ignore case if all lowercase
set nobackup " don't need swp files
set noswapfile " don't need swp files
"set showmatch " Show matching braces when over one
set backspace=indent,eol,start " allow backspacing everything in insert
set hlsearch " highlight searches
set incsearch " search as typing
set laststatus=2 " for lightline.vim plugin
" Use comma as leader
let g:mapleader = ','
" make it possible to write danish letters
let g:AutoPairsShortcutFastWrap=''
" ---Re-mappings---
"
" Ctrl-C for yanking to register, Ctrl+P to paste from clipboard
vnoremap <C-c> "*y :let @+=@*<CR>
map <C-p> "+P
" since I constantly write accidentally mess these up when going fast
command WQ wq
command Wq wq
command W w
command Q q
" w!! to write with sudo even if not opened with sudo
cmap w!! w !sudo tee >/dev/null %
"split navigations
nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>
" Bind to clear search
nmap <leader>/ :nohlsearch<CR>
" --- LaTeX Stuff ---
" Navigating with guides
inoremap ,<Tab> <Esc>/<++><Enter>"_c4l
vnoremap ,<Tab> <Esc>/<++><Enter>"_c4l
map ,<Tab> <Esc>/<++><Enter>"_c4l
autocmd FileType tex inoremap <F6> <Esc>:w<Enter>:!pdflatex<space>%<Enter>a
autocmd FileType tex nnoremap <F6> :w<Enter>:!pdflatex<space>%<Enter><Enter>
autocmd FileType tex inoremap ,bf \textbf{}<++><Esc>T{i
autocmd FileType tex inoremap ,it \textit{}<++><Esc>T{i
autocmd FileType tex inoremap ,dm \[\]<Enter><++><Esc>khi
autocmd FileType tex inoremap ,im $$<++><Esc>5hli
autocmd FileType tex inoremap ,con \rightarrow
autocmd FileType tex inoremap ,bic \leftrightarrow
" SaveAndRun scripts
let filePath = expand("%")
" Save, compile, run C programs
let outputName = filePath[0:eval(len(filePath) - 3)]
let cCmd = ".!gcc " . filePath . " -o " . outputName . " && ./" . outputName
nnoremap <silent> <F5> :call SaveAndRun("C Runner", cCmd)<CR>
vnoremap <silent> <F5> :<C-u>call SaveAndRun("C Runner", cCmd)<CR>
" Run Python scripts
let pCmd = ".!python " . shellescape(filePath, 1)
nnoremap <silent> <F6> :call SaveAndRun("Python", pCmd)<CR>
vnoremap <silent> <F6> :<C-u>call SaveAndRun("Python", pCmd)<CR>
function! SaveAndRun(bufferName, cmd)
" save and reload current file
silent execute "update | edit"
" get file path of current file
let s:current_buffer_file_path = expand("%")
let s:output_buffer_name = a:bufferName
let s:output_buffer_filetype = "output"
" reuse existing buffer window if it exists otherwise create a new one
if !exists("s:buf_nr") || !bufexists(s:buf_nr)
silent execute 'botright new ' . s:output_buffer_name
let s:buf_nr = bufnr('%')
elseif bufwinnr(s:buf_nr) == -1
silent execute 'botright new'
silent execute s:buf_nr . 'buffer'
elseif bufwinnr(s:buf_nr) != bufwinnr('%')
silent execute bufwinnr(s:buf_nr) . 'wincmd w'
endif
silent execute "setlocal filetype=" . s:output_buffer_filetype
setlocal bufhidden=delete
setlocal buftype=nofile
setlocal noswapfile
setlocal nobuflisted
setlocal winfixheight
setlocal cursorline " make it easy to distinguish
setlocal nonumber
setlocal norelativenumber
setlocal showbreak=""
" clear the buffer
setlocal noreadonly
setlocal modifiable
%delete _
" add the console output
silent execute a:cmd
" resize window to content length
" Note: This is annoying because if you print a lot of lines then your code buffer is forced to a height of one line every time you run this function.
" However without this line the buffer starts off as a default size and if you resize the buffer then it keeps that custom size after repeated runs of this function.
" But if you close the output buffer then it returns to using the default size when its recreated
"execute 'resize' . line('$')
" make the buffer non modifiable
setlocal readonly
setlocal nomodifiable
endfunction