-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.vimrc
More file actions
184 lines (161 loc) · 4.48 KB
/
.vimrc
File metadata and controls
184 lines (161 loc) · 4.48 KB
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
180
181
182
183
184
" this allows pathogen plugin to be in its own submodule
runtime bundle/pathogen/autoload/pathogen.vim
filetype off
call pathogen#infect()
filetype plugin indent on
" default swap file location
set directory=~/.tmp//,.
" indentation
set autoindent
set tabstop=4
set shiftwidth=4
set expandtab
" buffer search
set hls " highlight search
set incsearch " incremental search
set ignorecase " ignore case ...
set smartcase " ... but only if there is no uppercase letters
set showmatch " quickly jump cursor to matching bracket
set linebreak " won't split a word
set encoding=utf-8
set number
set title
set showcmd
" the colorscheme section
set t_Co=256
colorscheme gruvbox
" https://github.com/morhetz/gruvbox/issues/175
let g:gruvbox_guisp_fallback = "bg"
if filereadable(expand("~/.config/prefer-light-color-scheme"))
set background=light
else
set background=dark
endif
" most common vertical movement in wrapped lines
" for other commands, prepend 'g' ex. g$
nnoremap j gj
nnoremap k gk
vnoremap j gj
vnoremap k gk
inoremap jj <Esc>
" buffers and clipboards
nnoremap <C-N> :bnext<Cr>
vnoremap Y "+y
let mapleader = ","
nnoremap <silent> <Leader><Space> :noh<Cr>
nnoremap <Leader>c :CtrlP<Cr>
nnoremap <Leader>s :w<Cr>
nnoremap <F1> :call BlogPost()<Cr>
nnoremap <F3> :call SetSpell()<Cr>
nnoremap <F4> :call SetFoldMethod()<Cr>
nmap <leader>c <Plug>FocusModeToggle
nnoremap <leader>m :call KBFollowLink()<Cr>
nnoremap <leader>ev :vsplit $MYVIMRC<Cr>
nnoremap <leader>v :source $MYVIMRC<Cr>
" my filetypes
au BufNewFile,BufRead *.j2 setf htmljinja
" GUI options
if has("gui_running")
set lines=40
set columns=84 " 80 + 4 lines that 'numbers' uses
set guifont=Monospace\ 12
set guioptions-=m " remove menu bar
set guioptions-=T " remove toolbar
endif
function! BlogPost()
set ft=markdown
set tw=62
%s/“/"/ge
%s/”/"/ge
%s/’/'/ge
endfunction
function! SetSpell()
if &spell
set nospell
echo "No spell checking"
else
set spell
echo "Spell checking"
endif
endfunction
function! SetFoldMethod()
if &foldmethod == "manual"
set foldmethod=indent
echo "Foldmethod: indent"
else
set foldmethod=manual
echo "Foldmethod: manual"
endif
endfunction
" All KB functions assume one is in the right KB folder
function! KBFollowLink()
" search for a 12-digit ID in the current line
let note_id = matchstr(getline('.'), '\d\{12}')
if note_id != ""
let filename = system("find . -name '*".note_id.".md'")
execute "edit ".filename
return 0
endif
" if you can't find an ID, search for a hashtag in the current line
let tag = matchstr(getline('.'), '#\S\+')
if tag != ""
execute "vimgrep /" . tag . "/j *.md"
execute "copen"
return 0
endif
endfunction
function! KBWhatLinksToHere()
let note_id = matchstr(expand('%:t'), '\d\{12}')
if note_id != ""
execute "silent! vimgrep /" . note_id . "/j *.md"
if len(getqflist()) != 0
execute "copen"
else
echo "No other notes link to this note."
endif
else
echo "Can't find the note ID in the name of the file."
endif
endfun
augroup kbgroup
autocmd!
if exists("$KB_HOME")
execute 'autocmd BufRead,BufNewFile '.fnameescape($KB_HOME).'/* setlocal completefunc=KBComplete'
endif
augroup END
function! KBComplete(findstart, base)
if a:findstart
" locate the start of the word
let line = getline('.')
" is it a tag? #
let start = match(line, '#')
if start >= 0
return start
endif
" is it an ID? [[
let start = match(line, '@')
if start >= 0
return start
endif
return -3 " Negative return values: -3 To cancel silently and leave completion mode.
else
if a:base =~ '@' " match note IDs ...
" match excluding the @ character and match anywhere in the line
let matchstring = a:base[1:]
let filename = '.noteids'
elseif a:base =~ '#' " ... or match tags
" match from the beginning including '#'
let matchstring = '^' . a:base
let filename = '.notetags'
else " no match
return []
endif
let res = []
for line in readfile(filename)
if line =~ matchstring
call add(res, line)
endif
endfor
return res
endif
endfun