Thursday, November 20, 2014

Using VIM

Getting some time for myself, I decided to improve my professional skills by adding a new powerful tool: vi.
Having some trouble changing inside a quoted string with ci" (after some time i figure it out: it should be ci" and a space right after(for quotes)), I found this gem:

The operators that can be used are:
 ~ switch case     |v_~|
 d delete      |v_d|
 c change (4)     |v_c|
 y yank      |v_y|
 > shift right (4)     |v_>|
 < shift left (4)     |v_<|
 ! filter through external command (1)  |v_!|
 = filter through 'equalprg' option command (1) |v_=|
 gq format lines to 'textwidth' length (1)  |v_gq|

The objects that can be used are:
 aw a word (with white space)   |v_aw|
 iw inner word     |v_iw|
 aW a WORD (with white space)   |v_aW|
 iW inner WORD     |v_iW|
 as a sentence (with white space)   |v_as|
 is inner sentence     |v_is|
 ap a paragraph (with white space)   |v_ap|
 ip inner paragraph     |v_ip|
 ab a () block (with parenthesis)   |v_ab|
 ib inner () block     |v_ib|
 aB a {} block (with braces)   |v_aB|
 iB inner {} block     |v_iB|
 at a block (with tags)                  |v_at|
 it inner block                   |v_it|
 a< a <> block (with <>)    |v_a<|
 i< inner <> block     |v_i<|
 a[ a [] block (with [])    |v_a[|
 i[ inner [] block     |v_i[|
 a" a double quoted string (with quotes)  |v_aquote|
 i" inner double quoted string   |v_iquote|
 a' a single quoted string (with quotes)  |v_a'|
 i' inner simple quoted string   |v_i'|
 a` a string in backticks (with backticks)  |v_a`|
 i` inner string in backticks   |v_i`|
Additionally the following commands can be used:
 : start Ex command for highlighted lines (1) |v_:|
 r change (4)     |v_r|
 s change      |v_s|
 C change (2)(4)     |v_C|
 S change (2)     |v_S|
 R change (2)     |v_R|
 x delete      |v_x|
 D delete (3)     |v_D|
 X delete (2)     |v_X|
 Y yank (2)     |v_Y|
 p put      |v_p|
 J join (1)     |v_J|
 U make uppercase     |v_U|
 u make lowercase     |v_u|
 ^] find tag     |v_CTRL-]|
 I block insert     |v_b_I|
 A block append     |v_b_A|
Here is a list taken from stackoverflow lost somewhere in my browser history (thanks to the post author and to that great site build for knowledge):
select                                   v                                     
select row(s)                            SHIFT + v                             
select blocks (columns)                  CTRL  + v                             
indent selected text                     >                                     
unindent selected text                   <                                     
list buffers                             :ls                                   
open buffer                              :bN (N = buffer number)               
print                                    :hardcopy                             
open a file                              :e /path/to/file.txt                  
                                         :e C:\Path\To\File.txt                
sort selected rows                       :sort                                 
search for word under cursor             *                                     
open file under cursor                   gf                                    
  (absolute path or relative)                                                  
format selected code                     =                                     
select contents of entire file           ggVG                                  
convert selected text to uppercase       U                                     
convert selected text to lowercase       u                                     
invert case of selected text             ~                                     
convert tabs to spaces                   :retab                                
start recording a macro                  qX (X = key to assign macro to)       
stop recording a macro                   q                                       
playback macro                           @X (X = key macro was assigned to)    
replay previously played macro *         @@                                    
auto-complete a word you are typing **   CTRL + n                              
bookmark current place in file           mX (X = key to assign bookmark to)    
jump to bookmark                         `X (X = key bookmark was assigned to  
                                             ` = back tick/tilde key)          
show all bookmarks                       :marks                                
delete a bookmark                        :delm X (X = key bookmark to delete)   
delete all bookmarks                     :delm!                                 
split screen horizontally                :split                                
split screen vertically                  :vsplit                               
navigating split screens                 CTRL + w + j = move down a screen     
                                         CTRL + w + k = move up a screen       
                                         CTRL + w + h = move left a screen     
                                         CTRL + w + l = move right a screen    
close all other split screens            :only                                 

*  - As with other commands in vi, you can playback a macro any number of times.
     The following command would playback the macro assigned to the key `w' 100
     times: 100@w

** - Vim uses words that exist in your current buffer and any other buffer you 
     may have open for auto-complete suggestions.

1 comment:

jowdjbrown said...

Nice to read your article! I am looking forward to sharing your adventures and experiences.