2018-05-23 07:38:47 +00:00
|
|
|
" vim: set bufhidden=delete list noexpandtab :miv "
|
2017-10-24 09:46:48 +00:00
|
|
|
"!!! makes use of marker '
|
2017-10-18 16:50:13 +00:00
|
|
|
|
2018-02-09 07:31:25 +00:00
|
|
|
set nocompatible
|
|
|
|
""""""""""""""""
|
|
|
|
|
2017-10-24 09:39:53 +00:00
|
|
|
" Sessions
|
|
|
|
set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages
|
2018-03-09 10:56:15 +00:00
|
|
|
set foldmethod=marker
|
2017-10-24 09:39:53 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" some conditional configs
|
|
|
|
if has('mouse')
|
|
|
|
set mouse=a
|
|
|
|
endif
|
2017-11-06 12:18:40 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
if &t_Co > 2 || has("gui_running")
|
|
|
|
syntax on
|
|
|
|
set hlsearch "Highlight search results
|
2017-08-19 06:48:08 +00:00
|
|
|
endif
|
|
|
|
|
2018-01-31 07:17:19 +00:00
|
|
|
if v:version >= 800
|
2017-12-19 15:24:58 +00:00
|
|
|
set cm=blowfish2
|
2018-01-31 07:17:19 +00:00
|
|
|
elseif v:version >= 703
|
|
|
|
set cm=blowfish
|
2017-12-19 15:24:58 +00:00
|
|
|
end
|
2017-11-06 09:07:53 +00:00
|
|
|
|
2017-11-16 10:19:42 +00:00
|
|
|
" set linespace=0
|
2017-11-06 09:00:07 +00:00
|
|
|
set scrolloff=6
|
2017-10-24 09:46:48 +00:00
|
|
|
set history=50 " keep 50 lines of command line history
|
|
|
|
set nonumber
|
2018-01-03 13:17:55 +00:00
|
|
|
" set relativenumber
|
2017-10-18 16:50:13 +00:00
|
|
|
set langmenu=en_UK
|
|
|
|
let $LANG = 'en_UK'
|
|
|
|
source $VIMRUNTIME/delmenu.vim
|
|
|
|
source $VIMRUNTIME/menu.vim
|
|
|
|
set guioptions-=r
|
|
|
|
set guioptions-=R
|
|
|
|
set guioptions-=l
|
|
|
|
set guioptions-=L
|
|
|
|
try
|
2017-10-24 09:46:48 +00:00
|
|
|
set undodir=$HOME/.vimundo
|
2017-10-18 16:50:13 +00:00
|
|
|
set undofile
|
|
|
|
catch
|
2017-10-24 09:46:48 +00:00
|
|
|
echom "Undofile doesn't work :("
|
2017-10-18 16:50:13 +00:00
|
|
|
endtry
|
|
|
|
filetype plugin on
|
|
|
|
filetype indent on
|
|
|
|
set ruler
|
|
|
|
set backspace=eol,start,indent
|
|
|
|
set path+=** " Enable fuzzy search " STAAAAAARS
|
|
|
|
set wildmenu "Menu for tab completion
|
|
|
|
set enc=utf8
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" Search Stuff
|
|
|
|
set ignorecase
|
|
|
|
set smartcase
|
|
|
|
noh
|
|
|
|
set incsearch
|
|
|
|
set lazyredraw
|
|
|
|
set magic "Who doesn't want to be a vim-wizard?
|
|
|
|
set showmatch
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" Backup and file stuff
|
|
|
|
set nobackup
|
|
|
|
set nowb
|
2017-11-06 10:29:05 +00:00
|
|
|
" set noswapfile
|
2017-11-06 12:18:40 +00:00
|
|
|
set swapfile
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" Indentation, etc.
|
|
|
|
set tabstop=2
|
2018-08-01 12:53:37 +00:00
|
|
|
set shiftwidth=0 " Not needed
|
|
|
|
set softtabstop=0 " Not needed
|
2017-10-18 16:50:13 +00:00
|
|
|
set noexpandtab
|
|
|
|
set smarttab
|
|
|
|
set autoindent
|
|
|
|
set smartindent
|
|
|
|
set smarttab
|
|
|
|
set shiftwidth=2
|
|
|
|
set gdefault
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
set wrap
|
2017-10-23 12:28:12 +00:00
|
|
|
au BufEnter,BufRead * set linebreak
|
2017-10-18 16:50:13 +00:00
|
|
|
set breakat=\ .,{
|
|
|
|
set display+=lastline
|
2017-11-16 13:09:18 +00:00
|
|
|
if v:version>=800
|
|
|
|
set breakindent
|
2017-12-18 10:02:12 +00:00
|
|
|
set breakindentopt=sbr
|
2017-11-16 13:09:18 +00:00
|
|
|
au WinNew * set breakindentopt=sbr
|
|
|
|
set showbreak=.\
|
|
|
|
else
|
|
|
|
set showbreak=+->\
|
|
|
|
end
|
2017-11-06 09:00:07 +00:00
|
|
|
set listchars=eol:¶,tab:»\ ,trail:.,nbsp:.
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
set modeline " Allows setting vim options in other files
|
|
|
|
set statusline=(%n)\ %f\ [%M%R]\ [%Y]%=%l,%c%V\ %4.P
|
|
|
|
set laststatus=2
|
|
|
|
set cmdheight=1
|
2017-10-20 07:45:49 +00:00
|
|
|
set timeoutlen=1200
|
2017-10-18 16:50:13 +00:00
|
|
|
|
|
|
|
" Clipboard and Copy/Paste things
|
2017-10-31 12:52:03 +00:00
|
|
|
if has('unnamedplus') " Allow copying to and from OS clipboard
|
|
|
|
set clipboard=unnamedplus
|
|
|
|
else
|
|
|
|
set clipboard=unnamed
|
|
|
|
end
|
2017-10-18 16:50:13 +00:00
|
|
|
|
2017-10-30 12:01:10 +00:00
|
|
|
" === GENERAL UTILITIES ===
|
2017-11-07 14:28:10 +00:00
|
|
|
|
2018-05-11 06:19:32 +00:00
|
|
|
" --- TEXT SNIPPETS ---
|
|
|
|
|
|
|
|
" -- Global --
|
|
|
|
|
|
|
|
if !exists('s:snippets')
|
|
|
|
let s:snippets = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function! s:make_snippet(name, lines)
|
|
|
|
let s:snippets[a:name] = a:lines
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:make_snippet_range(name, line_start, line_end)
|
|
|
|
call s:make_snippet(a:name, getline(a:line_start, a:line_end))
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:insert_snippet(name)
|
|
|
|
for line in get(s:snippets, a:name, [])
|
|
|
|
put =line
|
|
|
|
endfor
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! MkSnip(name, str)
|
|
|
|
call s:make_snippet(a:name, split(a:str, '\n'))
|
|
|
|
endfun
|
|
|
|
|
|
|
|
command! -nargs=1 Snippet call s:insert_snippet(<f-args>)
|
|
|
|
command! -range -nargs=1 MkSnippet call s:make_snippet_range(<f-args>, <line1>, <line2>)
|
|
|
|
|
|
|
|
" -- Filetype --
|
|
|
|
|
|
|
|
if !exists('s:ft_snippets')
|
|
|
|
let s:ft_snippets = {}
|
|
|
|
end
|
|
|
|
|
|
|
|
function! s:make_ft_snippet(ft, name, lines)
|
|
|
|
if !get(s:ft_snippets, a:ft, 0)
|
|
|
|
let s:ft_snippets[a:ft] = {}
|
|
|
|
end
|
|
|
|
let s:ft_snippets[a:ft][a:name] = a:lines
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:make_ft_snippet_range(ft, name, line_start, line_end)
|
|
|
|
call s:make_ft_snippet(a:ft, a:name, getline(a:line_start, a:line_end))
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:insert_ft_snippet(ft, name)
|
|
|
|
for line in get(get(s:ft_snippets, a:ft, {}), a:name, [])
|
|
|
|
put =line
|
|
|
|
endfor
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! MkFTSnip(ft, name, str)
|
|
|
|
call s:make_ft_snippet(a:ft, a:name, split(a:str, '\n'))
|
|
|
|
endfun
|
|
|
|
|
|
|
|
command! -nargs=1 FTSnippet call s:insert_ft_snippet(&filetype, <f-args>)
|
|
|
|
command! -range -nargs=1 FTMkSnippet call s:make_ft_snippet_range(&filetype, <f-args>, <line1>, <line2>)
|
|
|
|
|
|
|
|
" --- AUTO CLOSE ---
|
|
|
|
|
2017-11-07 14:28:10 +00:00
|
|
|
function! s:autoClose_HelperOpen(open, close)
|
|
|
|
let next_c = getline(".")[col(".")-1]
|
|
|
|
if match(next_c, "\s")
|
|
|
|
return a:open.a:close."\<Left>"
|
|
|
|
else
|
|
|
|
return a:open
|
|
|
|
end
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
function! s:autoClose_HelperClose(open, close)
|
2017-11-07 14:41:36 +00:00
|
|
|
if getline(".")[col(".")-1] ==# a:close
|
2017-11-07 14:28:10 +00:00
|
|
|
return "\<Right>"
|
2017-11-10 12:43:23 +00:00
|
|
|
elseif getline(line(".")+1)
|
|
|
|
if match(getline(line(".")+1), "\M^\s*".escape(a:close, "\\"))
|
|
|
|
return "\<Down>\<Home>\<C-o>f".a:close."\<Right>"
|
|
|
|
end
|
2017-11-07 14:28:10 +00:00
|
|
|
else
|
|
|
|
return a:close
|
|
|
|
end
|
|
|
|
endfunc
|
|
|
|
|
2017-11-13 15:00:55 +00:00
|
|
|
function! s:autoClose_HelperDouble(open)
|
|
|
|
if getline(".")[col(".")-1] ==# a:open " Step over
|
|
|
|
return "\<Right>"
|
|
|
|
else
|
|
|
|
return a:open.a:open."\<left>"
|
|
|
|
end
|
|
|
|
endfunc
|
|
|
|
|
2017-11-07 14:28:10 +00:00
|
|
|
function! s:autoClose_HelperEnter()
|
|
|
|
if exists("b:autoClose_Pairs")
|
|
|
|
let next_c = getline(".")[col(".")-1]
|
|
|
|
let prev_c = getline(".")[col(".")-2]
|
|
|
|
|
|
|
|
if (next_c !=# "") && (prev_c !=# "")
|
|
|
|
if exists("b:autoClose_Pairs[prev_c]")
|
|
|
|
if (next_c ==# b:autoClose_Pairs[prev_c])
|
|
|
|
return "\<C-o>m'\<enter>\<C-o>`'\<enter>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-12-19 14:57:18 +00:00
|
|
|
end
|
2017-11-07 14:28:10 +00:00
|
|
|
return "\<enter>"
|
|
|
|
endfunc
|
|
|
|
|
2017-12-19 14:57:18 +00:00
|
|
|
function! s:autoClose_HelperSpace()
|
|
|
|
if exists("b:autoClose_Pairs")
|
|
|
|
let next_c = getline(".")[col(".")-1]
|
|
|
|
let prev_c = getline(".")[col(".")-2]
|
|
|
|
|
|
|
|
if (next_c !=# "") && (prev_c !=# "")
|
|
|
|
if exists("b:autoClose_Pairs[prev_c]")
|
|
|
|
if (next_c ==# b:autoClose_Pairs[prev_c])
|
|
|
|
return "\<space>\<C-o>h\<space>"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return "\<space>"
|
|
|
|
endfunc
|
|
|
|
|
2017-11-07 14:28:10 +00:00
|
|
|
function! s:autoClose_AddPair(open, close) "TODO: Improve with expand('<sfile>')
|
|
|
|
if !exists("b:autoClose_Pairs")
|
|
|
|
let b:autoClose_Pairs = {}
|
|
|
|
end
|
|
|
|
let b:autoClose_Pairs[a:open] = a:close
|
|
|
|
|
2017-11-13 15:00:55 +00:00
|
|
|
if a:open!=#a:close
|
|
|
|
exe "inoremap <buffer> <expr> ".a:open." <SID>autoClose_HelperOpen('".a:open."', '".a:close."')"
|
|
|
|
exe "inoremap <buffer> <expr> ".a:close." <SID>autoClose_HelperClose('".a:open."', '".a:close."')"
|
|
|
|
else
|
|
|
|
exe "inoremap <buffer> <expr> ".a:open." <SID>autoClose_HelperDouble('".a:open."')"
|
|
|
|
end
|
2017-11-07 14:28:10 +00:00
|
|
|
inoremap <buffer> <expr> <enter> <SID>autoClose_HelperEnter()
|
2017-12-19 14:57:18 +00:00
|
|
|
inoremap <buffer> <expr> <space> <SID>autoClose_HelperSpace()
|
2017-11-07 14:28:10 +00:00
|
|
|
endfunc
|
|
|
|
|
2017-10-30 12:01:10 +00:00
|
|
|
function! MatchingLines(pattern)
|
|
|
|
let list = []
|
|
|
|
let pattern = a:pattern
|
|
|
|
exec "g/".pattern."/ call add(list, expand('%').'('.line('.').') : '.matchstr(getline('.'), '".pattern."'))"
|
|
|
|
return list
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
function! s:mld_helper(list, pattern)
|
|
|
|
" Helper function for MatchingLinesDict
|
2017-11-01 11:43:42 +00:00
|
|
|
call add(a:list, {'filename': expand("%"), 'lnum': line("."), 'col': match(getline("."), a:pattern)+1, 'text': matchstr(getline("."), a:pattern)})
|
2017-10-30 12:01:10 +00:00
|
|
|
endfunc
|
|
|
|
function! MatchingLinesDict(pattern)
|
|
|
|
let list = []
|
|
|
|
silent! exec "g/".a:pattern."/ call s:mld_helper(list, a:pattern)"
|
|
|
|
return list
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
function! LocationAddLineCol(filename, lnum, text, col)
|
|
|
|
call setloclist(0, [{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text, 'col': a:col}], 'a')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! QuickfixAddLineCol(filename, lnum, text, col)
|
|
|
|
call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text, 'col': a:col}], 'a')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! LocationAddLine(filename, lnum, text)
|
|
|
|
call setloclist(0, [{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a')
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! QuickfixAddLine(filename, lnum, text)
|
|
|
|
call setqflist([{'filename': a:filename, 'lnum': a:lnum, 'desc': a:text}], 'a')
|
|
|
|
endfunction
|
|
|
|
|
2017-11-01 11:43:42 +00:00
|
|
|
" Original implementation: https://stackoverflow.com/a/6271254/4984564
|
2017-10-31 12:52:03 +00:00
|
|
|
function! VisualSelection()
|
2017-11-01 11:43:42 +00:00
|
|
|
if mode()=="v"
|
|
|
|
let [line_start, column_start] = getpos("v")[1:2]
|
|
|
|
let [line_end, column_end] = getpos(".")[1:2]
|
|
|
|
else
|
|
|
|
let [line_start, column_start] = getpos("'<")[1:2]
|
|
|
|
let [line_end, column_end] = getpos("'>")[1:2]
|
|
|
|
end
|
|
|
|
if (line2byte(line_start)+column_start) > (line2byte(line_end)+column_end)
|
|
|
|
let [line_start, column_start, line_end, column_end] =
|
2018-02-09 07:37:48 +00:00
|
|
|
\ [line_end, column_end, line_start, column_start]
|
2017-11-01 11:43:42 +00:00
|
|
|
end
|
|
|
|
let lines = getline(line_start, line_end)
|
|
|
|
if len(lines) == 0
|
|
|
|
return ''
|
|
|
|
endif
|
|
|
|
let lines[-1] = lines[-1][: column_end - 1]
|
|
|
|
let lines[0] = lines[0][column_start - 1:]
|
|
|
|
return join(lines, "\n")
|
2017-10-31 12:52:03 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-11-01 11:43:42 +00:00
|
|
|
function! StringReverse(str)
|
|
|
|
return join(reverse(split(str, ".\\zs")), "")
|
|
|
|
endfunc
|
|
|
|
|
2017-11-13 15:00:55 +00:00
|
|
|
function! ShiftMarker(m,n)
|
|
|
|
let [bufn,line,column,offset]=getpos("'".a:m)
|
|
|
|
call setpos("'".a:m,[bufn,line,column+a:n,offset])
|
|
|
|
endfunc
|
|
|
|
|
|
|
|
function! ShiftSelection(n)
|
|
|
|
call ShiftMarker("<", a:n)
|
|
|
|
call ShiftMarker(">", a:n)
|
|
|
|
endfunc
|
|
|
|
|
2017-11-16 15:34:43 +00:00
|
|
|
" Auto-close quickfix list when leaving it
|
|
|
|
function! s:autobd()
|
|
|
|
au! WinLeave <buffer> bd!
|
|
|
|
endfun
|
|
|
|
|
2017-10-26 10:39:08 +00:00
|
|
|
" === GENERAL COMMANDS ===
|
2018-03-15 15:30:57 +00:00
|
|
|
|
|
|
|
" General Purpose
|
2018-04-25 08:53:27 +00:00
|
|
|
command! -range Count echo(<line2>-<line1>+1)
|
2018-03-15 15:30:57 +00:00
|
|
|
command! Closeall bufdo bdelete
|
|
|
|
command! Context bufdo bdelete | e .
|
|
|
|
command! Kontext Context
|
2018-08-02 11:49:05 +00:00
|
|
|
command! -range=% Numbers <line1>,<line2>
|
2018-08-15 07:33:46 +00:00
|
|
|
\ s/^/\=printf("%0".float2nr(ceil(log10(<line2>)))."i", line("."))."\t"/
|
2018-08-02 11:49:05 +00:00
|
|
|
\ | noh
|
2018-03-15 15:30:57 +00:00
|
|
|
|
2017-10-26 10:39:08 +00:00
|
|
|
command! L lopen | set number | set norelativenumber
|
2017-10-30 12:01:10 +00:00
|
|
|
command! LAddLine call LocationAddLine(expand("%"), line("."), getline("."))
|
|
|
|
command! QAddLine call QuickfixAddLine(expand("%"), line("."), getline("."))
|
|
|
|
command! LAddCursor call LocationAddLineCol(expand("%"), line("."), getline("."), col("."))
|
|
|
|
command! QAddCursor call QuickfixAddLineCol(expand("%"), line("."), getline("."), col("."))
|
2017-10-26 10:39:08 +00:00
|
|
|
|
2017-11-06 09:00:07 +00:00
|
|
|
command! Fixme call setloclist(0, MatchingLinesDict("\\c\\<fixme.*"))
|
|
|
|
command! Todo call setloclist(0, MatchingLinesDict("\\c\\<todo.*"))
|
2017-10-26 10:39:08 +00:00
|
|
|
|
2017-10-30 12:01:10 +00:00
|
|
|
command! -nargs=1 LFind call setloclist(0, MatchingLinesDict(<args>))
|
|
|
|
command! -nargs=1 QFind call setqflist(MatchingLinesDict(<args>))
|
2017-10-26 11:24:02 +00:00
|
|
|
|
2018-01-30 09:47:42 +00:00
|
|
|
function! s:hex(...)
|
|
|
|
if !(a:000 == [""])
|
2018-01-31 15:29:22 +00:00
|
|
|
let l:args = map(copy(a:000), {i,val -> "".val})
|
2018-01-30 09:47:42 +00:00
|
|
|
else
|
|
|
|
let l:args = []
|
|
|
|
end
|
2018-04-12 06:19:29 +00:00
|
|
|
if &filetype != "xxd"
|
2018-01-31 15:29:22 +00:00
|
|
|
silent exec '%!xxd '.join(l:args, " ")
|
2018-04-12 06:19:29 +00:00
|
|
|
set filetype=xxd
|
2018-01-31 15:29:22 +00:00
|
|
|
nnoremap <buffer> i i<ins>
|
2018-02-09 07:37:48 +00:00
|
|
|
echo "A witch turned your file into a hexadecimal toad!"
|
2018-01-30 09:47:42 +00:00
|
|
|
else
|
2018-01-31 15:29:22 +00:00
|
|
|
nunmap <buffer> i
|
2018-02-09 07:37:48 +00:00
|
|
|
silent exec '%!xxd -r '.join(l:args, " ")
|
2018-04-12 06:19:29 +00:00
|
|
|
filetype detect
|
2018-02-09 07:37:48 +00:00
|
|
|
echo "The witch turned your file back into binary data"
|
2018-01-30 09:47:42 +00:00
|
|
|
end
|
|
|
|
endfunction
|
|
|
|
command! -nargs=* Hex call <sid>hex(<q-args>)
|
|
|
|
|
2018-08-02 14:11:54 +00:00
|
|
|
command! -range=% LuaCompile <line1>,<line2>w !luac -l -p -
|
|
|
|
|
2018-08-02 12:08:27 +00:00
|
|
|
" ┌─────────────────┐
|
|
|
|
" └─┬─┬───┬─┬───┬─┬─┘
|
|
|
|
" │ │ │ │ │ │
|
|
|
|
" │ │ │ │ │ │
|
|
|
|
" ┌─┴─┴───┴─┴───┴─┴─┐
|
|
|
|
" ┌┘ Git Stuff └┐
|
|
|
|
" └───────────────────┘
|
2018-04-12 06:19:29 +00:00
|
|
|
|
2018-08-02 11:51:17 +00:00
|
|
|
function! s:gitroot()
|
|
|
|
let s:ret = substitute(system('git rev-parse --show-toplevel'), '\n\_.*', '', '')
|
|
|
|
if v:shell_error
|
|
|
|
throw s:ret
|
|
|
|
else
|
|
|
|
return s:ret
|
|
|
|
end
|
|
|
|
endf
|
|
|
|
|
2018-04-12 06:22:02 +00:00
|
|
|
function! s:git_history()
|
2018-04-12 07:38:32 +00:00
|
|
|
if exists("b:git_history")
|
2018-04-12 12:18:29 +00:00
|
|
|
if b:git_history[0]+10 > localtime()
|
2018-04-12 07:38:32 +00:00
|
|
|
return b:git_history[1]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-04-12 06:22:02 +00:00
|
|
|
if exists("b:git_original_file") " Is this already a file@revision buffer?
|
|
|
|
let l:fname = b:git_original_file
|
|
|
|
else
|
2018-04-12 12:18:29 +00:00
|
|
|
let l:fname = substitute(expand("%"), "\\\\", "/", "g")
|
2018-04-12 06:22:02 +00:00
|
|
|
end
|
2018-04-12 08:27:49 +00:00
|
|
|
let l:commits = system('git log --format="%h" '.l:fname)
|
2018-04-12 07:38:32 +00:00
|
|
|
let l:hist = split(l:commits, "\n")
|
|
|
|
let b:git_history = [localtime(), l:hist]
|
|
|
|
|
|
|
|
return l:hist
|
2018-04-12 06:22:02 +00:00
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:git_first()
|
|
|
|
if &modified
|
|
|
|
echo "Save your changes first!"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
let l:history = s:git_history()
|
2018-04-12 08:27:49 +00:00
|
|
|
call s:file_at_revision(get(l:history, -1))
|
2018-04-12 06:22:02 +00:00
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:git_last()
|
|
|
|
if &modified
|
|
|
|
echo "Save your changes first!"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
let l:history = s:git_history()
|
|
|
|
call s:file_at_revision(get(l:history, 1, "HEAD"))
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:git_info()
|
|
|
|
if !exists("b:git_revision_hash") || !exists("b:git_original_file")
|
2018-04-12 08:02:43 +00:00
|
|
|
echo "Not a file@revision buffer!"
|
2018-04-12 06:22:02 +00:00
|
|
|
return
|
|
|
|
end
|
|
|
|
echo system("git show --no-patch ".b:git_revision_hash)
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:git_next()
|
|
|
|
if !exists("b:git_revision_hash") || !exists("b:git_original_file")
|
|
|
|
echo "Error 01: Not a file@revision buffer!"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
let l:history = s:git_history()
|
|
|
|
let l:idx = index(l:history, b:git_revision_hash)
|
|
|
|
if l:idx == -1
|
|
|
|
echo "Error 02"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
let l:new_revision = get(l:history, l:idx-1, "LAST")
|
|
|
|
if l:new_revision=="LAST"
|
|
|
|
echo "Already at latest revision! ".l:new_revision
|
|
|
|
return
|
|
|
|
else
|
|
|
|
call s:file_at_revision(l:new_revision)
|
|
|
|
end
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:git_prev()
|
|
|
|
if !exists("b:git_revision_hash") || !exists("b:git_original_file")
|
2018-04-12 07:41:11 +00:00
|
|
|
let l:new_revision = s:git_history()[0]
|
|
|
|
else
|
|
|
|
let l:history = s:git_history()
|
|
|
|
let l:idx = index(l:history, b:git_revision_hash)
|
|
|
|
if l:idx == -1
|
|
|
|
echo "Error 03: cannot find revision ".b:git_revision_hash
|
|
|
|
return
|
|
|
|
end
|
|
|
|
let l:new_revision = get(l:history, l:idx+1, "FIRST")
|
2018-04-12 06:22:02 +00:00
|
|
|
end
|
|
|
|
if l:new_revision=="FIRST"
|
|
|
|
echo "Already at earliest revision! ".l:new_revision
|
|
|
|
return
|
|
|
|
else
|
|
|
|
call s:file_at_revision(l:new_revision)
|
|
|
|
end
|
|
|
|
endfun
|
|
|
|
|
|
|
|
function! s:file_at_revision(rev)
|
2018-04-12 06:36:21 +00:00
|
|
|
let l:pos = getpos(".")
|
2018-04-12 06:22:02 +00:00
|
|
|
if exists("b:git_original_file") " Is this already a file@revision buffer?
|
|
|
|
let l:fname = b:git_original_file
|
|
|
|
let l:ftail = fnamemodify(b:git_original_file, ":t")
|
|
|
|
else
|
2018-04-12 12:02:10 +00:00
|
|
|
let l:fname = expand("%")
|
2018-04-12 06:22:02 +00:00
|
|
|
let l:ftail = expand("%:t")
|
|
|
|
end
|
2018-04-12 12:02:10 +00:00
|
|
|
let l:fname = substitute(l:fname, "\\\\", "/", "g")
|
2018-04-12 06:22:02 +00:00
|
|
|
let l:ftype = &filetype
|
|
|
|
|
|
|
|
ene!
|
2018-04-12 06:59:04 +00:00
|
|
|
set modifiable
|
2018-04-12 06:22:02 +00:00
|
|
|
silent exec "file ".l:ftail."@".a:rev
|
|
|
|
exec "r!git show ".a:rev.":".l:fname
|
2018-04-12 06:59:04 +00:00
|
|
|
1,1del
|
|
|
|
let l:pos[0] = bufnr('.')
|
|
|
|
call setpos('.', l:pos)
|
2018-04-12 06:22:02 +00:00
|
|
|
setl nomodifiable
|
|
|
|
setl buftype=nofile
|
2018-04-12 06:43:20 +00:00
|
|
|
setl bufhidden=delete
|
2018-04-12 06:22:02 +00:00
|
|
|
let &filetype = l:ftype
|
|
|
|
|
|
|
|
let b:git_original_file = l:fname
|
|
|
|
let b:git_revision_hash = a:rev
|
|
|
|
endfun
|
|
|
|
|
2018-04-12 07:41:11 +00:00
|
|
|
function! s:git_diff(...)
|
|
|
|
if a:0
|
|
|
|
split
|
|
|
|
call s:file_at_revision(a:1)
|
2018-04-12 08:02:43 +00:00
|
|
|
diffthis
|
2018-04-12 07:41:11 +00:00
|
|
|
au BufUnload <buffer> diffoff!
|
2018-04-12 08:02:43 +00:00
|
|
|
exec "normal \<C-w>\<C-p>"
|
2018-04-12 07:41:11 +00:00
|
|
|
diffthis
|
2018-04-12 08:02:43 +00:00
|
|
|
call s:git_info()
|
2018-04-12 07:41:11 +00:00
|
|
|
else
|
|
|
|
if exists("b:git_revision_hash")
|
|
|
|
call s:git_diff(get(s:git_history(), index(s:git_history(), b:git_revision_hash)+1, "NIL"))
|
|
|
|
else
|
2018-04-12 08:17:54 +00:00
|
|
|
call s:git_diff(get(s:git_history(), 0, "HEAD"))
|
2018-04-12 07:41:11 +00:00
|
|
|
end
|
|
|
|
end
|
2018-04-12 06:59:04 +00:00
|
|
|
endfun
|
|
|
|
|
2018-07-13 09:25:22 +00:00
|
|
|
function! s:git_blame()
|
|
|
|
let l:name = expand('%')
|
|
|
|
let l:line = getpos('.')[1]
|
|
|
|
let l:char = getpos('.')[2]+59
|
|
|
|
let l:type = &filetype
|
|
|
|
enew
|
|
|
|
set modifiable
|
|
|
|
let &filetype = l:type
|
|
|
|
set buftype=nofile
|
|
|
|
set bufhidden=delete
|
|
|
|
set nowrap
|
|
|
|
silent exec "file Blame: ".l:name
|
|
|
|
keepjumps exec 'r !git blame '.l:name
|
|
|
|
keepjumps 0,0del "
|
|
|
|
set nomodifiable
|
|
|
|
keepjumps call setpos('.', [0, l:line, l:char, 0])
|
|
|
|
endfun
|
|
|
|
|
2018-08-02 11:51:17 +00:00
|
|
|
command! Blame try
|
|
|
|
\| call s:gitroot() | call <sid>git_blame()
|
|
|
|
\| catch | echo 'Not a git repo!'
|
|
|
|
\| endtry
|
|
|
|
command! GitNext try
|
|
|
|
\| call s:gitroot() | call <sid>git_next() | call s:git_info()
|
|
|
|
\| catch | echo 'Not a git repo!'
|
|
|
|
\| endtry
|
2018-04-12 08:02:43 +00:00
|
|
|
command! GitPrev call <sid>git_prev() | call s:git_info()
|
|
|
|
command! GitFirst call <sid>git_first() | call s:git_info()
|
|
|
|
command! GitLast call <sid>git_last() | call s:git_info()
|
2018-04-12 06:22:02 +00:00
|
|
|
command! GitInfo call <sid>git_info()
|
2018-04-12 06:59:04 +00:00
|
|
|
command! -nargs=1 GitCheckout call <sid>file_at_revision(<f-args>)
|
2018-08-02 11:51:17 +00:00
|
|
|
command! -nargs=? GitCompare try
|
|
|
|
\| call s:gitroot() | call <sid>git_diff(<f-args>)
|
|
|
|
\| catch | echo 'Not a git repo!'
|
|
|
|
\| endtry
|
|
|
|
command! Uncommited try
|
|
|
|
\| call s:gitroot() | call <sid>git_diff()
|
|
|
|
\| catch | echo 'Not a git repo!'
|
|
|
|
\| endtry
|
|
|
|
command! GitRoot try
|
|
|
|
\| echo <sid>gitroot()
|
|
|
|
\| catch | echo 'Not a git repository'
|
|
|
|
\| endtry
|
2018-04-12 06:22:02 +00:00
|
|
|
|
2018-04-12 06:59:04 +00:00
|
|
|
" === FILE STUFF ===
|
|
|
|
|
2018-01-30 18:12:00 +00:00
|
|
|
function! s:unsaved()
|
2018-01-30 09:47:42 +00:00
|
|
|
if &mod
|
2018-01-30 18:12:00 +00:00
|
|
|
let l:filetype = &filetype
|
|
|
|
diffthis
|
|
|
|
below new
|
|
|
|
set modifiable
|
|
|
|
r #
|
2018-01-30 21:15:34 +00:00
|
|
|
1,1del
|
2018-01-30 18:12:00 +00:00
|
|
|
diffthis
|
|
|
|
au BufUnload <buffer> diffoff!
|
|
|
|
let &filetype = l:filetype
|
|
|
|
set nomodifiable
|
|
|
|
set buftype=nofile
|
|
|
|
set bufhidden=delete
|
|
|
|
silent exec "file =".expand("#:t")."@".strftime("%H:%M")
|
|
|
|
exec "normal \<C-w>k"
|
|
|
|
set foldlevel=999
|
2018-01-30 09:47:42 +00:00
|
|
|
else
|
|
|
|
echom "No changes to show :)"
|
|
|
|
end
|
|
|
|
endfun
|
2018-01-30 18:12:00 +00:00
|
|
|
command! Unsaved call <sid>unsaved()
|
2018-01-30 09:47:42 +00:00
|
|
|
|
2018-01-30 18:21:50 +00:00
|
|
|
function! s:snapshot()
|
|
|
|
let l:filetype = &filetype
|
|
|
|
let l:clipboard = @"
|
2018-01-30 18:25:08 +00:00
|
|
|
let l:pos = getpos(".")
|
2018-01-30 18:21:50 +00:00
|
|
|
|
2018-01-30 18:22:35 +00:00
|
|
|
silent 0,$yank "
|
2018-01-30 18:21:50 +00:00
|
|
|
below new
|
|
|
|
set modifiable
|
|
|
|
silent put "
|
2018-01-30 18:25:08 +00:00
|
|
|
1,1del
|
2018-01-30 18:21:50 +00:00
|
|
|
let &filetype = l:filetype
|
|
|
|
set nomodifiable
|
|
|
|
set buftype=nofile
|
|
|
|
set bufhidden=hide
|
2018-01-30 18:25:08 +00:00
|
|
|
call setpos(".", l:pos)
|
2018-01-30 18:21:50 +00:00
|
|
|
silent exec "file ¬".expand("#:t")."@".strftime("%H:%M")
|
|
|
|
|
|
|
|
exec "normal \<C-w>k"
|
|
|
|
set foldlevel=999
|
|
|
|
|
|
|
|
let @" = l:clipboard
|
|
|
|
endfun
|
|
|
|
command! Snapshot call <sid>snapshot()
|
|
|
|
|
2018-01-31 15:53:24 +00:00
|
|
|
command! -nargs=? Scratch new | set buftype=nofile | set filetype=<args>
|
2018-05-23 07:38:47 +00:00
|
|
|
command! -nargs=? Tempfile exec 'new '.tempname() | set filetype=<args> | au BufDelete <buffer> call delete(expand('%'))
|
2018-01-31 15:29:22 +00:00
|
|
|
|
2018-03-09 12:54:37 +00:00
|
|
|
" ┌──────────────────────────┐
|
|
|
|
" ├─┬──────────────────────┐ │
|
|
|
|
" ├─┤ GENERAL KEY MAPPINGS ├─┤
|
|
|
|
" │ └──────────────────────┴─┤
|
|
|
|
" └──────────────────────────┘
|
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
let mapleader = "\\"
|
2017-11-06 09:00:07 +00:00
|
|
|
|
2018-04-12 06:20:44 +00:00
|
|
|
" --- Moving Between Buffers ---
|
|
|
|
nnoremap <leader>n :next<CR>:args<CR>
|
|
|
|
nnoremap <leader>p :previous<CR>:args<CR>
|
|
|
|
|
2018-02-09 07:31:25 +00:00
|
|
|
let g:jmp_dist = 8
|
2018-03-07 11:44:04 +00:00
|
|
|
map <C-j> :exec "normal ".g:jmp_dist."j"<CR>
|
|
|
|
map <C-k> :exec "normal ".g:jmp_dist."k"<CR>
|
2018-02-09 07:31:25 +00:00
|
|
|
" Yes, not 'noremap', do whatever is mapped to J and K assuming
|
|
|
|
" it is some sort of custom up-down motion, but g:jmp_dist times
|
|
|
|
|
2018-04-25 07:39:55 +00:00
|
|
|
" --- Marks ---
|
|
|
|
nnoremap <leader>m :marks abcdefghijklmnopqrstuvwxyz<CR>
|
|
|
|
nnoremap <leader>M :marks ABCDEFGHIJKLMNOPQRSTUVWXYZ<CR>
|
|
|
|
|
2018-03-15 15:30:57 +00:00
|
|
|
" --- Windows, Tabs and More --
|
|
|
|
nnoremap <leader><space> :e %:p:h<CR>
|
|
|
|
|
2018-02-20 13:17:02 +00:00
|
|
|
" --- modes ---
|
|
|
|
nnoremap <ins> <ins><ins>
|
|
|
|
|
2017-11-06 15:31:27 +00:00
|
|
|
" --- /dev/null ---
|
|
|
|
noremap <leader>d "_d
|
|
|
|
noremap <leader>d "_d
|
2018-02-20 13:17:02 +00:00
|
|
|
noremap <del> "_x
|
|
|
|
noremap <S-del> 0"_x$
|
2017-11-06 15:31:27 +00:00
|
|
|
|
2018-02-09 07:31:25 +00:00
|
|
|
" --- Numbers ---
|
2017-11-16 13:09:18 +00:00
|
|
|
nnoremap <leader>- <C-x>
|
|
|
|
nnoremap <leader>= <C-a>
|
2017-11-07 15:55:22 +00:00
|
|
|
|
2018-02-09 07:31:25 +00:00
|
|
|
" --- Text ---
|
|
|
|
nnoremap U ~h
|
|
|
|
|
2017-11-06 09:00:07 +00:00
|
|
|
" --- MOVEMENT ---
|
2018-04-12 11:11:33 +00:00
|
|
|
" noremap j gj
|
|
|
|
" noremap k gk
|
2018-02-09 07:31:25 +00:00
|
|
|
|
|
|
|
noremap gj j
|
|
|
|
noremap gk k
|
2017-11-06 09:00:07 +00:00
|
|
|
|
|
|
|
" --- CLIPBOARD ---
|
|
|
|
nnoremap Y y$
|
|
|
|
|
2018-03-07 11:44:04 +00:00
|
|
|
" --- VISUAL EXECUTE ---
|
2018-03-12 08:30:49 +00:00
|
|
|
vnoremap <C-CR> ""y<CR>
|
|
|
|
\ :call setreg("\"", substitute(getreg("\""), "\n", "", ""), "v")<CR>
|
|
|
|
\ :<C-r>"<CR>`<
|
|
|
|
|
2018-04-25 07:41:36 +00:00
|
|
|
let $LUA_PATH = $LUA_PATH.";".expand("<sfile>:p:h")."/lua/?.lua"
|
2018-03-09 13:11:26 +00:00
|
|
|
let g:mooncompile = "!moonc ".expand("<sfile>:p:h")."/lua"
|
|
|
|
command! Mooncompile silent exec g:mooncompile
|
2018-03-09 13:57:04 +00:00
|
|
|
let g:exe_prg = "moonc -- \| lua -l vim -"
|
2018-03-09 12:54:37 +00:00
|
|
|
vnoremap <CR> :<C-U>exec "'<,'>!".g:exe_prg<CR>
|
2018-03-12 08:30:49 +00:00
|
|
|
inoremap <C-Space> <C-[>0v$:<C-U>exec "'<,'>!".g:exe_prg<CR>
|
2018-03-07 11:44:04 +00:00
|
|
|
|
2017-11-06 09:00:07 +00:00
|
|
|
" --- OTHER ---
|
2017-11-13 15:00:55 +00:00
|
|
|
" Don't exit visual mode when "shifting"
|
2017-11-06 09:00:07 +00:00
|
|
|
vnoremap < <gv
|
|
|
|
vnoremap > >gv
|
|
|
|
|
2017-11-13 15:00:55 +00:00
|
|
|
vnoremap <leader>" <C-[>`>a"<C-o>`<"<C-[>:call ShiftSelection(1)<CR>gv
|
|
|
|
vnoremap <leader>' <C-[>`>a'<C-o>`<'<C-[>:call ShiftSelection(1)<CR>gv
|
|
|
|
vnoremap <leader>( <C-[>`>a)<C-o>`<(<C-[>:call ShiftSelection(1)<CR>gv
|
|
|
|
vnoremap <leader>[ <C-[>`>a]<C-o>`<[<C-[>:call ShiftSelection(1)<CR>gv
|
|
|
|
vnoremap <leader>{ <C-[>`>a}<C-o>`<{<C-[>:call ShiftSelection(1)<CR>gv
|
|
|
|
|
2017-10-26 10:39:08 +00:00
|
|
|
nnoremap <S-l> :L<cr>
|
2017-10-18 16:50:13 +00:00
|
|
|
noremap <space> :
|
|
|
|
noremap <C-space> @:
|
|
|
|
noremap Q @q
|
|
|
|
nnoremap <S-space> gQ
|
2018-02-09 07:35:33 +00:00
|
|
|
" This part is just supposed to make saving as inconvenient as possible
|
|
|
|
" because I have a tendency to just save stuff pretty much as soon as I start
|
|
|
|
" typing because I'm bored and possibly a bit paranoid.
|
2018-02-01 08:02:38 +00:00
|
|
|
function! s:saveprompt()
|
2018-02-09 07:35:33 +00:00
|
|
|
if &swapfile
|
|
|
|
echo "You have swap files enabled, stop in-between-saving all the time!"
|
|
|
|
end
|
2018-02-09 07:37:48 +00:00
|
|
|
if input("Type 'save' to save: ") ==? "save"
|
|
|
|
write
|
2018-02-09 07:35:33 +00:00
|
|
|
echo "File saved, but was it really necessary?"
|
2018-02-09 07:37:48 +00:00
|
|
|
else
|
|
|
|
echo "Calm the fuck down man!"
|
|
|
|
end
|
2018-02-01 08:02:38 +00:00
|
|
|
endfun
|
|
|
|
noremap <C-s> :call <sid>saveprompt()<CR>
|
2017-10-18 16:50:13 +00:00
|
|
|
nnoremap <C-n> :bnext<CR>
|
|
|
|
nnoremap <C-p> :bprevious<CR>
|
2017-11-16 15:34:43 +00:00
|
|
|
nnoremap <leader>j :lnext<cr>
|
|
|
|
nnoremap <leader>k :lNext<cr>
|
|
|
|
nnoremap <leader><leader>j :cnext<cr>
|
|
|
|
nnoremap <leader><leader>k :cNext<cr>
|
2017-10-26 09:10:43 +00:00
|
|
|
nnoremap <C-i> Bi <esc>i
|
|
|
|
nnoremap <C-a> Ea <esc>a
|
|
|
|
" This one does nothing, but I'm adding it to remember not to remap the tab key
|
|
|
|
nnoremap <tab> <C-S-I>
|
|
|
|
nnoremap <S-tab> <C-S-O>
|
2017-10-18 16:50:13 +00:00
|
|
|
noremap <F1> :setl number!<CR>
|
|
|
|
noremap <F2> :setl relativenumber!<CR>
|
|
|
|
noremap <F3> :setl autowriteall!<CR>:setl autowriteall?<CR>
|
|
|
|
noremap <F4> :setl list!<CR>
|
|
|
|
nnoremap <C-e> ge
|
|
|
|
nnoremap <C-E> gE
|
2017-11-07 15:58:55 +00:00
|
|
|
com! SetWD :cd %:p:h
|
|
|
|
com! SetLWD :lcd %:p:h
|
2018-03-15 15:30:57 +00:00
|
|
|
com! Trailing let _s=@/ | %s/\v(\\@<!\s)+$//ge | let @/=_s
|
2017-10-18 16:50:13 +00:00
|
|
|
nnoremap <C-d> :copy .<CR>
|
2018-04-13 07:20:43 +00:00
|
|
|
vnoremap <C-d> :copy '><CR>
|
2017-10-18 16:50:13 +00:00
|
|
|
nnoremap dx 0"_d$
|
|
|
|
nnoremap dcx 0d$
|
2017-10-20 07:45:49 +00:00
|
|
|
nnoremap <leader>: :let @* = @:<CR>
|
2017-10-31 12:52:03 +00:00
|
|
|
nnoremap <expr> <S-r> ":%s/\\<".expand("<cword>")."\\>/"
|
2017-11-01 11:43:42 +00:00
|
|
|
vnoremap <expr> <S-r> ":<C-u>%s/".VisualSelection()."/"
|
|
|
|
" Put in new line with indentation
|
|
|
|
nnoremap ]p :let [content, type]=
|
|
|
|
\[getreg(v:register), getregtype(v:register)] \|
|
|
|
|
\call setreg(v:register, content, "V")<CR>]p
|
|
|
|
\:call setreg(v:register, content, type)<CR>
|
|
|
|
nnoremap [p :let [content, type]=
|
|
|
|
\[getreg(v:register), getregtype(v:register)] \|
|
|
|
|
\call setreg(v:register, content, "V")<CR>[p
|
|
|
|
\:call setreg(v:register, content, type)<CR>
|
2017-10-24 07:40:54 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" Empty Lines
|
2017-10-20 07:45:49 +00:00
|
|
|
nnoremap <ENTER> :call <SID>Enter(0)<CR>
|
|
|
|
nnoremap <S-ENTER> :call <SID>Enter(1)<CR>
|
|
|
|
function! s:Enter(shift)
|
|
|
|
if !a:shift
|
2018-01-30 18:12:36 +00:00
|
|
|
silent exe "normal o\<esc>0\"_d$"
|
2017-10-20 07:45:49 +00:00
|
|
|
else
|
2018-01-30 18:22:35 +00:00
|
|
|
silent exe "normal O\<esc>0\"_d$j"
|
2017-10-20 07:45:49 +00:00
|
|
|
endif
|
|
|
|
endfunction
|
2017-10-18 16:50:13 +00:00
|
|
|
|
|
|
|
" Markdown Stuff
|
|
|
|
vnoremap * <C-c>`>a*<C-c>`<i*<C-c>
|
|
|
|
vnoremap _ <C-c>`>a__<C-c>`<i__<C-c>
|
|
|
|
|
|
|
|
" === GENERAL ABBREVIATIONS ===
|
2017-10-18 17:15:31 +00:00
|
|
|
cabbr rcpath fnamemodify($MYVIMRC, ":p:h")
|
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
cabbr <expr> %% expand('%:p:h')
|
2017-10-18 17:15:31 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
digraph <3 9829
|
|
|
|
digraph ue 252
|
|
|
|
digraph UE 220
|
|
|
|
digraph ae 228
|
|
|
|
digraph AE 196
|
|
|
|
digraph oe 246
|
|
|
|
digraph OE 214
|
|
|
|
digraph ss 223
|
|
|
|
|
|
|
|
" === GENERAL AUTOCOMMANDS ===
|
|
|
|
|
2018-02-09 07:31:25 +00:00
|
|
|
command! HLProgress syntax match Comment /\_.*\ze\n.*\%#/
|
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
nnoremap <leader>h :call <SID>toggleWUC()<CR>
|
2018-07-18 08:40:03 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
function! s:updateWUC()
|
|
|
|
if exists("b:hlwuc")
|
|
|
|
if b:hlwuc > 1
|
|
|
|
call matchdelete(b:hlwuc)
|
|
|
|
end
|
|
|
|
end
|
2017-10-20 10:39:20 +00:00
|
|
|
if exists("b:word_hl")
|
|
|
|
let hl = b:word_hl
|
|
|
|
else
|
|
|
|
let hl = "Underlined"
|
|
|
|
endif
|
2018-07-18 08:40:03 +00:00
|
|
|
let l:str = "\\<".escape(expand("<cword>"), "\\")."\\>"
|
|
|
|
let b:hlwuc = matchadd(hl, l:str)
|
2017-10-18 16:50:13 +00:00
|
|
|
endfunc
|
2018-07-18 08:40:03 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
function! s:toggleWUC()
|
|
|
|
augroup hlwuc
|
|
|
|
if exists("b:hlwuc")
|
|
|
|
autocmd!
|
|
|
|
if b:hlwuc > 1
|
|
|
|
call matchdelete(b:hlwuc)
|
|
|
|
end
|
|
|
|
unlet b:hlwuc
|
|
|
|
else
|
|
|
|
autocmd CursorMoved <buffer> call <SID>updateWUC()
|
|
|
|
autocmd CursorMovedI <buffer> call <SID>updateWUC()
|
2018-07-18 08:40:03 +00:00
|
|
|
call <SID>updateWUC()
|
2017-10-18 16:50:13 +00:00
|
|
|
endif
|
|
|
|
augroup END
|
2018-07-18 08:40:03 +00:00
|
|
|
redraw
|
2017-10-18 16:50:13 +00:00
|
|
|
endfunction
|
|
|
|
|
2017-11-03 07:09:12 +00:00
|
|
|
" Autosave when vim loses focus :)
|
2018-02-15 08:06:47 +00:00
|
|
|
function! TryAutosave(warn, mode)
|
2018-02-20 13:17:02 +00:00
|
|
|
if a:mode == 0
|
|
|
|
if &autowriteall || &autowrite
|
2018-02-15 08:06:47 +00:00
|
|
|
silent wall
|
|
|
|
if a:warn
|
|
|
|
echo "Autosaving all buffers..."
|
|
|
|
end
|
2018-02-20 13:17:02 +00:00
|
|
|
end
|
|
|
|
elseif a:mode == 1
|
|
|
|
if &autowriteall
|
2018-02-01 08:02:38 +00:00
|
|
|
if &mod
|
|
|
|
silent write
|
|
|
|
if a:warn
|
|
|
|
echo "Autosaving current buffer..."
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-02-20 13:17:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
redraw
|
2017-10-18 16:50:13 +00:00
|
|
|
endfunction
|
2018-02-20 13:17:02 +00:00
|
|
|
|
2018-02-01 08:02:38 +00:00
|
|
|
augroup autosave
|
|
|
|
autocmd!
|
|
|
|
autocmd FocusLost * call TryAutosave(0, 0)
|
2018-02-20 13:17:02 +00:00
|
|
|
autocmd BufLeave * call TryAutosave(0, 1)
|
|
|
|
autocmd CursorHold * call TryAutosave(0, 1)
|
2018-02-01 08:02:38 +00:00
|
|
|
augroup END
|
2017-10-18 16:50:13 +00:00
|
|
|
|
|
|
|
vnoremap <leader>g :<C-u>call <SID>GrepOperator(visualmode())<CR>
|
|
|
|
nnoremap <leader>g :set operatorfunc=<SID>GrepOperator<CR>g@
|
|
|
|
function! s:GrepOperator(type)
|
|
|
|
let reg1 = @@
|
|
|
|
if a:type==# 'v'
|
|
|
|
execute "normal! `<v`>y"
|
|
|
|
elseif a:type==# 'char'
|
|
|
|
execute "normal! `[y`]"
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
echom "vimgrep! /\\M".escape(@@, "\\")."/ *"
|
|
|
|
silent! execute "vimgrep /\\M".escape(@@, "\\")."/j *"
|
|
|
|
let @@ = reg1
|
|
|
|
copen
|
|
|
|
set nowrap
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
" Window Height stuff
|
2017-11-16 13:09:18 +00:00
|
|
|
command! EqualH call Equal()
|
|
|
|
command! -nargs=1 WinHeight call SetWinMinHeight(<f-args>)
|
2017-10-26 06:49:54 +00:00
|
|
|
function! Equal()
|
|
|
|
set winminheight=0
|
|
|
|
set winheight=1
|
|
|
|
set equalalways!
|
|
|
|
set equalalways!
|
|
|
|
endfunc
|
2017-10-18 16:50:13 +00:00
|
|
|
function! SetWinMinHeight(num)
|
|
|
|
execute "set winminheight=".0
|
2017-10-26 06:49:54 +00:00
|
|
|
if a:num>=0
|
|
|
|
execute "set winheight=".(a:num+1)
|
|
|
|
execute "set winminheight=".a:num
|
|
|
|
endif
|
2017-10-18 16:50:13 +00:00
|
|
|
execute "set winheight=".9999
|
|
|
|
endfunc
|
2017-11-16 13:09:18 +00:00
|
|
|
" call SetWinMinHeight(2)
|
2017-10-18 16:50:13 +00:00
|
|
|
function! AddWinMinHeight(num)
|
|
|
|
let a:new = &winminheight + a:num
|
|
|
|
call SetWinMinHeight(a:new)
|
|
|
|
set winminheight?
|
|
|
|
endfunc
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-26 11:08:27 +00:00
|
|
|
" Window Width Stuff
|
2017-10-26 14:32:00 +00:00
|
|
|
command! EqualW silent! call EqualW()
|
2017-11-16 13:09:18 +00:00
|
|
|
command! -nargs=1 WinWidth call SetWinMinWidth(<f-args>)
|
2017-10-26 11:08:27 +00:00
|
|
|
function! EqualW()
|
|
|
|
set winminwidth=0
|
|
|
|
set winwidth=1
|
|
|
|
set equalalways!
|
|
|
|
set equalalways!
|
|
|
|
endfunc
|
|
|
|
function! SetWinMinWidth(num)
|
|
|
|
execute "set winminwidth=".0
|
|
|
|
if a:num>=0
|
|
|
|
execute "set winwidth=".(a:num+1)
|
|
|
|
execute "set winminwidth=".a:num
|
|
|
|
endif
|
|
|
|
execute "set winwidth=".9999
|
|
|
|
endfunc
|
|
|
|
function! AddWinMinWidth(num)
|
|
|
|
let a:new = &winminwidth + a:num
|
|
|
|
call SetWinMinWidth(a:new)
|
|
|
|
set winminwidth?
|
|
|
|
endfunc
|
|
|
|
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-11-16 15:34:43 +00:00
|
|
|
" === GENERIC AUTOCOMMANDS ===
|
|
|
|
|
2017-08-19 06:48:08 +00:00
|
|
|
if has("autocmd")
|
2017-08-19 07:02:59 +00:00
|
|
|
" Enable file type detection.
|
|
|
|
" Use the default filetype settings, so that mail gets 'tw' set to 72,
|
|
|
|
" 'cindent' is on in C files, etc.
|
|
|
|
" Also load indent files, to automatically do language-dependent indenting.
|
|
|
|
filetype plugin indent on
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-08-19 07:02:59 +00:00
|
|
|
" Put these in an autocmd group, so that we can delete them easily.
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-08-19 07:02:59 +00:00
|
|
|
" For all text files set 'textwidth' to 78 characters.
|
2017-11-16 15:34:43 +00:00
|
|
|
" autocmd FileType text setlocal textwidth=78
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-08-19 07:02:59 +00:00
|
|
|
" When editing a file, always jump to the last known cursor position.
|
|
|
|
" Don't do it when the position is invalid or when inside an event handler
|
|
|
|
" (happens when dropping a file on gvim).
|
|
|
|
autocmd BufReadPost *
|
|
|
|
\ if line("'\"") >= 1 && line("'\"") <= line("$") |
|
|
|
|
\ exe "normal! g`\"" |
|
|
|
|
\ endif
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
endif
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
" === FILETYPE SPECIFIC STUFF ===
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-11-16 10:19:42 +00:00
|
|
|
" --- GENERIC STUFF ---
|
|
|
|
au BufNewFile,BufRead * :call <sid>init_generic_file()
|
|
|
|
|
|
|
|
function! s:init_generic_file()
|
|
|
|
call s:autoClose_AddPair("[", "]")
|
|
|
|
call s:autoClose_AddPair("(", ")")
|
|
|
|
call s:autoClose_AddPair("{", "}")
|
|
|
|
call s:autoClose_AddPair('"', '"')
|
|
|
|
endfunc
|
|
|
|
|
2018-03-07 11:52:24 +00:00
|
|
|
" --- VIMSCRIPT STUFF ---
|
2017-10-26 10:39:08 +00:00
|
|
|
au BufNewFile,BufRead *.vim,*vimrc :call <sid>init_vim_file()
|
|
|
|
|
|
|
|
function! s:init_vim_file()
|
2018-01-03 13:20:23 +00:00
|
|
|
setl number
|
2017-11-16 13:09:18 +00:00
|
|
|
nnoremap <buffer> <F5> :w<CR>:so %<CR>
|
2017-10-26 10:39:08 +00:00
|
|
|
nnoremap <leader>c A<space>"<space>
|
|
|
|
nnoremap <leader>if ofunction! <C-o>m'()<enter>endfunction<C-o>`'<C-o>l
|
|
|
|
|
|
|
|
command! -buffer Functions lex MatchingLines("^\\s*fun\\(ction\\)\\?\\>!.*$")
|
|
|
|
command! -buffer Commands lex MatchingLines("^\\s*com\\(mand\\)\\?\\>!.*$")
|
2017-10-30 12:01:10 +00:00
|
|
|
command! -buffer Autocommands lex MatchingLines("^\\s*au\\(tocmd\\)\\?\\>!\\@!.*$")
|
2017-10-26 10:39:08 +00:00
|
|
|
endfunction
|
2017-10-20 07:45:49 +00:00
|
|
|
|
|
|
|
" --- C / C++ Stuff ---
|
2017-10-19 06:41:26 +00:00
|
|
|
|
2017-10-20 07:45:49 +00:00
|
|
|
" Insert Stuff
|
2017-10-26 14:32:00 +00:00
|
|
|
au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap <buffer> <leader>ii O#include <><esc>i
|
2017-10-20 07:45:49 +00:00
|
|
|
au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap <buffer> <buffer> <leader>ip oprintf("<C-o>m'\n");<esc>`'a
|
|
|
|
au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap <buffer> <leader>im oint main(int argc, char *args[]) {<CR>}<esc>O
|
|
|
|
" Other Stuff
|
2017-10-18 16:50:13 +00:00
|
|
|
au BufNewFile,BufRead *.c,*.cpp,*.h,*.hpp :nnoremap <buffer> ; m'$a;<C-c>`'
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-10-20 07:45:49 +00:00
|
|
|
" --- Ruby Stuff ---
|
2017-10-26 10:39:08 +00:00
|
|
|
au BufNewFile,BufRead *.rb :call <sid>init_ruby_file()
|
|
|
|
|
|
|
|
function! s:init_ruby_file()
|
2018-02-09 07:37:48 +00:00
|
|
|
set makeprg=ruby\ -wc\ %
|
2018-01-03 13:20:23 +00:00
|
|
|
setl number
|
2018-03-13 08:55:01 +00:00
|
|
|
command! -buffer Methods lex MatchingLines("^\\s*def\\>\\s\\+\\zs.*$") | lopen
|
|
|
|
command! -buffer Functions Methods " Alias
|
2017-11-16 15:34:43 +00:00
|
|
|
command! -buffer Classes lex MatchingLines("^\\s*class\\>\\s\\+\\zs.*$") | lopen
|
|
|
|
command! -buffer Modules lex MatchingLines("^\\s*module\\>\\s\\+\\zs.*$") | lopen
|
2018-03-13 08:55:01 +00:00
|
|
|
command! -buffer Members lex MatchingLines("@\\<\\i*\\>") | lopen
|
2017-11-16 15:34:43 +00:00
|
|
|
command! -buffer Requires lex MatchingLines("^\\s*require\\(_relative\\)\\?\\>\\s\\+\\zs.*$") | lopen
|
2017-10-26 10:39:08 +00:00
|
|
|
|
|
|
|
nnoremap <buffer> <leader>ic oclass <C-o>m'<enter>end<esc>`'a
|
|
|
|
nnoremap <buffer> <leader>id odef <C-o>m'()<enter>end<esc>`'a
|
|
|
|
|
|
|
|
nnoremap <buffer> <F5> :w<CR>:!ruby %<CR>
|
2018-01-30 15:38:39 +00:00
|
|
|
nnoremap <buffer> <F6> :lmake<CR>:lopen<CR>
|
2017-10-26 10:39:08 +00:00
|
|
|
nnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR>
|
|
|
|
nnoremap <buffer> <leader># :call <SID>RubyComment(1)<CR>
|
|
|
|
vnoremap <buffer> <leader>~ :call <SID>RubyComment(0)<CR>
|
|
|
|
vnoremap <buffer> <leader># :call <SID>RubyComment(1)<CR>
|
|
|
|
endfunction
|
|
|
|
|
2017-10-18 16:50:13 +00:00
|
|
|
function! s:RubyComment(a)
|
|
|
|
if a:a==0
|
2017-11-16 10:19:42 +00:00
|
|
|
" silent! exec '.s/\m^\s*\zs#*//'
|
|
|
|
silent! exec '.s/\v^(\s|#)*//'
|
|
|
|
normal ==
|
2017-10-18 16:50:13 +00:00
|
|
|
elseif a:a==1
|
2017-11-16 10:19:42 +00:00
|
|
|
" silent! exec '.s/\v^(\s*#)@!/#/'
|
|
|
|
silent! exec '.s/\v^(\s|#)*/# /'
|
|
|
|
normal ==
|
2017-10-18 16:50:13 +00:00
|
|
|
end
|
|
|
|
endfunction
|
2017-08-19 06:48:08 +00:00
|
|
|
|
2017-11-03 07:09:12 +00:00
|
|
|
" augroup rbindent
|
|
|
|
" autocmd!
|
|
|
|
" au BufNewFile,BufRead *.rb :set noexpandtab | :retab! |
|
|
|
|
"
|
|
|
|
" au BufWritePre *.rb :let ts = &tabstop | set expandtab | set tabstop=2 | retab | let &tabstop=ts | :set noexpandtab
|
|
|
|
"
|
|
|
|
" au BufWritepost *.rb :silent! :undo | :exe "normal \<C-O>"
|
|
|
|
" augroup END
|
2017-10-30 15:52:24 +00:00
|
|
|
|
2017-10-30 15:56:35 +00:00
|
|
|
" --- Lua Stuff ---
|
2017-11-12 18:55:15 +00:00
|
|
|
|
|
|
|
" Matches all types of Lua string!
|
|
|
|
" \v(["'])\zs.{-}\ze\\@1<!\2|\[(\=*)\[\zs.{-}\ze\]\3\]
|
|
|
|
|
2017-10-30 15:52:24 +00:00
|
|
|
au BufNewFile,BufRead *.lua :call <sid>init_lua_file()
|
|
|
|
|
|
|
|
function! s:init_lua_file()
|
2018-01-03 13:20:23 +00:00
|
|
|
setl number
|
2017-11-12 18:55:15 +00:00
|
|
|
command! -buffer Requires call setloclist(0, MatchingLinesDict("\\vrequire\\s*\\(?(([\"'])\\zs.{-}\\ze\\\\@1<!\\2|\\[(\\=*)\\[\\zs.{-}\\ze\\]\\3\\])\\)?"))
|
|
|
|
command! -buffer Functions call setloclist(0, MatchingLinesDict("^\\v(\\s*\\zs(local\\s*)?function\\s*[a-zA-Z0-9.:_]*\\(.*\\)(\\s*--.*|\\ze.*)|.*function\\(.*\\)(\\s*--.*|\\ze.*))$"))
|
2017-10-30 15:52:24 +00:00
|
|
|
endfunction!
|
2017-10-30 15:56:35 +00:00
|
|
|
|
2017-10-30 14:50:14 +00:00
|
|
|
" --- HTML Stuff ---
|
2017-11-04 12:16:10 +00:00
|
|
|
au BufNewFile,BufRead *.html,*.htm,*.etlua,*.erb :call <sid>init_html_file()
|
2017-10-30 14:50:14 +00:00
|
|
|
|
|
|
|
function! s:init_html_file()
|
2018-01-03 13:20:23 +00:00
|
|
|
setl number
|
2017-10-30 14:50:14 +00:00
|
|
|
command! -buffer -nargs=1 Tag normal
|
|
|
|
\ i<<args>><<C-o>m'/<args>><ESC>`'
|
2018-03-15 15:30:57 +00:00
|
|
|
nnoremap <buffer> <leader>T ""ciw<<C-o>""p><C-o>m'</<C-o>""p><C-o>`'<C-o>l
|
2017-10-30 14:50:14 +00:00
|
|
|
nnoremap <buffer> <leader>T ""diw<C-o>"_cc<<C-o>""p><C-o>o</<C-o>""p><C-o>O
|
|
|
|
|
2018-02-09 07:37:48 +00:00
|
|
|
function! s:insert_tag(tag, newline)
|
|
|
|
if !a:newline
|
|
|
|
let l:text = "<".a:tag."></".a:tag.">"
|
|
|
|
else
|
|
|
|
end
|
2018-01-31 15:29:22 +00:00
|
|
|
put =l:text
|
2018-02-09 07:37:48 +00:00
|
|
|
endfunction
|
2018-01-31 15:29:22 +00:00
|
|
|
|
2018-02-09 07:37:48 +00:00
|
|
|
nnoremap <C-space> :call <sid>insert_tag(input(""), 0)<CR>
|
2018-01-31 15:29:22 +00:00
|
|
|
|
2017-10-30 14:50:14 +00:00
|
|
|
inoremap <buffer> <C-space> <C-o>""ciw<<C-o>""p><C-o>m'</<C-o>""p><C-o>`'<C-o>l
|
|
|
|
inoremap <buffer> <C-CR> <C-o>""diw<C-o>"_cc<<C-o>""p><C-o>o</<C-o>""p><C-o>O
|
|
|
|
endfunction
|
2018-07-25 08:11:54 +00:00
|
|
|
|
|
|
|
" --- Moonscript Stuff ---
|
|
|
|
|
|
|
|
augroup MOON
|
|
|
|
au!
|
|
|
|
au FileType moon nnoremap <buffer> <F8> :ToggleAutoMoonLocal<CR>
|
|
|
|
au BufWritePost *.moon call <SID>automoon()
|
|
|
|
augroup END
|
|
|
|
com! ToggleAutoMoon echo <SID>toggleautomoon()
|
|
|
|
com! ToggleAutoMoonLocal echo <SID>toggleautomoonlocal()
|
|
|
|
function! s:automoon()
|
|
|
|
if exists('g:automoon') || exists('b:automoon')
|
|
|
|
silent !moonc %
|
|
|
|
redraw
|
|
|
|
end
|
|
|
|
endfun
|
|
|
|
function! s:toggleautomoon()
|
|
|
|
if exists('g:automoon')
|
|
|
|
unlet g:automoon
|
|
|
|
return 'Automoon: off'
|
|
|
|
else
|
|
|
|
let g:automoon=1
|
|
|
|
return 'Automoon: on'
|
|
|
|
end
|
|
|
|
endfun
|
|
|
|
function! s:toggleautomoonlocal()
|
|
|
|
if exists('b:automoon')
|
|
|
|
unlet b:automoon
|
|
|
|
return 'Local Automoon: off'
|
|
|
|
else
|
|
|
|
let b:automoon=1
|
|
|
|
return 'Local Automoon: on'
|
|
|
|
end
|
|
|
|
endfun
|