Blog History Page 6

Starting Your Terminal with tmux

I am getting more comfortable with tmux and I want to make sure I don't forget to use it when I'm at the command prompt. So, I made a simple Bash script to automatically connect to an existing session or start a new session when I start my terminal:

tmux-start.sh:

#!/bin/bash
tmux ls > /dev/null ; [ $? == 0 ] && tmux attach || tmux
  • tmux ls will list existing sessions, but I'm dumping that output and just using its return value which will be 0 if there are any existing sessions.
  • $? is the return value of the previous command
  • && ... || is basically equivalent to a ternary operator in other programming languages

Use Vim as a Pager

I wanted to be able to scroll a man page in the terminal with my mouse wheel. While looking for a setting to change I learned that Vim can be used as a pager allowing mouse support and much more. Inspired by this entry at the Vim Tips Wiki, I decided to set it up for myself, but with a few minor changes. I did all this in WSL with Ubuntu 20.04.6 and Zsh on Windows 11, but it should work as well with any Unix or Linux variant:

~/.zshrc:

export PAGER="/bin/sh -c \"unset PAGER;col -b -x | vim -R \
    -c 'set ft=man mouse=a nonumber t_te=' \
    -c 'highlight Normal ctermbg=NONE guibg=NONE' \
    -c 'map q :q<CR>' \
    -c 'map <SPACE> <C-D>' \
    -c 'map b <C-U>' \
    -c 'nmap K :Man <C-R>=expand(\\\"<cword>\\\")<CR><CR>' -\""

This is very similar to what was documented in the Vim Tips Wiki, but I've made a few changes to suit my needs...

  • /bin/sh -c executes a command with the most basic shell on the system (Bash on most modern systems)
  • col -b -x filters out reverse line feeds used by man to show underlined text when outputting directly to the console.
  • vim -R starts Vim in read-only mode
    • I initially replaced this with nvim, but the key mapping for the q key doesn't work with Neovim.
  • -c 'set ft=man mouse=a nonumber t_te='
    • -c: executes a command in Vim. This line sets a few options
    • ft=man (a.k.a. filetype=man) enables proper syntax highlighting for man pages
    • mouse=a: enables mouse support for all editor modes
    • nonumber: turns off the line numbers I usually have enabled for editing code
    • t_te=: disables clearing the screen when Vim exits
  • -c 'highlight Normal ctermbg=NONE guibg=NONE': This disables the background color that I use in the editor when editing code so that my terminal transparency is still in effect.
  • The rest of the lines change some key mappings so that it works in a familiar way if you're used to less (the default pager for man pages)

VSCodeVim Broke Quick Open

VSCodeVim Cartoon Character Breaking VSCode

VSCodeVim broke VSCode's file Quick Open keybinding. Now, CTRL-P just moves the cursor up a line instead of opening the file finder as expected.

Based on the GitHub issue linked in the commit, it was meant to enable MacOS's default cursor movement keys.

Issue #8574 shows some easy fixes. I chose to disable the plugin's handling of the keybinding:

"vim.handleKeys": {
    "<C-p>": false
}

This is in settings.json and I got there by opening Settings, entering "handlekeys" into the search box, and clicking on the "Edit in settings.json" link.

References