TODO

:h caddexpr (:h cad) (write into quickfix) :help curly-braces-names :ilist or [I :colder :cnewer vim setreg() (google keep) ctrl-e and ctrl-y alternative buffer (#) [count]:command :e # reopen closed buffer


!Important!

Tricks

highlight word under cursor

/\k*\%#\k*

How to search for a URL without backslashing

use backwards search ? skip the escaping, isn't it clever?! ?http://www.vim.org/

change above into:

Use Vim's spell check feature to split this sentence into words using spaces.
 Vim: set spell:
	- my solution (30)      : 3fsi <ESC>2;2h.3;.fu.5@='1z=[s'<CR>ZZ
	- amazing solution (18) : A[sE<C-V>dgvpP@.<Esc>U@.ZZ

reverse text

separate letters

change abcde into -a-b-c-d-e-  
:s/\_A*/-/g

using \A* won't add the - to the end. 

scrolling jump

	set sj to set the scrolling jump manner. :h 'sj'

"= register

:h "= for details

change:

- One number per line -
-----------------------
2,3,5,7,
11,13,17,
19,23,29,

into:

2
3
5
7
11
13
17
19
23
29

this will do it: 5gJV"=[<C-R><C-A>]<CR>pZZ

regex

handle search result

!Important! ends


Settings

Windows

Normal mode

Delete

Motion

Format

Insert mode

Command mode

Commands

- :scriptnames : show loaded plugin - :g/foo/y A : copy all matched line to "a"

Execute and normal!

useful atoms for matching

Search and Regex

Search

Patterns

Visual area/block

:h \%V could be used for :s for example, only replace pattern in visual selected area. for example: :s /\%Vfoo\%V/bar/g

lines

columns

\%23c Matches in a specific column. \%<23c Matches before a specific column. \%>23c Matches after a specific column.

substitution trick

Do something like sed/awk's /pattern1/,/pattern2/ s/foo/bar/

1
2
3
g/pattern1/.,/pattern2/s/foo/bar/g
 
.,/pattern2/ is a range, from current line to the next /pattern2/ matching line

Char to Hex

Encode all non-ascii characters into Hex

1
%s/[^\x00-\x7f]/\=printf('\x%x',char2nr(submatch(0)))/g

Regex

character class

NOTE: Using the atom is faster than the [] form.

some special character class

useful for highlighting

Ordinary atoms

Other Patterns

Handle search result (by / or ?)

Copy/Move lines

:copy or :t :move or :m

some hints

Examples

replace t with m will do move

script

get character under cursor

1
matchstr(getline('.'), '\%' . col('.') . 'c.')

get visual selection

1
2
3
4
5
6
7
8
function! s:get_visual_selection()
    let [lnum1, col1] = getpos("'<")[1:2]
    let [lnum2, col2] = getpos("'>")[1:2]
    let lines = getline(lnum1, lnum2)
    let lines[-1] = lines[-1][: col2 - 2]
    let lines[0] = lines[0][col1 - 1:]
    return join(lines, "\n")
endfunction

or use a register:

1
2
3
4
5
6
7
8
9
10
function! GetVisual()
  try
    let a_save = @a
    normal! gv"ay
    return @a
  finally
    let @a = a_save
  endtry
endfunction
  

Misc Tips

convert escaped codevalue to unicode character

http://stackoverflow.com/questions/21076598/convert-escaped-codepoint-to-unicode-character/21076866#21076866

s#\\u[0-9a-f]*#\=eval('"'.submatch(0).'"')#
or
s#\v\\u([0-9a-f]{4})#\=nr2char(str2nr(submatch(1),16))#

color hi

Mapping

About !

silent

<<Back