From 560a40492e1954d19f4528d58c2f45b07379cff5 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 8 May 2024 11:40:31 +0100 Subject: new post: snip snap --- posts/snip_snap.md | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 posts/snip_snap.md (limited to 'posts') diff --git a/posts/snip_snap.md b/posts/snip_snap.md new file mode 100644 index 0000000..fa61fe2 --- /dev/null +++ b/posts/snip_snap.md @@ -0,0 +1,102 @@ +I regularly switch between exactly two things while working, +a "current" and an "alternate" item; a lot of tools I use +seem to support this flow. + +#### git + +Pass `-` to `git-checkout` to switch to the previously +active branch: + +```bash +$ git branch +* foo + bar + +$ git checkout bar +$ git branch + foo +* bar + +$ git checkout - +$ git branch +* foo + bar +``` + +#### bash - cd + +This may not be exclusive to `bash`: + +```bash +~/foo $ cd ~/bar +~/bar $ cd - +~/foo $ +``` + +This is especially handy in combination with my [git-worktree +flow](../curing_a_case_of_git-UX/): + +```bash +~/main-branch $ gwj feature +~/feat-branch $ cd - +~/main-branch $ +``` + +#### bash - jobs + +I often suspend multiple `vim` sessions with `Ctrl-Z`: + +```bash +$ jobs +[1]+ Stopped vim transpiler/src/transform.rs +[2]- Stopped git commit --verbose +``` + +In the above example: I suspended `vim` when working on +`transform.rs`, and then began working on a commit by +running `git commit` without a message flag (lets you craft +a message in `$EDITOR`). To bring the current job to the +foreground, you can use `fg`: + +```bash +$ fg +``` + +With a job identifier: + +```bash +$ fg %2 # resumes interactive git commit +``` + +Or switch to "last" job, or the second-most-recently-resumed +job: + +```bash +$ fg %- +$ %- # shorthand + +``` + +#### vim + +Switch to the last active buffer with `Ctrl+^`. In +command-mode, `#` refers to the last active buffer, you can +use this as an argument to a few commands: + +```vimscript +:b# " switch to alternate buffer (same as Ctrl+^) +:vsp# " create a vertical split with the alternate buffer +:read# " read contents of alternate buffer into current buffer +:!wc # " pass file name of alternate buffer to the command `wc` +``` + +See `:help c_#` for more. + +#### tmux + +Switch to the last active tmux session with +`+shift+L`. + +#### qutebrowser + +Switch to the last active tab with `g$`. -- cgit v1.2.3