Skip to content

Instantly share code, notes, and snippets.

@humus
Last active December 23, 2015 03:59
Show Gist options
  • Select an option

  • Save humus/6577058 to your computer and use it in GitHub Desktop.

Select an option

Save humus/6577058 to your computer and use it in GitHub Desktop.
Función para cambiar a snake_case la últimas palabras escritas
fun! Snake_last() "{{{
let start_mod = getpos("'[")
let end_mod = getpos("']")
if start_mod[1] != end_mod[1]
return
endif
let mod_line = getline(start_mod[1])
let inserted_text = mod_line[start_mod[2] - 1:end_mod[2] - 2]
let text_replacement = substitute(inserted_text, '\v(\S)@<=\s(\S)@=', '_', 'g')
let prepared_line = ''
if start_mod[2] > 1
let prepared_line .= mod_line[0:start_mod[2]-2]
endif
let prepared_line .= mod_line[end_mod[2]-1:-1]
call setline(start_mod[1], prepared_line)
call setpos('.', start_mod)
call feedkeys('i' . text_replacement . "\<Esc>")
endfunction "}}}
command! SnakeCaseLast call Snake_last()
cab sl SnakeCaseLast
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment