Vim

Vim is like the most powerful tool on the market for fast text editing. There are also some not mentioned below, I will add over time. I started using Vim because of George Hotz’s livestreams.

Shift + J to move the line up

Command + Shift + { / }to switch between tabs really quickly.

New thing: Use vim marks! https://vim.fandom.com/wiki/Using_marks

Resources

Cheatsheets

To learn:

Multiline number increment:

  • Visual block mode (select all the ones), then g + ctrl + A

Search and replace

I learned to pipe through the command line, i.e.

pip3 list | vim - 

See more about pipes in bash.

Mouse mode with vim??

set mouse=a

Combos (i is inner and a is outer) vi{ ci{ di{ same with va{

Key ideas:

  • when you capitalize, it is to go backwards

I need to master Regex, it is super useful.

Use of | (“or”) to delete all lines except those that contain “error” or “warn” or “fail” (:help pattern): :v/error|warn|fail/d

Visual Block Mode:

  • There are multiple things

g + ctrl A for multline increase

Movement

Basics that I have mastered h - Move left j - Move down k - Move up l - Move right w - Move forward to next word, with cursor on first character W - Move forward to next word, by whitespace only b - Move backward to next word, with cursor on first character B - Move background to next word to by whitespace only

$ - Move to end of line 0 - Move to beginning of line (including whitespace) ^ - Move to first character on line#to-use

gg - Move to first line of file G - Move to last line of file

e - Move forward to next word, with cursor on last character (use E - Jump by whitespace only ge - Move backwards to next word, with cursor on last character gE - jump by whitespace only ( - Move to beginning of previous sentence. Use ) to go to next sentence { - Move to beginning of previous paragraph. Use } to go to next paragraph + - Move forward to the first character on the next line - - Move backwards to the first character on the previous line

TO MASTER THESE CTRL+O - Go back to last cursor position, after you have made a jump CTRL+u - Move up by half a page#to-use CTRL+d - Move down by half a page CTRL+b - Move up by a page CTRL+f - Move down by a page

H - Move cursor to header (top) line of current visible window M - Move cursor to middle line of current visible window L - Move cursor to last line of current visible window

Horizontal Speed Search (AMAZING) fc - Move cursor on top of the next character c on the current line. Use Fc to move backwards tc - Move cursor right before the next character c on the current line. Use Tc to move backwards (Idk why this would be useful.. um YES) ; - walk to the next character, basically reapply fc , - walk backgrounds, opposite of ;

Screen Movement % - Move cursor to next brace, bracket or comment paired to the current cursor location

z. - Center the the screen on the cursor zt - Scroll the screen so the cursor is at the top zb - Scroll the screen so the cursor is at the bottom

Search#to-use

* - Search forward for word under cursor(SUPER USEFUL) # - Search backwards for word under cursor

/word - Search forward for word. Accepts regular expressions to search ?word - Search backwards for word. Accepts regular expressions to search n - Repeat the last / or ? command N - Repeat the last / or ? command in the opposite direction

If you word to search for a visually selected word, you can yank it using y.

Then

  • /
  • Ctrl + r
  • "

Which will paste what you have yanked after the /.

Normal Mode Insert Mode

I mastered this already i - Enter insert mode to the left of the cursor a - Enter insert mode to the right of the cursor o - Insert line below current line and enter insert mode O - Insert line above current line and enter insert mode

TO USE MORE I - Enter insert mode at first character of current line A - Enter insert mode at last character of current line

cm - Delete (change) the character or word (w) in motion m, then enter insert mode ci[ - Change inner of the brackets and go into insert mode cc - Delete current line and enter insert mode (unlike dd which leaves you in normal mode) C - Delete (change) from cursor to end of line, and enter insert mode

s - Delete character under cursor, then switch to insert mode

Deletion

x - Delete character forward (under cursor). use x do delete backwards (before cursor) r - Replace single character under cursor, and remain in normal mode

dm - Delete in direction of movement m. For m, you can also use w, b, or any other variation (TO MASTER, YOU CAN COMBO) dd - Delete entire current line D - Delete until end of line

YANK & PUT

y - Copy highlighted text yy - Copy current line#to-use yw - Yank a word from the cursor ynw - Yank n words from the cursor y$ - Yank till the end of the line p - Put yanked text below current line P - Put yanked text above current line J - Join current line with the next line. Use gJ to exclude join-position space xp - Transpose two letters (delete and paste, technically)

VISUAL MODE

v - Enter visual mode and highlight characters V - Enter visual mode and highlight lines CTRL+v - Enter visual block mode and highlight exactly where the cursor moves o - Switch cursor from first & last character of highlighted block while in visual mode ~ - Swap case under selection << - Shift lines to left >> - Shift lines to right

Instead of va(, you can do vab va{ awesome combo, outer stuff vi{ awesome combo, inner stuff vai vat - Highlight all text up to and including the parent element vit - Highlight all text up to the parent element, excluding the element vac - Highlight all text including the pair marked with c (like va<, va’ or va”) vic - Highlight all text inside the pair marked with c

MARKING

ma        -   Set a marker a at cursor position to come back to later. a can be any character you choose
mb        -   Set a marker b at current position
`a        -   Move cursor to exact position of the marker you set with ma
'a        -   Move cursor to the first character of the line marked with ma

d'a       -   Delete from current line to line of mark a
d`a       -   Delete from current cursor position to position of mark a
c'a       -   Change text from current line to line of mark a
y`a       -   Yank text to unnamed buffer from cursor to position of mark a

:marks 	  -   List all the current marks
:marks ab -   List marks a, b

'a,'bs/test/foo/g - Search and replace test with foo between markers a and b

VIM FOLDING

zf#j      -   creates a fold from the cursor down # lines.
zf/string -   creates a fold from the cursor to string .
v{move}zf -   creates a visual select fold
zf'a      -   creates a fold from cursor to mark a

zo        -   opens a fold at the cursor.
zO        -   opens all folds at the cursor.
za        -   Toggles a fold at the cursor.
zc        -   closes a fold at the cursor.
zM        -   closes all open folds.
zd        -   deletes the fold at the cursor.
zE        -   deletes all folds.

zj        -   moves the cursor to the next fold.
zk        -   moves the cursor to the previous fold.
zm        -   increases the foldlevel by one.
zr        -   decreases the foldlevel by one.
zR        -   decreases the foldlevel to zero -- all folds will be open.
[z        -   move to start of open fold.
]z        -   move to end of open fold.

MISCELLANEOUS

u        -   Undo
U        -   Undo all changes on current line
CTRL+R   -   Redo
.        -   Redo

g~       -   switch case under cursor
g~$      -   Toggle case of all characters to end of line.
g~~      -   Toggle case of the current line (same as V~).
gUU      -   switch the current line to upper case
guu      -   switch the current line to lower case

CTRL+A   -   Increment the number at cursor
CTRL+X   -   Decrement the number at cursor

.        -   Repeat last change or delete
;        -   Repeat last f, t, F, or T command
,        -   Repeat last f, t, F, or T command in opposite direction

vim +10 <file_name>            - opens the file at line 10
vim +/bash cronjob-lab.yml     - opens the file cronjob-lab.yml on the first occurence of bash

vim scp://balasundaramm@mgmt-bst:22/~/automation/test-file.txt - Edit a remote file via scp

HISTORY/COMMAND BUFFER

q:              -   list history in command buffer
q/              -   search history in command buffer
CTRL+c CTRL+c   -   close the command buffer

:set list       -   show hidden characters

gg=G            -   Format HTML. Make sure FileType is set to html with :setf html
CTRL+n          -   Press after typing part of a word. It scrolls down the list of all previously used words
CTRL+p          -   Press after typing part of a word. It scrolls up the list of all previously used words

BUFFERS

:ls (or :buffers)   -   list / show available buffers
:e filename         -   Edit a file in a new buffer
:bnext (or :bn)     -   go to next buffer
:bprev (of :bp)     -   go to previous buffer
:bdelete (or :bd)   -   unload a buffer (close a file)
:bwipeout (or :bw)  -   unload a buffer and deletes it
:b [N]              -   The number of the buffer you are interested to open
:ball               -   opens up all available buffers in horizontal split window
:vertical ball      -   opens up all available buffero in vertical split window
:q                  -   close the buffer window
:help buffers       -   help for buffers
:r <file_path>      -   reads a file from the path to the buffer
:r !<command>       -   reads the output of the command into buffer
:.! cat <file_path> -   reads the output of the command (eg: cat) into buffer or !! in ex-mode

TAB VIEWS

:tabe filename      -   opens the file in newtab
:tabe new           -   open an empty tab
:tabs               -   list opened tabs
:tabc               -   close the active tab
:tabn and tabp      -   Go to next tab or previous tab
:tabfirst           -   Go to the first available tab
:tablast            -   Go to the last available tab
:help tabpage       -   help for tabs

vim -p *.txt        -   open all txt files in tabs

TAB NAVIGATION

gt                  -   go to next tab
gT                  -   go to previous tab
{i}gt               -   go to tab in position i

TAB SHORTCUTS

CTRL+W T            -   Break out current window into a new tabview
CTRL+W o            -   Close every window in the current tabview but the current one
CTRL+W n            -   create a new window in the current tabview
CTRL+W c            -   Close current window in the current tabview

WINDOW MANAGEMENT

#split screen horizontal
:split filename
vim -o file1 file2

#split screen vertical
:vs filename
or
:vsplit filename
vim -O file1 file2

#close current window
:hide

#Horizontal resize in active window
:resize 20

#vertical resize
:vertical resize 20

#diff
:windo diffthis -  diff between 2 vsplit windows
:diffs, diffsplit {filename} - diffs the current window with the file given
:diffoff  - turns off diff selection


CTRL+w s       -   Split current window horizontally
CTRL+w v       -   Split current window vertically
CTRL+w c       -   Close current window
CTRL+w m       -   Move to window according to motion m
CTRL+w o       -   Maxmize current window (note: this overwrites your current window configuration)

# EX Mode
:Vex           - Open Vertical Split in ex mode with file browser
:Sex           - Open Vertical Split in ex mode with file browser

MOVING WINDOWS

CTRL+W r       -   Swap bottom/top if split horizontally
CTRL+W R       -   Swap top/bottom if split horizontally

CTRL+w r       -   Rotates the windows from left to right - only if the windows are split vertically
CTRL+w R       -   Rotates the windows from right to left - only if the windows are split vertically

CTRL+w H       -   Move current window the far left and use the full height of the screen
CTRL+w J       -   Move current window the far bottom and use the full width of the screen
CTRL+w K       -   Move current window the far top and full width of the screen
CTRL+w L       -   Move current window the far right and full height of the screen
CTRL+w CTRL+w  -   switch between windows
CTRL+w UP      -   Move to the top window from current window
CTRL+w DOWN    -   Move to the bottom window from current window
CTRL+w LEFT    -   Move to the left window from current window
CTRL+w RIGHT   -   Move to the right window from current window

RESIZING WINDOWS

#Sometimes windows open up funny or are rendered incorrectly after separating from an external monitor. Or maybe you want to make more room for an important file.

CTRL+w _       -   Max out the height of the current split
CTRL+w |       -   Max out the width of the current split
CTRL+w =       -   Normalize all split sizes, which is very handy when resizing terminal

CTRL+w >       -   Incrementally increase the window to the right. Takes a parameter, e.g. CTRL-w 20 >
CTRL+w <       -   Incrementally increase the window to the left. Takes a parameter, e.g. CTRL-w 20 <
CTRL+w -       -   Incrementally decrease the window's height. Takes a parameter, e.g. CTRL-w 10 -
CTRL+w +       -   Incrementally increase the window's height. Takes a parameter, e.g. CTRL-w 10 +

COMMENT LINES (TCOMMENT PLUGIN)

CTRL+_ CTRL+_   -   Comment a line using tcomment
CTRL+V          -   #{Select the block before commenting a block,
CTRL+_ CTRL+_   -   Comment a block of line using tcomment}

MODELINE MAGIC

:set modeline  -    Enable modeline magic or add this option to your .vimrc
\ml            -    write the modeline based on your settings to the file

NERDTree Plugin

CTRL-n              -   Toggle

m                   -   opens the  menu
?                   -   help
i                   -   horizontal split
s                   -   vertical split
CTRL-w + <-|->      -  (left or right) to navigate

PERMISSION OVERRIDE

:w !sudo tee %            -    Allows to override the permission of the written file
:w !sudo sh -c "cat > %"  -             "                            "

VimBeGood Docker command

docker run -it --rm brandoncc/vim-be-good:stable