Time to Tweak the Terminal#
Having played around with and gotten some comfort level with Vim
with VS Code
, I feel it’s time to start exploring using Vim
from the terminal. Dun, Dun, Dun! I’ve very little experience with this apart from git
and running the occassional hugo
or gulp
basic commands, also from within the VS Code
environment.
In order to setup Vim
properly and to make the most of the experience of writing Python, it’s the next logical step for me to get comfortable with the terminal. Already I’ve found a multitude of plugins, hacks and possibilities to alter the terminal experience, but let’s go step by step.
I want to have an idea of where I am in the terminal, in terms of location, but at present my terminal shows an enormous string on the command prompt
line. Here’s an example"
(base) Communitymanager-work@David-Nevins-MacBook-Pro ~ %
This as you can imagine offers a high level of distraction and once I delve deeper into folders it becomes a mess. And yes, I know my computer name is a mess, I set it some years ago when I only ever considered the experience from inside the MacOS environment. Subsequent migrations with using full backups have carried over this mistake many times.
To change the command prompt text
for a single use I found the following command on stackoverflow
.
PS1="\w\n>"
Warning: Rabbit hole!
Z-Shell Customizing#
Following the advise of these two videos by Corey Schafer:
- Customizing Your Terminal: .bash_profile and .bashrc files
- Customizing Your Terminal: Adding Color and Information to Your Prompt
I went through the process of exploring both video’s and in doing so stumbled across the depreciation warning
in my MacOS bash
shell. After a little reading of this excellent series Scripting OX
and then switched my setup to zsh
or z-shell, as the preferred/recommended MacOS terminal default.
I also discovered Oh-my-zsh but that is taking it too far for me at the moment.
I just want a few tweaks to offer a few handrails while I get into terminal
usage.
For anyone interested, the zsh
manual is here. zsh options
I choose to use the ~/.zshrc
for my personal configurations.
This zsh/Misc/vcs_info-examples github was the basis for the git functionality in the command line.
This is what I ended up with: (edited to remove anaconda and other config details)
autoload -Uz vcs_info
precmd() {
vcs_info
if [[ -z ${vcs_info_msg_0_} ]]; then
PS1="%5~%# "
else
PS1="%2~${vcs_info_msg_0_}%# "
fi
}
setopt prompt_subst
# Enable wildcard search and tab through options
setopt NO_CASE_GLOB
# Auto change to directory if directory name is used
setopt AUTO_CD
# Remember history from previous sessions
HISTFILE=${ZDOTDIR:-$HOME}/.zsh_history
# Add additional info to shell history
setopt EXTENDED_HISTORY
SAVEHIST=5000
HISTSIZE=2000
# share history across multiple zsh sessions
setopt SHARE_HISTORY
# append to history
setopt APPEND_HISTORY
# adds commands as they are typed, not at shell exit
setopt INC_APPEND_HISTORY
# expire duplicates first
setopt HIST_EXPIRE_DUPS_FIRST
# do not store duplications
setopt HIST_IGNORE_DUPS
#ignore duplicates when searching
setopt HIST_FIND_NO_DUPS
# removes blank lines from history
setopt HIST_REDUCE_BLANKS
# When you mistype a command or path, the shell is usually unforgiving. In zsh you can enable correction.
setopt CORRECT
setopt CORRECT_ALL
#Aliases
alias ll='ls -al'
...
Vim Config#
This it seems is a whole entire universe. In nuce, I went with a combination of these two configurations. It will evolve as my understanding of my needs evolve.
I installed the Vim Plug
following instructions from here:
Linux Devices which lead me to simply go with the automatic installation guide from Junegunn Choi here.
So, I’m set up in Vim
, feeling smooth but still don’t know how to use tabs
, filetree
or everything else beyond basic commands.