VI commands

From Edgar BV Wiki
Revision as of 13:49, 2 March 2007 by Red (talk | contribs) (New page: VI SHIT VIM defaults are in ~/.vimrc :set noai Sets auto indent :set nocindent sets autoindenting for braces and stuff (good to put these off for pasting stuff from other config file...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

VI SHIT

VIM defaults are in ~/.vimrc

set noai

Sets auto indent

set nocindent

sets autoindenting for braces and stuff

(good to put these off for pasting stuff from other config files)

<shift+v> visual line select <alt+v> visual select point to point <ctrl+b> visual block select Y = yank (copy) d = (cut) P = paste after


start-line,end-linew /tmp/filename

write lines to /tmp/filename

.,$s/bla/BLA/g

replace bla to BLA from current line to last line in doc.


lines: . = current line, $ = last line

.,100 d = delete from current line to line 100 (, = seperator)

in the editor, doing 226dd will delete the next 226 lines from the cursor

!ls

runs 'ls'

r!ls

runs ls and puts the output in the open buffer

set number
set nonumber

puts the line numbering on or off

set textwidth=0

puts the max textwidth off for wrapping

Find and replace goes with

%s/findme/replaceme/

for the first instance and

%s/findme/replaceme/g

for every instance in the file (g) The / charachter can be replaced with any other character and special characters such as /,",', etc can be escaped. EG to replace every / in a file with a new line use

%s/\//\r/g


To get rid of "^M" (MSDOS carriage returns) in a file or to put them in press control+V and then type M. You can find and replace with this too.

Some usefull regular expressions to know (and use in replacements) are \n - newline \r - return use only \r to get stuff onto next lines, \n creates the ^@ char, and I'm not sure what that does yet