vim/vimrc.functions.vim

66 lines
2.0 KiB
VimL

" TODO better name
function! GetStatusFrag(condition, colorname, conditionprefix, text) abort "{{{
let l:frag='%#' . a:colorname . '#'
let l:frag.=a:conditionprefix
let l:frag.='%{(' . a:condition . ")?'" . a:text . "':''}"
return l:frag
endfunction"}}}
function! CheckLineEnding() abort "{{{
:normal $
if getline('.')[col('.')-1] == ';' || getline('.')[col('.')-1] == ','
:startinsert
else
:startinsert!
endif
endfunction"}}}
" get name of syntax item
function! SyntaxItem() abort "{{{
return synIDattr(synID(line('.'),col('.'),1),'name') . ' -> ' . synIDattr(synIDtrans(synID(line('.'),col('.'),1)), 'name' )
endfunction
nnoremap <space>p :echom SyntaxItem()<CR>"}}}
" devdocs DD
" https://gist.github.com/romainl/8d3b73428b4366f75a19be2dad2f0987#file-devdocs-vim
function! s:Get_env() abort "{{{
if has('win64') || has('win32') || has('win16')
return 'WINDOWS'
else
return toupper(substitute(system('uname'), '\n', '', ''))
endif
endfunction
" What command to use on what system
let s:cmds = {'DARWIN': 'open', 'LINUX': 'qutebrowser', 'WINDOWS': 'start'}
" Build the URL stub
let s:stub = s:cmds[<SID>Get_env()] . " 'http://devdocs.io/?q="
command! -nargs=* DD silent! call system(len(split(<q-args>, ' ')) == 0 ?
\ s:stub . &ft . ' ' . expand('<cword>') . "'" : len(split(<q-args>, ' ')) == 1 ?
\ s:stub . &ft . ' ' . <q-args> . "'" : s:stub . <q-args> . "'")
"}}}
" use ranger as file manager
if !exists('*RangerExplorer') "{{{
function RangerExplorer() abort
exec 'silent !ranger --choosefile=/tmp/vim_ranger_current_file ' . expand('%:p:h')
if filereadable('/tmp/vim_ranger_current_file')
exec 'edit ' . system('cat /tmp/vim_ranger_current_file')
call system('rm /tmp/vim_ranger_current_file')
endif
redraw!
endfun
map <space>ra :call RangerExplorer()<CR>
endif"}}}
function! GetLinterStatus(key) abort "{{{
let l:linter = ale#statusline#Count(bufnr(''))
return l:linter[a:key]
endfunction
"}}}
" vim: foldmethod=marker