Skip to content

Instantly share code, notes, and snippets.

@huyhoang8398
Forked from ericdouglas/super-tip.txt
Created August 16, 2023 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huyhoang8398/c6681e50981854e865f7d56ece9f1381 to your computer and use it in GitHub Desktop.
Save huyhoang8398/c6681e50981854e865f7d56ece9f1381 to your computer and use it in GitHub Desktop.
Change 4 spaces to 2 spaces indentation and change tab to spaces - Vim tip
// 4 spaces to 2 spaces
%s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g
// Tab to 2 spaces
:%s/\t/ /g
@huyhoang8398
Copy link
Author

Put this in .vimrc

fun! Four2Two() range
  '<,'>s;^\(\s\+\);\=repeat(' ', len(submatch(0))/2);g
  norm!gv
endfun

Select the code V and apply it by :'<,'>call Four2Two()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment