Mac Terminal commands and packages / addons - Do you use any?

Not weird at all – I use both Vim and Oh-My-Zsh and a lot of aliases. I like and use Emacs and BBEdit as well, but Vim is still more convenient for quick dotfile edits. (Yes I do know about emacsclient, but still prefer Vim for this.)

2 Likes

Another weirdo here. I write all my words in Vim. I love it. My terminal is set to vim mode.

2 Likes

as a newbie , what are the key differences between vim and nano?

I’d say the biggest difference is that vi[m] is a modal editor, while nano is not. “Modal” means you move between “normal” mode, in which you move, search, etc; and “insert” mode, in which you enter text. In nano you move using special key combinations and enter text without those special combinations.

I used vi, the predecessor of vim, for many years before switching to emacs for the majority of my text editing needs, although I use vim too, for much the same reasons as @brookter mentioned. I’ve only used nano a few times but it seems like a perfectly capable text editor.

2 Likes

Nano is an ordinary text editor based on the method you’ve seen a million times: you enter text with the keyboard, then you edit it using shortcuts involving a modifier key (cmd, opt, etc).

Vim is different, as @jec0047 says. It’s modal, which basically means that the processes of text entry (in ‘Insert’ mode) and text editing (in ‘Normal’ mode) are separate. (Actually there are more than 2 modes, but that’s just a detail.)

Most people’s reaction when they first come across this is to think ‘But why?’, and it is on the face of it, a bit odd. However, it’s this separation which makes Vim so powerful as a text editor.

You can think of it this way. You know those games you play with keyboard and mouse – each key represents a movement, or an action (“shoot”, “lower landing gear” and so on)?

Vim’s default ‘Normal’ mode is like that special keyboard layer. Every single key represents an action you can perform on the text. I’m sure you’re familiar with the notorious ‘hjkl’ for the arrow keys, but you also have ‘x’ which deletes a single character, ‘y’ copies (‘yanks’) the text, ‘p’ pastes it, ‘w’ moves forward a word, ‘b’ moves backwards a word and so on. And to enter into ‘Insert’ mode where you actually type the text, you press ‘i’. (Escape to exit back to ‘normal’ mode.)

So far, so simple, but the power comes when you combine these ‘action’ and ‘motion’ commands. For example, the commands:

  • y3wGp: copy the next three words to the end of the file

  • di"ggap: delete the words within these inverted commas (but not the inverted commas themselves) and paste them at the top of the file. If you wanted the inverted commas included, then just use ‘a’ (‘all’) instead of ‘i’ (‘inside’)

  • ~4fp: upper case from here to the fourth occurrence of the letter ‘p’ in this line.

In principle almost any command can be combined with an option number to act on any combination of words - this is extraordinarily powerful.

In other words, behind the strangeness, there’s a grammar and logic which means that once you’ve internalised the idea, you can manipulate any text very very quickly.

This isn’t to say that ‘normal’ editors aren’t capable of this level of manipulation – Emacs is the other obvious example, and professional packages such as BBEdit have text manipulation features which get close (and have other features which Vim doesn’t have). But Vim is outstanding at this, which is why many programmers still swear by it.

There is a steep learning curve, but once you grasp the basic commands and the concept of the ‘grammar’, then you can make a lot of progress quickly.

(Oh, by the way, you quit Vim by typing :q :slight_smile: )

HTH

10 Likes

really appreciate @brookter and @jec0047 for the informative explanation. As a non-code and newbie, I think I stick to nano , until I have grown up :joy:

1 Like

If you’re not programming, then there’s little point to learning Vim. Programmers spend most of their time editing, rather than inputting text, so they gain most from the additional text manipulation abilities. For most writers, the balance is different. Of course, if you’ve already learnt Vim, then it’s natural to use it for everything, but otherwise there are probably better choices. (Like Emacs… :slight_smile: )

Also note that BBEdit has a command line tool so that it can be called from the shell. I use BBEdit as my editor, and thus entering:

% bbedit filename

in the shell will open filename in BBEdit. Other editors may have similar shell integration, so you may be able to use an editor you are already familiar with. It is still useful to be familiar with a standard shell editor like nano for those cases where you are on a system that does not have your preferred editor.

