Categorías: Todo - insert - command

por Mike Ton hace 8 años

2488

vim

Vim offers powerful features for text editing, including macros and special key mappings. Macros allow users to record and replay sequences of commands, simplifying repetitive tasks.

vim

vim

macro

@q
access macro
qq
begin rec

stop

q

....

:

:Git
push origin master
:Gcommit
:Gstatus

-

stage file

Tab/
(char)\zs

align to char(after char)

=(char)

(Tabularize)align to char

binary
:%!xxd

-r

(revert?)

:set display=uhex
:set binary
ack "pattern" *
search for text in current directory
gr[ep] -rin -A 2 "pattern" .
search for text pattern(plus 2 lines) in all files at current pwd
!

*21.2* Executing shell commands

To execute a single shell command from Vim use ":!{command}". For example, to

see a directory listing:

:!ls

:!dir

The first one is for Unix, the second one for MS-Windows.

Vim will execute the program. When it ends you will get a prompt to hit

<Enter>. This allows you to have a look at the output from the command before

returning to the text you were editing.

The "!" is also used in other places where a program is run. Let's take

a look at an overview:

:!{program} execute {program}

:r !{program} execute {program} and read its output

:w !{program} execute {program} and send text to its input

:[range]!{program} filter text through {program}

regexp
:%s/oldstuff/newstuff/gci

simple global find and replace(confirm/caseinsensitive[i]casesensitive[I])

ls
list all files in buffer

:bp

buffer prev

:bn

buffer next

ctrl + ^

switch active buffer

:buffer n

switch to buffer by number

install

Mac
terminal

brew install macvim --override-system-vim

:help

pathing

:p

make filename full path

:h

head of the file name

/dropbox/mydir

/dropbox/mydir/mylist.txt

motion.text
nav

completion

ctrl + p (or ctrl + n)

screens

tabs

#gt

tab number

gT

gt

windows

ctrl+w

s

split horizontally

v

split vertically

w

tumble through windows

cursor

ctrl + i

ctrl + o

search

$

end

^

begin

brace match

%

highlight

#

search backward for word under cursor

*

search forward for word under cursor

f?

line

/?

document

prev

next

textobject

==

fix indentation

ctM

change 'till 'M'

ci{ [ci}]

change in bracket

caw

change in word greedy

ciw

change in word

select

z(folding)

*28.5* Folding by indent

Defining folds with |zf| is a lot of work. If your text is structured by

giving lower level items a larger indent, you can use the indent folding

method. This will create folds for every sequence of lines with the same

indent. Lines with a larger indent will become nested folds. This works well

with many programming languages.

Try this by setting the 'foldmethod' option:

:set foldmethod=indent

Then you can use the |zm| and |zr| commands to fold more and reduce folding.

It's easy to see on this example text:

i

toggle

c

close

o

open

m(char)

'(char)

'"

go to last cursor pos

'.

go to last edit

go to char

mark to char

Vi{

select in bracket

delete

d

d-i-b

delete in bracket

d-a-w

delete a word

repeat
&

:s

repeat last substitute

N

repeat / or ? backward(search)

n

repeat / or ? forward (search)

.

repeat last command

insert

This uses special keys to move around, while remaining in Insert mode. This

resembles what you would do in a modeless editor. It's easier to remember,

but takes more time (you have to move your hand from the letters to the cursor

keys, and the <End> key is hard to press without looking at the keyboard).

These special keys are most useful when writing a mapping that doesn't

leave Insert mode. The extra typing doesn't matter then.

An overview of the keys you can use in Insert mode:

<C-Home> to start of the file

<PageUp> a whole screenful up

<Home> to start of line

<S-Left> one word left

<C-Left> one word left

<S-Right> one word right

<C-Right> one word right

<End> to end of the line

<PageDown> a whole screenful down

<C-End> to end of the file

There are a few more, see |ins-special-special|.

a
append
I