Vim Tips Wiki
(Move categories to tip template)
(Remove html character entities)
Line 1: Line 1:
 
{{review}}
 
{{review}}
 
{{TipImported
 
{{TipImported
|id=1378
+
|id=231
|previous=1377
+
|previous=230
|next=1379
+
|next=232
|created=November 3, 2006
+
|created=April 5, 2002
 
|complexity=basic
 
|complexity=basic
|author=Bertram Scharpf
+
|author=Salman Halim
|version=n/a
+
|version=6.0
|rating=4/3
+
|rating=5/2
 
|category1=Syntax
 
|category1=Syntax
 
|category2=
 
|category2=
 
}}
 
}}
  +
I frequently like to edit multiple files in the same vim session. however, if I come into vim from another window I frequently hit 'i' and start typing in whatever buffer is currently being used -- this is often the wrong one (requires <Esc>, undo, go the other buffer and . to redo).
When editing files in two different directories, for example when copying parts of code from one into the other, you may change the color scheme to quickly identify the directory of the current file:
 
   
  +
One way to work around this for me is to use a different color scheme depending on what file I'm working on:
 
<pre>
 
<pre>
  +
au BufEnter * if (exists("b:colors_name")) | let b:current_colors=colors_name
:autocmd BufEnter * if match(@%,'/otherdir/')&gt;=0 | colorscheme oceanblack | else | colorscheme inkpot | end
 
  +
\| execute "colorscheme " . b:colors_name | endif
  +
  +
au BufLeave * if (exists("b:current_colors")) | execute "colorscheme " . b:current_colors | endif
 
</pre>
 
</pre>
   
  +
If you define <tt>b:colors_name</tt> with a particular color scheme name, then the above autocommands will switch to that colorscheme when you enter that window and will return to the original color upon departure.
This does not work very well for split windows.
 
   
  +
Inside ftplugin/java.vim, for example, I might have <tt>b:colors_name</tt> set to 'morning', causing all java files to have a distinguishing color scheme.
See {{help|registers}} for information on @%.
 
   
 
==Comments==
 
==Comments==
"This does not work very well for split windows." - maybe try BufWinEnter instead of BufEnter?
 
----
 

Revision as of 05:25, 29 September 2008

Tip 231 Printable Monobook Previous Next

created April 5, 2002 · complexity basic · author Salman Halim · version 6.0


I frequently like to edit multiple files in the same vim session. however, if I come into vim from another window I frequently hit 'i' and start typing in whatever buffer is currently being used -- this is often the wrong one (requires <Esc>, undo, go the other buffer and . to redo).

One way to work around this for me is to use a different color scheme depending on what file I'm working on:

au BufEnter * if (exists("b:colors_name")) | let b:current_colors=colors_name
 \| execute "colorscheme " . b:colors_name | endif

au BufLeave * if (exists("b:current_colors")) | execute "colorscheme " . b:current_colors | endif

If you define b:colors_name with a particular color scheme name, then the above autocommands will switch to that colorscheme when you enter that window and will return to the original color upon departure.

Inside ftplugin/java.vim, for example, I might have b:colors_name set to 'morning', causing all java files to have a distinguishing color scheme.

Comments