tricky

[!TIP|label:references:]

mode

diff mode

[!NOTE|label:references:]

terminal mode

[!NOTE|label:references:]

shortcuts

combine multiple lines with or without space

  • with space: J

  • without space: gJ or :j!

J-gJ

shortcut
comments

gcw

capitalize word (from cursor position to end of word)

gcW

capitalize WORD (from cursor position to end of WORD)

gciw

capitalize inner word (from start to end)

gciW

capitalize inner WORD (from start to end)

gcis

capitalize inner sentence

gc$

capitalize until end of line (from cursor postition)

gcgc

capitalize whole line (from start to end)

gcc

capitalize whole line

{Visual}gc

capitalize highlighted text

[!NOTE|label:references:]

  • lowercase

  • uppercase

  • reverse

  • more

    • g~3w : toggle case of the next three words

    • g~$ : toggle case to the end of line

    • g~iw : toggle case of the current word (inner word – cursor anywhere in word)

    • g~~ == g~g~ : toggle case of the current line (same as V~ - cursor anywhere in the line)

    • gUU == gUgU : to uppercase of the current line (same as V~ - cursor anywhere in the line)

    • guu == gugu : to lowercase of the current line (same as V~ - cursor anywhere in the line)

counter

[!NOTE|label:references]

vim calculator

insert vim expression

  • i/I/a/A/o/O to insert mode

  • ctrl + r + = to insert expression

  • ctrl + r> + " ( + v ) to insert the contents of the default register

  • enter

vim ctrl-r insert expression

batch insert vim expression

[!NOTE|label:references:]

  • or ~/.vimrc

g ctrl-g

commands

[!NOTE|label:references:]

vim-paste-command-output

[!NOTE|label:reference:]

CMD

ignorecase

smartcase

MATCHES

foo

off

-

foo

foo

on

-

foo Foo FOO

foo

on

on

foo Foo FOO

Foo

on

on

Foo

Foo

on

-

foo Foo FOO

\cfoo

-

-

foo Foo FOO

foo\C

-

-

foo

search-case-sensitive

search with \V

pattern
result

/a.k.a<CR>

backward a.k.a

/a\.k\.a<CR>

backward a.k.a

/Va.k.a<CR>

backward a.k.a

search in visual mode

[!NOTE]

  • v go to visual mode

  • /KEYWORDS search next KEYWORDS | ?KEYWORDS search previous KEYWORDS

  • enter

select until find

[!NOTE|label:references:]

  • sort

    sort lines
  • sort and unique

    sort lines

  • or

  • or and use: for f in GetFiletypes() | echo f | endfor

- [Vim documentation: pattern](http://vimdoc.sourceforge.net/htmldoc/pattern.html#/%5Cr) : - `\n` matches an end of line (newline) - `\r` matches a carriage return (more precisely it’s treated as the input `CR`))

redirect cmd

[!NOTE|label:references:]

redir to debug

insert hex code

METHOD
PROS
CONS

statusline %B

native support

only shows current cursor position

char2nr()

batch processing capability

requires manual handling of encoding ranges

:ascii

displays complete encoding info

requires parsing multi-line output

using :g /./ :ascii

get hex code of char

with function

[!NOTE|label:references:] performance:

SOLUTION
SPEED
PROS
CONS

:ascii

~1.2s

exactly matches the official format

slow

char2nr()

~0.03s

fast

requires custom format

hybrid

~0.5s

balancing speed and format

requires custom format

format json in vim

[!NOTE|label:references:]

multiple repalce in silent mode

related commands:

  • :argdo : all files in argument list

  • :bufdo : all buffers

  • :tabdo : all tabs

  • :windo : all windows

reference:

  • replace

  • force the bufdo to continue without saving files via :bufdo!

close buffer when close window

  • commands

  • autocmd

switch in buffers

  • next buffer: ctrl + ^

  • previous buffer: ctrl + 6

  • first: :1b<CR>

  • last: :$b<CR>

show ascii under cursor

[!NOTE|label:references:]

  • keyboard

    • ga

  • commands

ascii

open vim with specific line Number

[!NOTE|label:reference]

jumplist

[!TIP|label:tips:]

  • :help ''

  • `:help ```

encryption with Vim

  • encrypt

  • decrypt

open vim with specific commands

[!NOTE|label:references:]

  • using vim to format git commit message

config

get platform

[!NOTE|label:references:]

disable vim beep

pastetoggle

[!NOTE|label:references:]

run vim commands in terminal

[!NOTE|label:manual:]

  • additional highlight

reference:

overview of multi items

pattern
magic
nomagic
matches of the preceding atom

/star

*

\*

0 or more   (as many as possible)

/\+

\+

\+

1 or more   (as many as possible)

/\=

\=

\=

0 or 1   (as many as possible)

/\?

\?

\?

0 or 1   (as many as possible)

/\{

\{n,m}

\{n,m}

n to m   (as many as possible)

\{n}

\{n}

n   exactly

\{n,}

\{n,}

at least n   (as many as possible)

\{,m}

\{,m}

0 to m   (as many as possible)

\{}

\{}

0 or more   (as many as possible. same as *)

/\{-

\{-n,m}

\{-n,m}

n to m   (as few as possible)

\{-n}

\{-n}

n    exactly

\{-n,}

\{-n,}

at least n   (as few as possible)

\{-,m}

\{-,m}

0 to m   (as few as possible)

\{-}

\{-}

0 or more   (as few as possible)

overview of ordinary atoms

pattern
magic
nomagic
matches

/^

^

^

start-of-line (at start of pattern) /zero-width

/\^

\^

\^

literal '^'

/\_^

\_^

\_^

start-of-line (used anywhere) /zero-width

/$

$

$

end-of-line (at end of pattern) /zero-width

/\$

\$

\$

literal '$'

/\_$

\_$

\_$

end-of-line (used anywhere) /zero-width

/.

.

\.

any single character (not an end-of-line)

/\_.

\_.

\_.

any single character or end-of-line

/\<

\<

\<

beginning of a word /zero-width

/\>

\>

\>

end of a word /zero-width

/\zs

\zs

\zs

anything, sets start of match

/\ze

\ze

\ze

anything, sets end of match

/\%^

\%^

\%^

beginning of file /zero-width E71

/\%$

\%$

\%$

end of file /zero-width

/\%V

\%V

\%V

inside Visual area /zero-width

/\%#

\%#

\%#

cursor position /zero-width

/\%'m

\%'m

\%'m

mark m position /zero-width

/\%l

\%23l

\%23l

in line 23 /zero-width

/\%c

\%23c

\%23c

in column 23 /zero-width

/\%v

\%23v

\%23v

in virtual column 23 /zero-width

  • every 3rd

    regex every third
  • the 3rd

    regex every third

\v: the following chars in the pattern are "very magic":

  • ^\(.\{-}\zsPATTERN\)\{N} == > \v^(.{-}\zsPATTERN){N}

  • ^\(.\{-}\zs=\)\{N} == > \v^(.{-}\zs\=){N}

NOTICE: after using \v the = should using \= instead

characters

[!NOTE|label:references:]

first
char
mode
max nr of chars
max value

(none)

decimal

3

255

-

o or O

octal

3

377

(255)

x or X

hexadecimal

2

ff

(255)

u

hexadecimal

4

ffff

(65535)

U

hexadecimal

8

7fffffff

(2147483647)

insert unicode

micro

[!NOTE|label:references:]

stop macro at the end of line

stop recursive macro at the end of line

others

[!NOTE|label:references:]

[!NOTE|label:references:]

  • binary mode by -b

    • binary on

    • textwidth 0

    • modeline off

    • expandtab off

  • or

comments

[!NOTE|label:references:]

statueline

[!NOTE|label:references:]

ctags

[!NOTE|label:references:]

Last updated

Was this helpful?