Skip to content

Instantly share code, notes, and snippets.

@jarun
Last active December 11, 2022 04:58
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 jarun/ffa25d7ea4bf387cd3ca90abae9da284 to your computer and use it in GitHub Desktop.
Save jarun/ffa25d7ea4bf387cd3ca90abae9da284 to your computer and use it in GitHub Desktop.
Useful vim and git tips

vim

daw - delete a word (under cursor)
caw - delete a word (under cursor) and put in insert mode

Remove first 5 characters in each line:

:%s/^.\{0,5\}//

Remove last two characters from each line:

%s/..$//

Swap left and right panes with ^WX.

Reader mode:

vim -R
view

vimdff merge all changes from buffer 1 to buffer 2:

:%diffget 1
:%diffput 2
Source: https://stackoverflow.com/a/31686752/3161329

Binary diff

vimdiff <(xxd foo1.bin) <(xxd foo2.bin)
# use xxd -l1000 to limit to 1000 bytes
Source: https://superuser.com/questions/125376/how-do-i-compare-binary-files-in-linux

Check filetype

:set ft?

git

Undo last change:

git reset --soft HEAD^
git reset --hard HEAD^

Delete a tag:

git push --delete origin tagname
git tag --delete tagname

Squash last n commits:

git reset --soft HEAD~n
git commit -a -S

Rebase last n commits:

git rebase -i -S HEAD~n
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment