Pages

Hotkeys and configs for bash, mc, vi, tmux, SecureCRT

SecureCRT terminal setting (router, switch - green text, servers - white text)
SecureCRT terminal settings


1) Vi editor - must-known editor
2) Tmux - terminal multiplexer
3) Bash - is a Unix shell
4) mc - Midnight Commander

1) vi (visual editor)
:wq     save and quit
:w        write (save) to the file file.
:q!        quit wothout save
[Esc]    Exit editing mode. Keyboard keys now interpreted as commands.
i        insert mode, (ESC to exit insert mode) allows text to be entered on the screen
/word    Move to the occurrence of "word"
dd        delete line
G        go to the last line in the file.


2) tmux (screen alternative)
Managing tmux sessions:
$ tmux       # start tmux server (new instance)
$ tmux a    # attach running sessions to a terminal
Session management 
( list running tmux sessions )
$ tmux ls  
$ tmux ls
4: 1 windows (created Sun Nov 27 15:37:58 2011) [147x55]
6: 2 windows (created Tue Dec  6 18:45:27 2011) [147x55]
$ tmux a -t 6
Each session can contain many windows.

Windows Management
NOTE: All commands need to be prefixed with the action key. By default, this is CTRL-b
^b  c  - create new window
^b  d  - detach (Kill session if no more windows are present)
^b s   - list sessions
^b w  - list windows
^b n/l - next/last window
^b ,   - rename window
^b  ?   - help
Windows Splitting
^b  %  - split window, adding a vertical pane to the right
^b " "  (space) - horizontal split is not bound to a key
^b ↑,↓, →, - switch to panel UP, DOWN, LEFT, RIGHT
Here is a list of a few basic tmux commands, http://lukaszwrobel.pl/blog/tmux-tutorial-split-terminal-windows-easily
Ctrl+b " - split pane horizontally.
Ctrl+b % - split pane vertically.
Ctrl+b arrow key - switch pane.
Hold Ctrl+b, don't release it and hold one of the arrow keys - resize pane.
Ctrl+b c - (c)reate a new window.
Ctrl+b n - move to the (n)ext window.
Ctrl+b p - move to the (p)revious window.

Advanced
 [  - enter copy mode (then use emacs select/yank keys)
      * press CTRL-SPACE or CTRL-@ to start selecting text
      * move cursor to end of desired text
      * press ALT-w to copy selected text
 ]  - paste copied text
Rebinding
~/.tmux.conf create if not exist
unbind C-b
set -g prefix C-a
Restart all tmux sessions. 


3) bash
CSH is default shell under FreeBSD.
a) Install BASH statictly (installed in /bin, or to be more exact in mount point / ).
# make -C /usr/ports/shells/bash -D WITH_STATIC_BASH -DWITHOUT_NLS PREFIX=/ config-recursive install clean
OR
# /usr/ports/shells/bash-static
# make install clean
b) Change shell
# chsh -s /bin/bash jfoo       # Change shell for user jfoo
# chsh -s /bin/bash            # Change shell for user root
c) Install cutomized aliases
Bash config file is located in ~/.bash_profile (is executed for login shells)

Download and install

