Home   Notes   Contact Me

vim

Local

External


How to Remove Empty Lines

:%s/^\n//g

Openning gvim as if it were vim

If gvim is run as vim it will behave as vim (i.e. open in the same window)

To to this make a soft link to gvim named vim and then execute it to run gvim as vim


Commands

DescriptionCommandsNotes
Begining of Line, Jump to0The command is the number zero, not the letter 'o'
config files
show load order
(like .vimrc
scriptnames
delete EOLJ
End of Line, Jump to$
Jump to EOFG
Jump to top of file:1'Goto' line 1
Macroq{letter to Identify Macro}{do stuff}q
execute:
@{letter used to identify macro}
example that deletes 2 lines then moves the cursor down a line:
qaddddjq
running the example 5 times:
5@a
Movement
(without cursor keys)
h - left
l - right
j - down
k - up
Outline: Collapse all to 1 levelzM
Outline: Collapse entire, one levelzm
Outline: Collapse folderzc
Outline: Collapse folder to 1 levelzC
Outline: Expand allzR
Outline: Expand entire, one levelzr
Outline: Folder Expand CompletelyzO
Outline: Open folderzo? This may open more than 1 level
Redo what was 'undo'-ed (undone)Control-R
Repeat Last Change.So if you did a 4x then moved (or not moved even), and then you type . it will repeat the 4x
Replace:[range]s/from/to/[flags]
or long version:
:[range]substitute/from/to/[flags]
replace all: :%s/This/That/
replace all with confirm: :%s/This/That/c
replace current line: :s/This/That/
to replace a slash: :s+w/+w/o+c
/{pattern}[/]Search for {pattern}
/{pattern}[/{count}]Search for the {count}'th occurance of pattern
Search Backwards%string
Search Next Forwardn
Search Next Reverse?
Undo current lines changesU
Undo last change, can be repeatedu
Window Navigationcontrol-W up
control-W down

Settings, at startup (.vimrc file)

.vimrc is typically located in the home directory
You can just put commands in it if you like
set background=dark

Variables

VariableDescription
:set nowrap
:set wrap
Turn line wrapping off and on
:set background=darkChanges pallette to accomidate a dark background
:set filetype=noneMakes it do file type specific stuff - such as syntax highlighting

Copy a Block of Text

  1. In command mode
  2. Move cursor to first char to copy
  3. type 'v'
  4. Move cursor to last char to copy
  5. type 'y' to yank (put data in copy buffer)
  6. Move cursor to where you want to place text
  7. type 'p' to paste

Text, a single color

In .vimrc
filetype off Or while running: :set filetype=none

Substitute


*10.2*  Substitution

The ":substitute" command enables you to perform string replacements on a
whole range of lines.  The general form of this command is as follows: >

        :[range]substitute/from/to/[flags]

This command changes the "from" string to the "to" string in the lines
specified with [range].  For example, you can change "Professor" to "Teacher"
in all lines with the following command: >

        :%substitute/Professor/Teacher/
<
        Note:
        The :substitute command is almost never spelled out completely.  Most
        of the time, people use the abbreviated version ":s".  From here on
        the abbreviation will be used.

The "%" before the command specifies the command works on all lines.  Without
a range, ":s" only works on the current line.  More about ranges in the next
section.

By default, the ":substitute" command changes only the first occurrence on
each line.  For example, the preceding command changes the line:

        Professor Smith criticized Professor Johnson today. ~

to:

        Teacher Smith criticized Professor Johnson today. ~

To change every occurrence on the line, you need to add the g (global) flag.
The command: >

        :%s/Professor/Teacher/g

results in (starting with the original line):

        Teacher Smith criticized Teacher Johnson today. ~

Other flags include p (print), which causes the ":substitute" command to print
out each line it changes.  The c (confirm) flag tells ":substitute" to ask you
for confirmation before it performs each substitution.  Enter the following: >

        :%s/Professor/Teacher/c

Vim finds the first occurrence of "Professor" and displays the text it is
about to change.  You get the following prompt: >

        replace with Teacher (y/n/a/q/l/^E/^Y)?

At this point, you must enter one of the following answers:

        y               Yes; make this change.
        n               No; skip this match.
        a               All; make this change and all remaining ones without
                        further confirmation.
        q               Quit; don't make any more changes.
        l               Last; make this change and then quit.
        CTRL-E          Scroll the text one line up.
        CTRL-Y          Scroll the text one line down.


The "from" part of the substitute command is actually a pattern.  The same
kind as used for the search command.  For example, this command only
substitutes "the" when it appears at the start of a line: >

        :s/^the/these/

If you are substituting with a "from" or "to" part that includes a slash, you
need to put a backslash before it.  A simpler way is to use another character
instead of the slash.  A plus, for example: >

        :s+one/two+one or two+