VI commands: Difference between revisions

From Edgar BV Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
<pre>
VI SHIT
VI SHIT


Line 63: Line 64:
:%s/findme/replaceme/g
:%s/findme/replaceme/g
for every instance in the file (g)
for every instance in the file (g)
To replace every ; in a file with a new line use
:%s/;/<ctrl-v> <enter>(will turn into ^M)/g
The / charachter can be replaced with any other character and special characters such as /,",', etc can be escaped.
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
EG to replace every / in a file with a new line use
Line 69: Line 75:


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


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

Latest revision as of 09:34, 6 October 2017

VI SHIT

VIM defaults are in ~/.vimrc

:set noai

Sets auto indent

:set nocindent

sets autoindenting for braces and stuff

:set paste

is good to paste stuff in the format it was copied

(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)

To replace every ; in a file with a new line use

:%s/;/<ctrl-v> <enter>(will turn into ^M)/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 (or press the enter key).
You can find and replace with this too.

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