AidanMontareDotNet

You are on the old part of aidanmontare.net, which I am no longer maintaining. Newer versions of some of this content can be found on the active part of my site, which you can reach from my homepage.

Text Editors

(last updated

Knowledge of a good command line text editor allows you to spend much more time in the terminal, and makes for easier system administration. Instead of using the default nano or something similar, try learning the basics of a more sophisticated editor. That way, when you desire a particular feature or shortcut, you won’t have to change editors.

Two of the most popular command line editors are Vim and Emacs. The fans of each of these rival editors have been at war for a long time, and loyalties to each side are often very strong (see the Wikipedia article). However, being a Notepad fan myself (its always fun when people who are not computer-savy hink Notepad means I am hacking something), I just want a good editor. Since everyone is different, here are some introductory resources to both editors. Try them each for a while and decide which one works best for you.

There are many references available for both of these text editors, so this is by no means a definitive guide. However, it may be useful to have some basic resources. Additionally, my tables of common keyboard shortcuts are a good quick reference that avoids having to search the manual for one command.

Vim

Vim, or Vi Improved, can be easily installed on most Linux distributions. For getting started in vim, simply install the vimtutor package and run vimtutor. This nice tutorial will teach you the basics of using Vim. However, there is much more you can do with Vim. Below are some of the commands I find most useful, as well as some tips on various topics.

Vim Basics

When you start Vim on the command line, or with the GVim GUI version, it starts in Normal mode. In Normal mode or command mode, keyboard combinations are mapped to various commands to interact with the file. One of these commands, i, enters Insert mode. Now most keyboard keys will enter characters as you would expect, though some keyboard combinations do other actions. ESC takes you back to Normal mode.

Moving the Cursor

w one word forward
b one word backward
e one word forward, moving at the end of the word
0 go to the first character in the current line
^ go to the first non-blank character in the current line
$ go to the last character in the current line

Scrolling

These commands scroll text, but do not move the cursor.

CTRL-E scroll window one line downward
CTRL-Y scroll window one line upward

Inserting and Appending

a start appending text after the cursor
A start appending text at the end of the line
o start inserting below the current line
O start inserting above the current line

Undo and Redo

u undo
CTRL-R redo

Copy and Paste

:req show all registers
p paste after the current position
P paste before current position
:pu paste text after current line
“+y copy text to the system clipboard (to put in other applications)
“+p paste text from the system clipboard

Interactions with Outside Vim

:!{command} run the {command} in a shell
:shell open a shell (exiting the shell will return to Vim with everything intact)
r [file] insert the contents of [file] at the cursor
:r! {command} insert the output of {command} at the cursor
:edit . open a directory listing in Vim
:Hexplore open a directory listing in a new window below the current window
:Sexplore open a directory listing in a new window above the current window

Multiple Windows

CTRL-W make current window smaller by one line
CTRL-W {arrow key} move to window in {arrow key} direction
CTRL-W s split current window horizontally
:vsplit split current window vertically
:res N set the current window height to N

Searching

* search for the word underneath the cursor

Getting Help

If you are ever in need of help while using Vim, simply typing :h in command mode will get you a very useful help browser.

:h open a help browser in a new window
CTRL-] jump to the link underneath the cursor

Spell Check

  • sudo apt-get install vim-scripts for a whole bunch of goodies, including vimspell, a spell checker
  • Read this guide to using spell check in vim.
  • Add set spell spelllang=en_us (or = your language) to load this all the time

VimOutliner

My introduction to VimOutliner started out as joke. I decided it would be fun to see if I could type notes using only a command line, and confuse my friends in the process. When I researched the topic, I found VimOutliner, an outliner plugin for Vim. In playing around with it, I found I actually quite enjoyed using, and now I often take notes in it.

Installing

On Debian-based systems its easy to install VimOutliner.

  • sudo apt-get install vim-vimoutliner
  • vim-addons install vimoutliner
  • Open your ~/.vimrc and add the following:
    filetype plugin indent on
    syntax on
    
  • start vim with any filename ending in .otl
  • :help vimoutliner to learn how to use it

Using

>> increase indent level by one
<< decrease indent level by one
,,w in insert mode, save and then come back to insert mode

Saving Vim Settings

You can save your Vim settings in a .vimrc file in your home directory. Here are the lines in my .vimrc file, along with explanations of what they do:

" General
set nobackup         " do not make backup files, as this can lead to security vulnerabilities when editing files on a public web server.

" Usability
set cursorline       " highlight the line the cursor is on
set cursorcolumn     " same with the current column
set showcmd          " show the incomplete command as you are typing it
set hlsearch         " highlight all instances of a search term once you search for it
set wrap             " wrap lines, this is useful for editing files with text in a paragraph form where each paragraph is a single line

" VimSpell
set spell spelllang=en_us

" things for VimOutliner
filetype plugin indent on
syntax on
nnoremap ,,cs A=strftime("    [Completed: %x]")        " maps ,,cs to insert a date stamp, usefull for adding a completed date to checklists made with VimOutliner

Update: comments in this file should be done with “, not #.

References

General Vim References

  • In Vim, type :h quickref. Thats where I learned alot of these commands, this list is merely a summary of the ones I find most useful.

Emacs

I have yet to actually learn Emacs, but when I do, I will list things here.