aboutsummaryrefslogtreecommitdiffstats
path: root/vim/vimrc
blob: d5f4e8b6b87e647610bd02167ca4b4ad7eff5bee (plain) (blame)
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
set nocompatible
syntax on			"turn syntax highlighting on
filetype plugin indent on	"load plugin and indent files associated a detected filetype

" macro to go to end of sentence and add a line break (for
" one-line-per-sentence vimming...)
let @s = ")i\<BS>\<CR>\<Esc>"

" leader
let maplocalleader = "\\"
let mapleader = ","

" encryption method when using :X
set cm=blowfish2

" Underline the current line, based on its length.
noremap <silent> <leader>ul mmyypVr-<Esc>`m
"
" Show the 'list' characters.
noremap <silent> <leader>ls :set list!<CR>

" Remove double- or single-quotes, or graves wrapped around a string.
noremap <silent> <leader>rdq mmF"xf"x`m
noremap <silent> <leader>rsq mmF'xf'x`m
noremap <silent> <leader>rg mmF`xf`x`m
 
" Jump up or down by 10 lines.
noremap <silent> J 10j
noremap <silent> K 10k

" Place timestamps, be it date (YYYY-MM-DD) or time (HH:MM:SS).
if (exists("*strftime"))
	noremap <silent> <leader>date "=strftime("%F")<CR>p9h
	noremap <silent> <leader>time "=strftime("%X")<CR>p7h
endif
"
" Execute the current line with BASH.
noremap <silent> <leader>rl :.w !bash<CR>

" Run the current file with PERL, Python, BASH, or a Bourne Shell derivative.
noremap <silent> <leader>rpl :!clear; perl %<CR>
noremap <silent> <leader>rpy :!clear; python %<CR>
noremap <silent> <leader>rb :!clear; bash %<CR>
noremap <silent> <leader>rs :!clear; sh %<CR>

set shell=/bin/sh
set hi=500
set scrolloff=0
set novisualbell
set relativenumber	"show line numbers
set wildmenu	"enable a menu that shows tab completion options in the status bar
set wildchar=<TAB>
set showmatch	"highlights matching brackets on cursor hover
set ruler	"show cursor position in status bar
set showcmd	"shows the normal mode command before it gets executed
set encoding=utf-8
set fileformats=unix,dos,mac
set nohlsearch	"highlights searches
set incsearch	"incremental search (searches character by character)
set ignorecase	"ignores the case of a search
set smartcase	"only ignores case if there are no capital letters in search (only works after ignorecase has been set)
set tabstop=4		"the amount of spaces that vim will equate to a tab character
set softtabstop=4	"like tabstop, but for editing operations (insert mode)
set splitbelow " split horiz below
set noswapfile
set splitright " split new to the right when doing vertical
set shiftwidth=4	"used for autoindent and << and >> operators in normal mode
set autoindent		"copies indent from current line to the next line
set expandtab		"tabs will expand to whitespace characters
set esckeys		"allows function keys to be recognized in Insert mode
set ttimeoutlen=20	"timeout for a key code mapping
set timeoutlen=1000	"time(ms) to wait for key mappings
set hidden
set t_Co=256
"set t_Co=0 - switches off all colours
set path+=**
set more
set colorcolumn=0
set equalalways
set showmode
set nobackup
set listchars=tab:»→,trail:␣
if executable('rg')
	set grepprg=rg\ --color=never\ --vimgrep
endif

" From Practical Vim p101 - Easy expansion of Active File Directory
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'

" i don't bother with folding, but it's here if i need it.
if has('folding')
	set foldmethod=marker
	set foldmarker=#\ {{{,#\ }}}
	set viewoptions=folds,options,cursor,unix,slash
endif

" Check whether any buffers have been updated outside of vim
nnoremap <F5> :checktime<CR>

" clear search highlights
nnoremap <leader><space> :noh<cr>:call clearmatches()<cr>

" previews in netrw
let g:netrw_preview = 1

" journal stuff
autocmd BufNewFile,BufReadPost *.md map <leader>jj <Esc>:r! date +" - \%H:\%M: "<ENTER>kJA<Esc>$<space><Esc> 
autocmd BufNewFile,BufReadPost *.md map <leader>jd <Esc>:r! date +"(\%Y-\%m-\%dT\%H:\%M)"<ENTER>i<backspace><space><Esc>

" ghetto note system
" Go to index of notes
nnoremap <leader>ni :e $NOTES_DIR/index.md<CR>:cd $NOTES_DIR<CR>
" Depends on grepprg being set to rg
command! -nargs=1 Ngrep grep "<args>" -g "*.md" $NOTES_DIR
nnoremap <leader>nn :Ngrep 

" open quicklist vertical
command! Vlist botright vertical copen | vertical resize 50
nnoremap <leader>v :Vlist<CR>

" Search with ripgrep
command! -bang -nargs=* Rg
      \ call fzf#vim#grep(
      \   'rg --column --line-number --no-heading --color=always --ignore-case '.shellescape(<q-args>), 1,
      \   <bang>0 ? fzf#vim#with_preview('up:60%')
      \           : fzf#vim#with_preview('right:50%:hidden', '?'),
      \   <bang>0)

nnoremap <C-p>a :Rg 

"" Quick Editing vimrc
nnoremap <leader>ev <C-w>s<C-w>j<C-w>L:e $MYVIMRC<cr>

set background=dark
colorscheme hipster

" manual highlights
" highlight Visual ctermfg=black ctermbg=LightMagenta
" highlight SignColumn ctermbg=black ctermfg=white
" highlight Comment ctermfg=DarkGray
" highlight DiffAdd term=bold ctermfg=yellow ctermbg=black
" highlight DiffDelete term=bold ctermfg=red ctermbg=black
" highlight DiffChange term=bold ctermfg=black ctermbg=DarkGreen

augroup general
    autocmd!
    "keep equal proportions when windows resized
    autocmd VimResized * wincmd =
    "save cursor position in a file
    autocmd BufReadPost * if line("'\"") > 1 && line("'\"")
                \ <= line("$") | exe "normal! g'\"" | endif
augroup END

augroup languages
    autocmd!
    autocmd BufNewFile,BufRead *.bash set syntax=sh
    autocmd FileType python xnoremap <leader>r <esc>:'<,'>:w !python3<CR>
    autocmd FileType go set noexpandtab
    autocmd FileType html :syntax sync fromstart
    autocmd FileType html,javascript,css,json,yaml,sh
                \ setlocal ts=2 sts=2 sw=2 expandtab
augroup END