February 2024: Futzing with Configs

Most of my work that doesn't happen in mark-up, happens in a terminal. This makes the combo of vim + tmux unbeatable for me personally. While I'm technically open to discuss the merits of vim against those of emacs (nano can go bury itself in a hole), tmux is somewhat unnegotiable in my workflow. That being said, I've never gotten around to writing my own config, even though I'm never actually very happy with the ones I either found online, or took from other people. Since the SSD drive in my primary work machine decided boot partitions were for losers and I basically had to set up a new operating system either way, I might as well use this opportunity to remedy this.

It's probably best to go feature by feature, some I've never been very comfortable using, some I never figured out. First is window resizing. I have relatively large screen resolutions and tiny script size, so there's usually ample space to move windows around. It also means that using the arrow keys for resizing is absolute ass. This is partially, because of a quirk of linux terminals, that maps ^?H to the backspace key. There's ways to change that, but that's a problem future me might tackle. In the meantime I mapped the larger chunk resizes to the WASD keys. Not great, but better than having a random different key in there somewhere.

bind -r C-d resize-pane -R 10
bind -r C-a resize-pane -L 10
bind -r C-s resize-pane -D 5
bind -r C-w resize-pane -U 5

I don't strictly speaking have a use for cycling panes, but maybe I'll find one, once I run out of real-estate on the screen again. Whenever that happens though, I'm pretty sure I'll want to cycle both directions, and since the counter-clockwise cycle is already mapped onto O, I'd like the clockwise nearby. I have designs on the P key, so I'll map it to I.

unbind C-i
bind -r C-i rotate-window -D 
unbind C-o
bind -r C-o rotate-window -U

The sessions functionality is great, and I've not used it too often. I don't need those keystrokes to go fast, so I decided to leave them where they are and just study them. Most interesting to me are the create/list/kill keystrokes. Beyond that, I like to have a smaller list-session and new-session option available without thinking about which bracket does what.

bind-key M list-sessions
bind-key N new-session

By the way, if you're debugging your tmux config, it's good to bind a key for sourcing your config.

unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded config"

My vim config could also use an update, along with maybe a way to automate calling ctags, because I always forget to do that myself.

Vim doesn't come with a vimrc lying around, but that's mostly fine, because it uses relatively sensible defaults. Still, if I'm writing a config, it might as well be as complete as I can think of. The first thing I always change in vim is showing the number on the left of a pane.

syntax on
set number

Then I like to make sure that typing tabs actually gives me tabs.

set shiftwidth=4
set tabstop=4
set expandtab

Beyond this, I'd like to have the cursorline and other quality-of-life improvements when it comes to searching, even though I haven't really needed it much, and the wildmenu, which is just better than cycling through all the file options.

set cursorline
set hlsearch
set wildmenu
set wildmode=list:longest

All of these are just standard config lines.

The interesting stuff comes from vimscripting. Here's where I want to get vim to call ctags in the directory I open it. Vimscripting features the option to design functions and call bash commands from inside them. The triggers, i.e. when these functions are meant to be called, are a separate thing that we'll get back to. First the function to call ctags whenever vim is opened.

function! LoadTags()
	let comm = 'exuberant-ctags -R'
	execute '!'.comm
	return 1
endfunction

Technically we could pass arguments to the function, but we don't need to. Upon closer inspection one can notice that what I'm calling via "execute" is the regular bash command (exuberant-ctags -R), preceded by "!". This is just the syntax for calling bash commands in vim. I like doing things this way, so that internally, I can separate the bash portion from the vim portion. ctags will create a tags file in the directory it's called, and - for middlingly large projects - the easiest way to update the tags is to just delete the file and generate it again. We need a separate function for that, too.

function! CleanUp()
	let comm = 'rm tags'
	execute '!'.comm
	return 1
endfunction

Straight-forward and easy. Then, we need to call LoadTags, when vim is opened, and CleanUp when it's closed. Vim features the autocmd keyword, which describes what might be familiar from javascript as event triggers. For us, we're looking for the VimEnter and VimLeave events. Then, we would also like to have the commands run quietly, because there's really no way these can break in a way that we need to notice. This will involve the silent! keyword when calling the functions.

autocmd VimEnter silent! LoadTags()
autocmd VimLeave silent! CleanUp()

And that's all my configs now. Not a lot of work went into this, but so far I'm expecting them to save me a good amount of effort moving forward.

Previous
Previous

March & April 2024: Programming with Hieroglyphics

Next
Next

January 2024: Scanlation