-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathinsertlessly.vim
More file actions
190 lines (164 loc) · 4.75 KB
/
Copy pathinsertlessly.vim
File metadata and controls
190 lines (164 loc) · 4.75 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
185
186
187
188
189
190
" insertlessly.vim - Waste no more time entering insert mode just to insert enters!
" Author: Barry Arthur <barry dot arthur at gmail dot com>
" Last Updated: 12 Feb 2012
"
" See insertlessly.txt for help. This can be accessed by doing
"
" :helptags ~/.vim/doc
" :help insertlessly
"
" Licensed under the same terms as Vim itself.
" ============================================================================
let g:insertlessly_version = 0.5
" Exit quickly when: {{{1
" - this plugin was already loaded or disabled
" - when 'compatible' is set
if (exists("g:loaded_insertlessly") && g:loaded_insertlessly) || &cp
finish
endif
let g:loaded_insertlessly = 1
" Setup {{{1
let s:cpo_save = &cpo
set cpo&vim
" Options
if !exists('g:insertlessly_insert_newlines')
let g:insertlessly_insert_newlines = 1
endif
if !exists('g:insertlessly_open_newlines')
let g:insertlessly_open_newlines = 1
endif
if !exists('g:insertlessly_backspace_past_bol')
let g:insertlessly_backspace_past_bol = 1
endif
if !exists('g:insertlessly_delete_at_eol_joins')
let g:insertlessly_delete_at_eol_joins = 1
endif
if !exists('g:insertlessly_cleanup_all_ws')
let g:insertlessly_cleanup_all_ws = 1
endif
if !exists('g:insertlessly_cleanup_trailing_ws')
let g:insertlessly_cleanup_trailing_ws = 1
endif
if !exists('g:insertlessly_adjust_cursor')
let g:insertlessly_adjust_cursor = 0
endif
if !exists('g:insertlessly_insert_spaces')
let g:insertlessly_insert_spaces = 1
endif
" Auto Commands {{{1
augroup Insertlessly
au!
au InsertLeave * call <SID>Insertlessly_LeaveInsert()
augroup END
" Maps {{{1
nnoremap <silent> <Plug>BSPastBOL :<c-u>call <SID>BackspacePastBOL()<CR>
nnoremap <silent> <Plug>InsertNewline :<c-u>call <SID>InsertNewline()<CR>
nnoremap <silent> <Plug>OpenNewline :<c-u>call <SID>OpenNewline()<CR>
nnoremap <silent> <Plug>DelAtEOL :<c-u>call <SID>DeleteAtEOL()<CR>
nnoremap <silent> <Plug>InsertSpace :<c-u>call <SID>InsertSpace()<CR>
if !hasmapto('<Plug>InsertNewline') && g:insertlessly_insert_newlines != 0
nmap <Enter> <Plug>InsertNewline
endif
if !hasmapto('<Plug>OpenNewline') && g:insertlessly_open_newlines != 0
nmap <S-Enter> <Plug>OpenNewline
endif
if !hasmapto('<Plug>BSPastBOL') && g:insertlessly_backspace_past_bol != 0
nmap <BS> <Plug>BSPastBOL
endif
if !hasmapto('<Plug>DelAtEOL') && g:insertlessly_delete_at_eol_joins != 0
nmap <Del> <Plug>DelAtEOL
endif
if !hasmapto('<Plug>InsertSpace') && g:insertlessly_insert_spaces != 0
nmap <Space> <Plug>InsertSpace
endif
" Functions {{{1
function! s:BackspacePastBOL()
if g:insertlessly_insert_newlines != 0
let pos = getpos('.')
let line = getline('.')
if (pos[2] == 1) && (pos[1] > 1)
if match(line, '.') != -1
normal! kJ
else
normal! kgJ
endif
else
exe "normal! " . v:count1 . "X"
endif
else
exe "normal! " . v:count1 . "X"
endif
endfunction
function! s:getcmdwintype()
if exists('*getcmdwintype')
return getcmdwintype()
elseif bufname('%') == '[Command Line]'
return 0
else
return 1
endif
endfunction
function! s:InsertNewline()
" Special buffer types (help, quickfix, command window, etc.) have buftype set
if (&buftype == "") || (&buftype == 'nofile' && s:getcmdwintype() == '')
if (col('.') + 1) == col('$')
exe "normal! " . v:count1 . "o"
else
exe "normal! " . v:count1 . "i\<Enter>"
endif
else
exe "normal! " . v:count1 . "\<Enter>"
endif
endfunction
function! s:OpenNewline()
exe "normal! " . v:count1 . "o"
endfunction
function! s:DeleteAtEOL()
if g:insertlessly_delete_at_eol_joins != 0
let eol_col = col('$')
let col = col('.')
let eob_line = line('$')
let line = line('.')
if ((col == 1) && (col == eol_col)) || (((col + 1) == eol_col) && (line != eob_line))
normal! J
else
exe "normal! " . v:count1 . "x"
endif
else
exe "normal! " . v:count1 . "x"
endif
endfunction
function! s:Insertlessly_LeaveInsert()
augroup InsertlesslyCleanup
au!
au CursorMoved,CursorHold * call s:CleanupAllWhitespace() | call s:AdjustCursor() | au! InsertlesslyCleanup
augroup END
endfunction
function! s:CleanupAllWhitespace()
if g:insertlessly_cleanup_all_ws != 0
call insertlessly#cleanup_all_whitespace()
else
call s:CleanupLine()
endif
endfunction
function! s:CleanupLine()
if g:insertlessly_cleanup_trailing_ws != 0
call insertlessly#cleanup_line()
endif
endfunction
function! s:AdjustCursor()
if g:insertlessly_adjust_cursor != 0
let col = col('.')
if col != 1
if col != (col('$') - 1)
normal! l
endif
endif
endif
endfunction
function! s:InsertSpace()
silent exe "normal! " . v:count1 . "i \<esc>l"
endfunction
" Teardown {{{1
let &cpo = s:cpo_save
" vim:set ft=vim sw=2 sts=2 et fdm=marker: