Skip to content

Instantly share code, notes, and snippets.

@ayinlaaji
Last active May 3, 2020 17:54
Show Gist options
  • Save ayinlaaji/c647e4b7eba4e2daa19af76e4800b32f to your computer and use it in GitHub Desktop.
Save ayinlaaji/c647e4b7eba4e2daa19af76e4800b32f to your computer and use it in GitHub Desktop.
snippets

Snips

  • Find and rename files with regexp

    find . -type f -name '*.stories.tsx' -execdir  rename  -v 's/(.*)\.stories\.tsx$/component\.stories\.tsx/' {} \;;
    
  • Redirect port:

    sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8000
    
  • Rename all occurance of text:

    git grep -l 'original_text' | xargs sed -i 's/original_text/new_text/g'
    
  • Replace a text occurrence with / in multiple files

    cur='@quadlobe/spt'
    rep='spt'
    git grep -l "$cur" | xargs sed -i -e "s%$cur%$rep%g"
    
  • Rename files in a directory

    files=$(find . -iname "*.js")
    
    for file in $files; do
      mv "$file" "${file%.js}.ts"
    done
    

Vim macro

  • Apply macro on lines matching pattern :g/pattern/norm! @a
  • Apply macro on line 5 to 10 :5,10norm! @a
  • Apply macro on highlights lines (V) :'<,'>norm! @a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment