Optimize Your Vim Statusline

Intro

Constantly asking Vim which file you are editing is disruptive to your workflow.

Especially after the 20th time of asking..😵‍💫

Here’s a great way to have Vim always tell you which file you are in; instead of stopping to ask.

Vim Options

Here are the commands to change and reset the defaults for laststatus and statusline from Command-line Mode, respectively:

# change the defaults
:set laststatus=2
:set statusline=buf\ %n:\ %F\ %m%r\ %=%l,%c\ \ \ \ \ \ \ \ %p%%

# reset to defaults
:set statusline= laststatus=1

#view buffer list
:ls

Here’s how to view the filename and buffer number from Normal Mode:

# view file name: control-g
^g

# view file name AND buffer number: 2 control-g
2 ^g

**Remember, you have to exit Insert Mode and go into Normal Mode first, with the Esc key

How To Create SSH Keys For Authentication

Overview

Creating and using SSH keys for authentication requires 3 minimum steps

  1. Generate Your Public-Private Key Pair
  2. Transfer Your Public Key To The Remote Host(s)
  3. Test Your Private Key

Commands To Run:

ssh-keygen
ssh-copy-id -i ~/.ssh/id_rsa.pub user1@remotehost
ssh user1@remotehost

Demonstration

Here’s my YouTube short explaining this process:

And here’s a long form video demonstrating this process:

TBA

Extra Information

  • SSH key authentication uses asymmetric encryption:
    • Public Key encrypts
    • Private Key decrypts
  • Your Public Key is safe to give to anyone, anywhere. Hence it’s name.
  • Your Private Key must be safeguarded.
    • If any copies exist, assume your identity is compromised and refresh your key pair.

Git Range Notation “..”

Here’s how NOT to read the following: 

git log master..origin/master

“Show me all commits from branch ‘master’ to branch ‘origin/master’ that are reachable”

Here’s the CORRECT WAY to read it:

“Show me all commits from branch ‘master’ to branch ‘origin/master’ that are UNREACHABLE”

That command will tell you what – if any – commits you WOULD merge in if you ran:

git checkout master
git merge origin/master

If you’re a Linux SYSADMIN and want to get started with Git,

Here’s my in progress Git playlist:

Edit Multiple Files in VIM – Part 2

Notes from video:

# Notes for my YouTube video:
# https://youtu.be/o6cZ8fFBj-M


###################
#
# Command-Line Mode
#
###################

##
:split 
:split [FILENAME]
:vertical split 
:vertical split [FILENAME]

##
# Close window with cursor
:close

##
# override all warnings with "!"
# and hide buffer
:close! 

##
# close all windows AND 
# exit the Vim program
:quitall

##
# override warning with "!"
# and discad ALL changes THEN
# exit Vim program
:quitall! 



##############
#
# Normal Mode
#
##############

##
# increase window width
^w >
[NUMBER] ^w >

##
# decrease window width
^w <
[NUMBER] ^w <

##
# increase window height
^w +
[NUMBER] ^w +

##
# decrease window height
^w -
[NUMBER] ^w -

##
# set all windows equal
^w =

##
# rotate windows
^w r

##
# move cursor in a 
# particular direction 
^w [ARROW KEY]

You can also get the most current version of the above via git:

git clone https://gist.github.com/3d380d4bbd54c0c36d144ededb7c3591.git vimBuffers2
cd vimBuffers2

Edit Multiple Files in VIM

Notes from video:

#
# Notes for my YouTube video => https://youtu.be/XTgNXp8PD3c
#

# Display Buffer List
:buffers
:ls

# open and edit another file w/in VIM
# AND append [FILENAME] to Buffer List
:edit [FILENAME] 

# Add [FILENAME] to the Buffer List from w/ in 
# a modified buffer
:badd [FILENAME]

# Navigating the buffer list
:bprevious
:bnext
:buffer [NUM] # jump directly to Buffer number [NUM]
:buffer! [NUM] # override warning and hide buffer

:pwd  # P(rint) W(orking) D(irectory)


# While in Normal Mode (aka Command Mode)
# Press "2", then "Control-g"
2 + Ctrl-g  
# Hit "Escape" key to enter Normal Mode

# Display Argument List
:args

# Navigate Argument List
:previous
:next

# Miscellaneous
:quit
:quit!
:write

You can also get the most current version of the above via git:

git clone https://gist.github.com/ec9f971671b0a493b9bbc4a92e7fdeb1.git vimBuffers
cd vimBuffers

How To Learn (Linux) Better 🧠

The best way to learn new information is to make it useful.

UTILITY is key! 🔑

For example, VIM has a lot of commands for splitting windows, creating tabs, managing buffers, etc.

I struggle to “make this, make sense”.

===

Finally ☝️, once I installed a VIM plugin for git – fugitive – all the shortcuts, commands, and concepts in VIM really came alive and had actual meaning.

Trying to learn a new feature in VIM, TMUX, etc…

Make it useful 😃