# cd ~ ; wget goo.gl/scvSW -O ~/.bash_profile  ;   source ~/.bash_profile
File .bash_profile
#  .bashrc config file v.03 @ 3 august 2012
#   source ~/.bash_profile
# increase history size
# Expand the history size
export HISTSIZE=100500
export HISTTIMEFORMAT='%F %T '
export HISTCONTROL=ignoredups
export HISTIGNORE="&:ls:[bf]g:exit:[ ]*:ssh:history"
alias update=/etc/periodic/weekly/310.locate
alias ports="portsnap fetch update"
alias psx="ps -auxww | grep $1"
alias pst='dtpstree -tp'
alias du='du -h -d 1'       # Makes a more readable output.
alias df='echo -e;mount; echo -e;df -h'
alias ll="ls -l"
alias lo="ls -o"
alias lh="ls -lh"
alias la="ls -la"
alias sl="ls"
alias l="ls"
alias s="ls"
alias ntp="ntpdate 2.md.pool.ntp.org"
alias su='su -'
alias grep="egrep"
alias rm='rm -i'
alias m='more'
alias gr='grep -v grep | grep -i'
alias gre='grep -v grep | grep -i'
alias grep='grep -v grep | grep -i'
alias gerp='grep -v grep | grep -i'
alias i='grep -v grep | grep -i'
alias inc='grep -v grep | grep -i'
alias include='grep -v grep | grep -i'
alias mtop='mtop --dbuser=root'
alias mic='make config-recursive install clean'
alias mdc='make deinstall clean'
alias w='w -n'
alias ifstat='ifstat -t'
#-------------------------------------------------------------
# spelling typos - highly personnal and keyboard-dependent :-)
#-------------------------------------------------------------
alias xs='cd'
alias vf='cd'
alias moer='more'
alias moew='more'
alias kk='ll'
# ports: pstree
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
#
#  export PS1='[`date +%d""%h""%Y"/"%T `] \u@\h \w \$ '
#  [03Aug2012/15:20:45] test@hostname /www $
export PS1='[`date +%d""%h""%Y"/"%T `] \u@\h \w \$ '
Bash Info:
# Run tasks in the background
#  bash lets you runone or more tasks in the background,
#  and selectively suspend or resume any of the current tasks (or "jobs").
# To run a task in the background, addan ampersand (&) to the end of its command line. Here's an example:
#     bash> tail -f /var/log/messages &
#     [1] 614

#  Each task back-grounded in this manner in assigned a job ID, which is printed to theconsole.
#  A task can be brought back to the foreground with the command fgjob number,
#  where jobnumber is the job IDof the task you wish to bring to the foreground.
#  Here's an example:   bash> fg 1

#  Alist of active jobs can be obtained at any time by typing
#  $jobs

# Moving the cursor:
#   Ctrl + a   Go to the beginning of the line (Home)
#   Ctrl + e   Go to the End of the line (End)
#   Ctrl + p   Previous command (Up arrow)
#   Ctrl + n   Next command (Down arrow)
#   Alt + b    Back one word
#   Alt + f    Forward one word
#   TAB        Tab completion for file/directory names

# Editing:
#  Ctrl + L   Clear the Screen, similar to the clear command
#  Ctrl + U   Cut/delete the line before the cursor position.
#  Ctrl + H   Backspace
#  Alt + Del  Cut the Word before the cursor.
#  Alt + d    Cut the Word after the cursor.
#  Ctrl + W   Cut the Word before the cursor to the clipboard.
#  Ctrl + K   Cut the Line after the cursor to the clipboard.
#  Ctrl + T   Swap the last two characters before the cursor.
#  Esc  + T   Swap the last two words before the cursor.
#  ctrl + y   Paste the last thing to be cut (yank)
#  Alt + u    Capitalize every character from the cursor to the end of the current word.
#  Alt + l    Lower the case of every character from the cursor to the end of the current word.
#  Alt + c    Capitalize the character under the cursor and move to the end of the word.
#  Alt + r    Cancel the changes and put back the line as it was in the history (revert).
#  ctrl + _   Undo

# Process control:
#  Ctrl + C   Interrupt/Kill whatever you are running (SIGINT)
#  Ctrl + D   Send an EOF marker, unless disabled by an option, this will close the current shell (EXIT)
#  Ctrl + Z   Send the signal SIGTSTP to the current task, which suspends it.
#                 To return to it later enter fg 'process name' (foreground).

4) mc - midnight commander

Start / Version

# mc
# mc -a     [Note: If display lines are not drawn properly, use -a]
# mc -c     [Note: Option -c will display mc in color]
# mc -V

Function Keys
F1        Help
F2        User Menu (compress/copy to a remote server with a single click).
            F9 -> Command -> Edit Menu File - to cutomize.
