Notes on the Vim editor

Nothing too important in here...


How to temporarily stop wrapping
:set textwidth=0 wrapmargin=0

This setting will disappear once Vim exited and you reenter the next time.


.vimrc issues

Performing :version will reveal where Vim thinks it's getting your .vimrc, probably off ${HOME}/.vimrc. If you're not getting some of your function key mappings, you might look at your keyboard to see if the function keys are toggled on. (Some keyboards allow them to be off, default to off, etc. This is something to think about each time you start your host from cold/off.)


gvim issues

To remove unused toolbar from gvim, add this to bottom of .vimrc:

" Removes the button bar from under the menu of gvim saving wasting what's
" typically unused functionality.
set guioptions-=T

How to search using grep and open vim with the results

Assuming the use of grep (fgrep, etc.) to find specific strings in files that may lead you to want to edit them, ...

    $ fgrep -l some-string filenames

...with the -l option, you get only the list of containing files. How to get them into Vim? use xargs:

  1. This loads the first file into Vim with the others stacked up (using :n to visit each new file):
    $ grep -il some-string filenames | xargs vim
    
  2. This opens every file in its own pane in one Vim window:
    $ grep -il some-string filenames | xargs vim -o
    

How to fix last search string...

You entered a search string and mistyped something? Start searching again (by pressing / or ?), then press the up arrow (↑) and edit the string.


The 7 habits of effective text editing...

Bram’s presentation slides


EasyAccent to the rescue...

This gizmo lets me type diacritics in vim.

How to set it up

Download from http://vim.sourceforge.net/scripts/script.php?script_id=451.

Where do I drop this script (EasyAccents.vim) in order for it to be in effect (/home/russ/? c:\Documents and Settings\russ\My Documents?) and how do I set g:EasyAccents_VowelFirst to zero?

Bring up vim; type...

	:echo &rtp

...and you’ll see a comma-delimited list of directories. Pick one, preferably not a system one (i.e.: not where vim stores its plugins), and create a subdirectory, /plugin. Put the EasyAccents script in there. You can read more about this using:

	:help 'rtp'

Now for the second question: again, while in vim do:

	:echo $HOME

You should place in the directory so displayed the .vimrc (_vimrc) file. Within it, have the following lines in effect...

	set nocp
	filetype plugin on
	let g:EasyAccents_VowelFirst = 0

How to use it

It’s easy to toggle on and off, just type:

	\eza

Merely type a vowel after any of the following:

	`    (grave)
	'    (acute)
	^    (circumflex)
	:    (dieresis/umlaut)

...or a comma (,) followed by c or C for ç or Ç; and b or B for ß.

For remaining diacritics like ñ and å, you must do this instead...

let g:EasyAccents_VowelFirst = 1

...and type the vowel followed by the accent...

n~
a@
etc.


Copy using mouse...

Use mouse to select a block and press y.


Find word under cursor...

Use # to find the word under the cursor going backward. * will find the next occurrence of the word under the cursor.


Accumulated tricks

Many for gvim, but most hold for vim.

  1. Turn off audible beeping: :set visualbell

  2. Sort a range of lines alphabetically (after clicking and dragging to define a range).
    :{range}sort [u]
    
    Use the u if you also wish to lose duplicate lines. What I do (in gvim) is click and drag to select the range, then (with the range still selected) I type :sort u, which looks like this:
    :'<,'>sort u
    

  3. Split window vertically: Ctrl-w v

  4. Split window horizontally: Ctrl-w s

  5. Click and drag for a visual selection; pressing : to begin search and replace will bring up '>,'< to which you add s/search/replace/g and it will act within that range rather than the whole file.

  6. To move between Java methods, use
    n]m to move to start of nth succeeding method
    n]M to move to end of nth succeeding method
    n[m to move to start of nth previous method
    n[M to move to end of nth previous method

  7. To set number of lines and width of window:
    :set lines=66 columns=120
    
  8. To keep wrapping text (visually), but avoid inserting line breaks, do this:
    :set textwidth=0 wrapmargin=0
    
  9. To append lines to a temporary register, use lower-case buffer name to overwrite, upper-case to append; do this:
    "ayy yanks first line and overwrites register
    "Ayy yanks another line and appends to register

  10. Sort lines alphabetically, only running under a real, nix-shell, do this:
    1. Select block of lines visually (click and drag or type Shift-V and press down arrow, etc.).
    2. Invoke sort from shell by typing :, at which point you'll see: :'<',>
    3. Type sort at the cursor.
    4. Press Enter and see the magic.

  11. gvim: Opening multiple files each in its own tab
    $ gvim -p file-1 file-2 file-3 etc.
    
    Already in the editor on multiple files (each with its own buffer)?
    :tab ball # (tab buffer all)
    

Folding tricks

Think of folding as represented by Z, because the character suggests something folded in three parts.


gvim: Opening multiple files each in its own tab
$ gvim -p file-1 file-2 file-3 etc.

Already in the editor on multiple files (each with its own buffer)?

    :tab ball              # (tab buffer all)