Created
April 19, 2017 07:14
-
-
Save jerrymarino/094c6cb23b97a74d5a668eca5ad79d52 to your computer and use it in GitHub Desktop.
Jump to semantic placeholders in vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function! Generate_placeholder_pattern() | |
return '<#\%(T##\)\?\%([^#]\+##\)\?\([^#]\+\)#>' | |
endfunction | |
function! Jump_to_placeholder() | |
if &filetype !=# 'swift' | |
return '' | |
end | |
if !Check_placeholder_existence() | |
return '' | |
endif | |
:call Begin_replacing_placeholder() | |
endfunction | |
function! Begin_replacing_placeholder() | |
echom "replace" | |
"if mode() !=# 'n' | |
" return | |
"endif | |
let l:pattern = Generate_placeholder_pattern() | |
let [l:line, l:column] = searchpos(l:pattern) | |
if l:line == 0 && l:column == 0 | |
return | |
end | |
execute printf(':%d s/%s//', l:line, l:pattern) | |
call cursor(l:line, l:column) | |
"startinsert | |
endfunction | |
function! Check_placeholder_existence() | |
return search(Generate_placeholder_pattern()) | |
endfunction | |
:nmap <C-k> :call Jump_to_placeholder() <CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment