sponsor Vim development Vim logo Vim Book Ad

Recent Vim Tip notes

tip #337 note #12875
dan.dorman@gmail.com, February 7, 2007 13:50
@Dave:

Thanks for pointing that out; the WinSCP integration works great.
 
tip #1043 note #12075
nsushkin@users.sourceforge.net, February 6, 2007 20:37
Transform XML output of cvs2cl (http://www.red-bean.com/cvs2cl/) into the format required for a promotion request.
cvs2cl.pl --xml gives you all the data and metadata you need.
 
tip #1504 note #11488
Anonymous, February 6, 2007 11:21
...and one more thing:
Ctrl-V is mapped only when your _vimrc contains following line:
source $VIMRUNTIME/mswin.vim

marian
 
tip #1504 note #11487
Anonymous, February 6, 2007 11:16
you could use <CR> (4 characters), which should work when your 'cpo' does not have < included. See
:he cpo-<
:he <>

even with < in 'cpo' you would be able to enter mapping this way - you need to use <special> modifier. See
:he :map-special

marian
 
tip #1491 note #11486
dsm26 [at] excite.com, February 6, 2007 10:42
Great Tip!  I use Vim from within bash on Windows XP and had to switch the path's to be more cygwin compliant.  I also switched some of the double quotes to single quotes.  Everything works great except that it takes forever to build my revision graph.  Here's my slight changes.  Fyi...I also used a different mapping than above, but that just a preference of mine:

" Save current buffer and diff the file using Tortoise SVN
map <unique> <silent> <leader>td :w<CR>:silent !'/C/Program Files/TortoiseSVN/bin/TortoiseProc.exe' /command:diff /path:'%' /notempfile /closeonend<CR>

" Save current buffer and launch Tortoise SVN's revision graph
map <unique> <silent> <leader>tr  :w<CR>:silent!'/C/Program Files/TortoiseSVN/bin/TortoiseProc.exe' /command:revisiongraph epath:'%' /notempfile /closeonend<CR>

" Save the current buffer and execute the Tortoise SVN interface's blame program
map <unique> <leader>tb :call TortoiseBlame()<CR>

" Save the current buffer and execute the Tortoise SVN interface's log
map <unique> <silent> <leader>tl   :w<CR>:silent !'/c/Program Files/TortoiseSVN/bin/TortoiseProc.exe' /command:log   /path:'%' /notempfile /closeonend<CR>

fu! TortoiseBlame()
  " Save the buffer
  silent execute(':w')

  " Now run Tortoise to get the blame dialog to display
  let filename = expand("%")
  let linenum  = line(".")
  execute('!/C/Progra~1/TortoiseSVN/bin/TortoiseProc.exe /command:blame /path:' . filename . ' /line:' . linenum . ' /notempfile /closeonend')
endfunc
 
tip #685 note #11462
danyel_lawson@yahoo.com, February 6, 2007 5:50
when using / for searching forward
n next match forward
N next match backward

when using ? for searching backward
n next match backward
N next match forward

just use N to reverse the search direction
by default searches loop around the document


Here is a neat way to use document searching:

c/tmp

change the first instance of tmp found
leaves you in insert mode
 
tip #1224 note #11382
MJ, February 6, 2007 4:30
It would be better to set the "myLang" variable local for each buffer,
cause the spell option is also local. In case you use two or more
buffers and activate "en_gb" for one, "g:myLang" contains 2 now if
you want to activate it for another one, you have to press <F7> three
times.

So change each occurrence of g:myLang to b:myLang and define it for
each buffer when the function is called for the first time. For this:  
remove the "let g:myLang = 0" line and add the following statement to
the function directly after the function declaration:

    if !exists( "b:myLang" )
        let b:myLang=0
    endif
 
tip #337 note #11061
alecclews@gmail.com, February 5, 2007 16:47
I have discovered how to make passive mode ftp work. See http://alecthegeek.wordpress.com/2007/02/06/handy-hack-how-to-use-vim-netrw-in-ftp-passive-mode/
 
tip #1501 note #10919
Anonymous, February 5, 2007 8:02
%s//.../
now this is a great  tip!  I had never seen it before, and it's immediately useful.

And also today, I learned of a Vi input manager for Cocoa applications on the Macintosh:
http://www.corsofamily.net/jcorso/vi/

It isn't the everything in Vi, let alone Vim, but it's a fantastic start.

This has been a great Vim day.
 
tip #1501 note #10766
Anonymous, February 5, 2007 3:47
Thanks, it is really interesting ...
 
tip #194 note #10412
martin@activevb.de, February 4, 2007 15:11
In good old msdos edit.com, you could paste text and the cursor wouldn't move to the last character of the pasted text, but instead staying at the current column. The technique described here is almost as good, but just almost :)
Does anyone know how to make vim behave like edit.com in this specific situation?
 
tip #693 note #10411
Anonymous, February 4, 2007 2:57
Thanks for your work!

The next example code has less stuff in it, even though it does include strings. Personally I prefered the former.
 
tip #1498 note #10410
Anonymous, February 4, 2007 1:10
<quote>
By doing this, you tell vim to interpret its current
position until the next occurance of " " (whitespace) as a word.
</quote>

This is not true. When you do that you simply tell vim to delete all the chars until (and including) the next space character. This is no magic, and I think it needs to be clarified for novices. The command f<char> puts the cursor on the next occurance of <char>. This is therefore a movement command. Any movement command, combined with the operator "d" instructs vim to delete until the new cursor position. As it has been suggested dW seems to be a more elegant way of doing this.
 
tip #693 note #10409
Anonymous, February 3, 2007 18:10
C example replaced to show strings. Thanks. --maverick
 
tip #26 note #10408
LynnKenney@ti.com, February 3, 2007 11:25
To those having problems with control-M not displaying as Control-M:

You should use the ENTER KEY or Return Key   INSTEAD of Control-M.
The purpose of the Control-V is to cancel the special meaning of the ENTER Key.

Therefore the key sequence to replace ^M that you may see at the end of a line is:

%s/control-vENTER//

control-v will appear as ^
Next when you then hit the enter key you will see ^M
The ^ will appear to be written over so what you actually see when you type the whole command is:

:%s/^M//

The fields of this "substitute" command are:
:(range)(action)/target/repacement string/options

% is the range and is a special character meaning the entire file. It can also be used in place of the name of the file. example :w %.bak would write the file you are editing to filename.bak. Range also understands line #s such as 5,10 or $,10. $ is the current line.

"s" is the action and means substitute in this case
target string and replacement string should be obvious

options change the default behavior of replace - examples are:
i  - ignore case, therefore the target string will be case insensitive
g - global, will replace the target multiple times per line if they exist

a better description of the substitute command is available right in VIM - just type :help substitute



 
tip #1269 note #10407
Anonymous, February 3, 2007 11:10
Note that
(i == 0 && !nextblank) || (i > 0 && ((indent(p) >= i && !(nextblank && a:inner)) || (nextblank && !a:inner)))

can be reduced to
(!nextblank && indent(p) >= i) || (!a:inner && nextblank)
 
tip #1266 note #10406
Anonymous, February 3, 2007 8:32
In fact the Enter key in all known text editors is quite an odd thing:
It produces a "\r", but once inserted you get a linebreak ("\n") in the text.
And nobody cares about (?)
 
tip #805 note #10405
tetsu_yes@gmail.com, February 3, 2007 7:08
Hi,

I really want to use the programme at http://bur.st/~benc/?p=external, but did not work for me.  Can you help? I used it  on Firefox 2.0, and it can start Vim (gvim) with a text copied from Firefox. But, the programme does not paste a text back to to Firefox when I type ":q!". Please, please help.

Tetsu
 
tip #26 note #10400
Anonymous, February 2, 2007 11:33
Totally stolen from a colleague, but make the following an executable script:

for f
        do
                mv $f ${f}~ && tr -d '\015\032' <${f}~ >$f
                rm ${f}~
        done

The command line syntax will be:
<script name> <input file>

The input file will be stripped of ^M.
 
tip #1501 note #10399
info at bertram dash scharpf dot de, February 2, 2007 10:04
Leaving the pattern empty has almost the same effect.

%s//.../

Maybe you like to have a look at "&", ":&", and "<c-r><c-w>".
 
tip #1498 note #10397
Anonymous, February 1, 2007 5:59
If you need that "f " motion often, you could also map
:ono <space> f<space>
first, and then delete with "d ", this is one key less :-)
 
tip #1497 note #10396
info at bertram dash scharpf dot de, February 1, 2007 3:53
The patterns become slightly more readable when
you use another delimiter than / and \v:

%s:\v//(.*):/*\1 */:
%s://\(.*\):/*\1 */:

Remove /* and */ at once. Avoid trailing spaces.

%s:/\*\(.\{-\}\)\s*\*/://\1:
 
tip #1498 note #10395
Anonymous, February 1, 2007 3:05
You can also use dW (capital W) to delete a WORD, which is a number of consecutive characters, such  as "/usr/bin/perl". Also check out dt<char>.
 
tip #1496 note #10394
Anonymous, January 31, 2007 23:28
Note that, for people using Vim with Windows keybindings, CTRL-V is (naturally) the paste operation;
so, to produce a ^M, you have to type CTRL-Q then CTRL-M
 
tip #1295 note #10393
Anonymous, January 31, 2007 15:22
Instead of simply opening a new tab, I find it more useful to use tabfind to search for and open anything in my path.

nmap <D-t> <Esc>:tabfind **/
nmap <D-t> <Esc>:tabnew<CR>
 

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
SourceForge.net Logo