I use a git repo and ghar to sync the config files on my desktop and laptop. And to set up new computers.
To set up a new computer, first install ghar:
$ cd ~ $ git clone https://github.com/philips/ghar.git $ export PATH=$PATH:`pwd`/ghar/bin/
You may wish to make the previous line permanent by adding the following to your .bashrc (or .bash_profile):
export PATH=$PATH:~/ghar/bin/
Then clone my (or your) config repo(s):
$ cd ghar $ git clone [email protected]:kwgoodman/config.git
Next tell ghar to install (symlink) your config files:
$ ghar install
Let's check the status:
$ ghar install --status
ghar does not overwrite existing files so move your existing config files (such
as .bashrc) before running ghar install
.
I know how to insert and save. For everything else I use the arrow keys. These vim notes are my journey to salvation.
The command to copy (t) or move (m) lines of text:
:[range]{t, m}[address]
For example:
:10t20
insert copy of line 10 on a new line after line 20:10m20
move line 10 to a new line after line 20:10t.
insert copy of line 10 on a new line after current line:10,13t20
insert copy of lines 10-13 on new lines after line 204:t$
insert copy of next 4 lines at end of file4:t0
insert copy of next 4 lines at top of file:t14
insert copy of current line after line 14
"A command using a motion, e.g., cw
, operates from the current cursor
position. A command using a text-object, e.g., ciw
operates on the whole
object regardless of the cursor position."
Text object commands have the form:
{command} {extent} {object}
where:
command | c (change), d (delete), v (select), y (yank), etc |
extent | i (inner), a (include enclosing quotes, parentheses, etc) |
object | w (word), s (sentence), p (paragraph), " , ) , etc |
Examples:
diw
delete current wordvaw
select current word plus trailing whitespace on one side of wordvip
select current paragraphvis
select current sentence (or block of code!)ci)
change everything between enclosing parentheses (or use"
,'
,]
, etc)ca)
same as above but include parentheses>ip
indent inner paragraph
Many text object commands have motion command equivalents. For example viw
is the same as bve
(or ve
if the cursor is already on the first
character of the word).
When using a command like ci"
the cursor does not have to be between the
quotes. It will change the text of the next quoted string on the current line.
I use a vim plugin to make indent objects that can be used to select text at
the current indentation level or higher. It is useful for treating Python code
in a if or for loop as a text object. For example, the command cii
changes all code that is indented as much as the current line or more.
<C-t>
insert one shiftwidth of indent at the start of current line<C-d>
delete one shiftwidth of indent at the start of current line<C-w>
delete word to the left of cursor (same as bash)<C-u>
delete back to start of line (same as bash)<C-r>0
paste yank register<C-r>"
paste unnamed register<C-r>=6*35<CR>
inserts 210
v/foo
select from cursor to "foo" (n
for next;v?foo
backwards)ev2B
select current WORD and previous word^2X
move current line two spaces left[n]H
move cursor to nth line of screenM
move cursor to middle line of screen[n]L
move cursor to nth line from bottom of screenzz
center screen on cursorgv
select last visual selection, enter visual modegp
,gP
same asp
,P
but leaves cursor at end1$
,2$
end of current, next line, etc.
:s/^/ /
move current line two spaces right:7pu
put yanked text on new line after line 7:7pu!
put yanked text on new line before line 74:
shorthand for range:.,.+3
<C-w>
delete word to the left of cursor (same as bash)<C-u>
delete back to start of line (same as bash)
o
go to other end of highlighted textu
,U
change selection to lower, upper caseI
,A
insert at start, end of selection (i
,a
don't work)p
replaces selection
""
unnamed, used byc
,d
,y
,x
,s
, etc."0
yank"-
deleted or changed text less than one line"+
system clipboard"*
last system-selected text".
last inserted text"{1-9}
most recent"1
, second most recent"2
, etc. delete
From 'Practical Vim' by Drew Neil:
``
position before the last jump within current file`.
location of last change`^
location of last insert`[
,`]
start, end of last change or yank`<
,`>
start, end of last visual selection
If you read this far then you wasted your time. You should have been reading 'Practical Vim' by Drew Neil.
<C-b>
,<C-f>
move backward, forward one character<C-a>
,<C-e>
go to start, end of line<M-b>
,<M-f>
move backward, forward one word (whitespace defined)<C-u>
,<C-k>
delete from cursor to beginning, end of line<C-w>
,<M-d>
delete from cursor to previous, next whitespace<C-y>
paste previous deletion<C-t>
,<M-t>
swap current character, word with previous