Tuesday, 28 April 2015

VIM tips n tricks!

vim tips:

why hjkl? => these used to have the arrow keys on them on old terminal when Bill Joy wrote vi!
(hjkl -> down left up right)
open a file on pattern: vi +/pattern file
open a file on line number vi +20 file
w, b forward/back one word
$, 0 end or start of line
numberG goes to line number
cntrl-H erase last character typed
o insert after line O insert before line
x delete char, p put char xp swaps chars
dd delete line
p paste buffer
yy copy line into buffer
d/string/ delete everything up to string
numberdd delete number lines
 /pattern - search for pattern n find next occurence, N find previous occurence
if have cursor over pattern * will search for next occurence and # for previous one
:help subject gives more detailed help on a subjext = e.g. :help pattern
can highlight txt - e.g. V5j highlights next 5 lines of file - can then act on that (d/s etc)
to sort a range of lines : sort (pretty cool!)
to sort e.g. second column '<,'>!sort -n -k 2
cw change word
c) change sentence
c$ change from curser to EOL
cntrl-a - increment number under cursor cntrl-x decrement number under cursor
set list set nolist - shows hidden chars

can mark a line  m then a char to remember it e.g. ms marks a line with s, `s returns to that line later
:r !cmd reads output of command into file or :r filename
so could mark two lines e.g. ms then mq, to sort alphabetically could then:  :`q,`s !sort

an uber cool feature for editing files on a remote host:

vim scp://username@hostname/file

excellent tutorial here:  cool vi tutorial

No comments:

Post a Comment

connect ubuntu to wifi from command line

so i have a server install of a beta release of bionic beaver - ubuntu 18.04 - I want to connect this to wifi as I'm not near my cobble...