Have fun!

1 Like

Power move! :rofl:

Being a professor and a lawyer (and occasional coder) who tried to learn Vim, I totally second that. Moves feel like magic, but I guess it’s not worth it to people who need to create long strings of non-code text (aka prose).

While VIM can write prose, it’s not the best tool for this job.

Tools like iA Writer, however, have a very interesting take on how to bring code editors features to prose writing (their Synthax highlight is a godsend!)

3 Likes

I don’t use vi(m) a lot, but I use it often, if that makes sense. If you’re going to do anything at all in the Unix-like world then it’s a good idea to know the basics because it’s going to be the one text editor that you are almost guaranteed to find installed, and it can be used over an ssh session. Managing a Unix-like system generally involves editing text files and often over ssh sessions.

I don’t find it a joy to use for day to day text editing or for writing code though.

I used vi (not vim) for decades. Got pretty good at it. (Macros are great once you master them and can spin one up on the fly.) It was the only editing tool I could count on when hopping on any server running a UNIX-type operating system. Even though I’ve been retired for a few years, my fingers still remember how to do it. :slightly_smiling_face:

5 Likes

You’re right: I was using ‘programming’ a little loosely, but meant sysadm stuff as well. When I first starting playing with Linux in the 90s (purely as a hobby), knowing vi was pretty much essential. I can’t remember if other editors were easily available at the time, but I don’t remember ever using them…

1 Like

My memory says every editor other than vi on UNIX-like boxes had to be installed, so I could not count on it being there.

1 Like

Nope! I need my terminal around all the time, no questions asked. I can’t be bothered with logging into a web service when I’ve got work to do.

Yes! Also, the bbdiff command is excellent for comparing two text files.

1 Like

Here’s my advice after using a terminal full time for 23 years.

  1. Keep it minimal
  2. Learn a few commands and dig deep into them. (grep, sed, awk)
  3. Learn the basics of Vim, but don’t bother living there.
  4. When using the Terminal becomes harder than a GUI, it’s not the right tool for the job anymore.

My prompt looks like this:
Buys Prompt

The relevant config:

  [ -n "$NNNLVL" ] && PS1="N$NNNLVL $PS1"

I’ve always used the plain Terminal.app shipped with the Mac. It’s fast, responsive, and does everything I need it to. I run zsh with the ohmyz.sh framework and two additions, zsh-autosuggestions and zsh-syntax-highlighting.

This setup lets me start typing a command and the shell will show me previous commands that match what I’ve typed so far. It also provides color-coding so I can tell at a glance if the command is correct or not.

I have a few aliases and a couple of functions, but nothing I can’t live without. My most used are:

alias oo='open .' # open current directory in OS X Finder
alias bb='bbedit .'

Overall my terminal setup allows me to work without getting in my way. The bare-bones layout shows me only the information I need, when I need it.

Oh, and don’t neglect learning your Terminal apps shortcuts. For example, ⇧⌘A will select the output of the previous command, and ⌘↑ and ⌘↓ jumps to the previous and next command, respectively.

9 Likes

Lots of interesting ideas there. Thanks.

1 Like

Also learning Python and every course I took used a different IDE. It was getting pretty confusing, so I figured I’d just learn vim and recreate as much as I could. Learning a lot of command line stuff this way, too. This thread has been very useful! Thanks to all who posted.

2 Likes

Just as a follow up to anyone interested in the sort of power Vim gives you, the following link is to a copy of a StackExchange answer that is often used to explain the ‘grammar’ of vi. It’s quite long, but I think it does illustrate the main idea nicely.

A word of caution – it’s not a tutorial! But it does a good job of explaining the logic: reading it for the first time years ago really helped me understand what was going on.

10 Likes

Thank you all for the massive amount of answers. I enjoyed this thread and I learned so much.
When I started I just used some simple commands but now I have tuned up my command line with ohmyzsh, I have autosuggestions and syntax highlighting.

I switched from Mac terminal.app to Kitty, I’m using ranger and ndcu instead of Finder and I am about to jump deep into the Neovim rabbit hole.
It is awesome and I’m impressed how much time it is saving me.
Especially Kitty was a game changer for me.

3 Likes