1
0
mirror of https://github.com/vbrandl/dotfiles synced 2024-11-27 01:45:12 +01:00
dotfiles/editors/vim/autoload/functions.vim

62 lines
1.8 KiB
VimL
Raw Normal View History

" Window movement shortcuts
" move to the window in the direction shown, or create a new window
function! functions#WinMove(key)
let t:curwin = winnr()
exec "wincmd ".a:key
if (t:curwin == winnr())
if (match(a:key,'[jk]'))
wincmd v
else
wincmd s
endif
exec "wincmd ".a:key
endif
endfunction
" smart tab completion
function! functions#Smart_TabComplete()
let line = getline('.') " current line
let substr = strpart(line, -1, col('.')+1) " from the start of the current
" line to one character right
" of the cursor
let substr = matchstr(substr, '[^ \t]*$') " word till cursor
if (strlen(substr)==0) " nothing to match on empty string
return '\<tab>'
endif
let has_period = match(substr, '\.') != -1 " position of period, if any
let has_slash = match(substr, '\/') != -1 " position of slash, if any
if (!has_period && !has_slash)
return '\<C-X>\<C-P>' " existing text matching
elseif ( has_slash )
return '\<C-X>\<C-F>' " file matching
else
return '\<C-X>\<C-O>' " plugin matching
endif
endfunction
" execute a custom command
function! functions#RunCustomCommand()
up
if g:silent_custom_command
execute 'silent !' . s:customcommand
else
execute '!' . s:customcommand
endif
endfunction
function! functions#SetCustomCommand()
let s:customcommand = input('Enter Custom Command$ ')
endfunction
function! functions#TrimWhiteSpace()
%s/\s\+$//e
endfunction
function! functions#HtmlUnEscape()
silent s/&lt;/</eg
silent s/&gt;/>/eg
silent s/&amp;/\&/eg
endfunction