F3        View the selected file using mcview (MC viewer)
F4        Edit the selected file using mcedit (MC editor)
F5        Copy
F6        Rename/Move
F7        Mkdir
F8        Delete file/dir
F9        MC Menu at the top of the screen.
F10        Quit MC

Common Functions

*            Select all files only
+            Select group (regexp)
+, *        Select all files and folder with * regexp
\            Unselect group (regexp)
Esc + .        Show/hidde hidden files and directories (that starts with '.').

Ctrl+x,j    Show background jobs
Ctrl + Space Directory size

Ctrl + r    Refresh or rescan directory view
Ctrl + l    Redraw MC

Ctrl-x d    Compare directories

Ctrl+x,i    Set the other panel display mode to information
Ctrl+x,q    Set the other panel display mode to quick preview (ie Text)

Ctrl-x c (o,s,l) - chmod (chown, symlink, link)
Ctrl-x a    Open VFS list (Virt File Syst - MC will interpret all of the path names (local,tar, ftp, rsh) used and will forward them to the correct file system)

Panel Functions
TAB            Switch between left and right panel, moves sequentially through fields of selection boxes
Insert        Select or unselect multiple file(s)
SpaceBar    Toggle tick boxes on or off
Esc+Shift+?    Opens search dialog (Find File)
Ctrl + s    Incremental search (First letter)
Esc + t        Change panel view ('Full','Brief','Long')
Esc + i        Make both panel with the same path (from active panel)
Ctrl + \    Directory hotlist

Command Line Functions
Shift + LMouse Select      Copy to buffer
Shift + Ins             Paste from buffer

Esc + TAB    Autocomplete
Ctrl + o    Subshell switch
Esc + Enter    Insert 'current object' to command line.
Esc + a        Insert PATH in command line of active panel.

Esc + h        Displays command line  history
Esc + p/n    Browse through the command history (p-back/n-forth)

Esc + H        Shows PATHS history
Esc + y/u    Browse through the PATHS history (y-back/u-forth)

MC Editor
F3            Начать выделение текста. Повторное нажатие F3 закончит выделение
Shift+F3    Начать выделение блока текста. Повторное нажатие F3 закончит выделение
F5            Скопировать выделенный текст
F6            Переместить выделенный текст
F8            Удалить выделенный текст
Esc+i        Переключение режима "Автовыравнивание возвратом каретки", удобно при вставке отформатированного текста из буфера обмена
Esc+l        Переход к строке по её номеру
Esc+q        Вставка литерала (непечатного символа).См. таблицу ниже
Esc+t        Сортировка строк выделенного текста
Esc+u        Выполнить внешнюю команду и вставить в позицию под курсором её вывод
Ctrl+f        Занести выделенный фрагмент во внутренний буфер обмена mc (записать во внешний файл)
Ctrl+k        Удалить часть строки до конца строки
Ctrl+n        Создать новый файл
Ctrl+s        Включить или выключить подсветку синтаксиса
Ctrl+t        Выбрать кодировку текста
Ctrl+u        Отменить действия
Ctrl+x        Перейти в конец следующего
Ctrl+y        Удалить строку
Ctrl+z        Перейти на начало предыдущего слова
Shift+F5    Вставка текста из внутреннего буфера обмена mc (прочитать внешний файл)
Esc+Enter    Диалог перехода к определению функции
Esc+-        Возврат после перехода к определению функции
Esc++        Переход вперед к определению функции
Esc+n        Включение/отключение отображения номеров строк
Tab            Отодвигает вправо выделенный текст, если выключена опция "Постоянные блоки"
Esc-tab    Отодвигает влево выделенный текст, если выключена опция "Постоянные блоки"
Shift+Стрелки    Выделение текста
Esc+Стрелки    Выделение вертикального блока
Esc+Shift+-    Переключение режима отображения табуляций и пробелов
Esc+Shift++    Переключение режима "Автовыравнивание возвратом каретки"