Vi,VIM and tmux

Still under construction

VIM

Vim Tips
Vim tips and tricks
Vim Windows

Command line edit with Vi

Make sure vi is your default editor with export EDITOR=vi
Set vi for comamand line with set -o vi

With Esc+v, vi will open. Anything in the prompt will be ‘pasted’.

Use :cq to exit vi without running the current text. Otherwise will be executed.

Runing your script/program (runing the buffer…)

:!python % (where % is subtituted by the edited file)
:w | !python % This saves the file first…
:w !python Writes to STDOUT, where we run python…
:w !bash … or bash.

Here, a very deep explanation.

Some configuration
set nocp              When invoked as "vi", vim starts in "old vi" comptible mode (withput new functionality)
set [list|nolist]     Shows|hidde non-printable and hidden characters:w

Ctrl+g   Shows filename, current line number, total lines in file, and % of file location
:.=      Shows current line number
:=       Shown total number of lines
Text selection: markers…

You can get your current marks with command marks

m + a        sets a mark, named 4, in cursor position
' + a        goes to mark 'a'
d + ' + a    deletes from cursos to mark 'a'
y + ' + a    yanks from cursor to mark 'a'
Text selection: Going visual…

Text selection can be done visually:

‘v’ for character mode selection
‘V’ for line mode selection
‘Ctrl-v’ blok mode selection

Once selected, usual commands do work: ’d’, ‘y’, etc

Also, when going to the command line (’:‘), begining of block mark (“>’) and end of block mark (”>‘) will be set for you, so only replace expression has to be build.

:'<,'>s/toreplace/newstr/g

Text indentation

To indent the current line, or a visual block:

ctrl-t, ctrl-d - indent current line forward, backwards (insert mode)
visual > or < - indent block by sw (repeat with . )

Working with windows

You can open multiple files, one window per file, with vim -o <files> (horizontal windows) or vim -O <files> (vertial windows)

Also, when inside vim, :split <file> and vsplit <file> opens <file> in a new window.

Ctrl+w goes to the windows following arrow direction

Vim and tmux play very well toghether

https://www.hamvocke.com/blog/a-quick-and-easy-guide-to-tmux/
https://robots.thoughtbot.com/a-tmux-crash-course