RE: automatically enter normal mode
You can have something happen on multiples of CursorHold and CursorHoldI by doing something like this (untested): :let g:flag = 0 :au CursorHoldI * if g:flag == 1 | doSomething | let g:flag = 0 | else | let g:flag += 1 | endif The 'doSomething' bit should only happen every other CursorHoldI firing. You could change the if condition to work off a higher number if you want. I have a (relatively) complicated function called LongEnough that return true/false if it has either been sufficiently long since the last time it was called or if it has been called quite frequently. Useful if you want to execute something either every 5 seconds or every 3 calls, for example. I can share it if it'll help. Salman. -Original Message- From: Eric Smith [mailto:[EMAIL PROTECTED] Sent: Tuesday, May 08, 2007 5:17 PM To: vim@vim.org Subject: Re: automatically enter normal mode On 08/05/07, A.J.Mechelynck [EMAIL PROTECTED] wrote: In an autocommand, you need an ex-command, which Esc isn't. I suggest :au CursorHoldI * stopinsert Make sure 'updatetime' has a long enough value (the default is 4000, i.e., 4 seconds, which might be a little short for some people). Problem now is that I already have: au CursorHoldI * update and this wants an updatetime of 4000 while as you say stopinsert will want a higher number. Is there a way? Thanks Eric
RE: question about insert mode and zz
I know that a function key is a single key, but touch-typists might find it faster to map it to something like leaderzz so they don't have to actually take their hands off the home keys to get to the mapping. I've set the leader on my system to the comma instead of the backslash, so it's even faster for me to hit ,zz (which I can do without looking) than to look at the keyboard while I move my hand off the home keys to get to the function key. Here's another one I use (not mine, but I'm afraid I don't remember who suggested it) occasionally: map silent Leaderzz :let scrolloff=999-scrolloffCR:set scrolloff?cr Hitting \zz (or ,zz for me) changes the scrolloff to a really large number (well, it toggles between the large number and the original value, which for me is 3). The behaviour? The cursor line is always smack in the middle of the screen. Hitting \zz again restores the original behaviour. Hope this helps, Salman. -Original Message- From: A.J.Mechelynck [mailto:[EMAIL PROTECTED] Sent: Friday, May 04, 2007 11:28 AM To: shawn bright Cc: vimlist Subject: Re: question about insert mode and zz shawn bright wrote: Hey there all, i really dig the zz function to get me in the middle of the screen. i was wondering if there were an insert mode ability to do the same thing. So if i am writing a long function and get to the bottom of the screen i can move where i am at to the middle of the screen while still in insert mode? thanks for any tips shawn Ctrl-O zz see :help i_CTRL-O (that's control-oh, not control-zero). Or if you're lazy: :imap F9 C-Ozz then F9 does it. Best regards, Tony. -- The years of peak mental activity are undoubtedly between the ages of four and eighteen. At four we know all the questions, at eighteen all the answers.
RE: button t useless?
I'm a one-handed typist (right-handed), and to me both are about equally bad on ergonomical grounds. I don't think of what I do as pecking however: I know where the keys are on my AZERTY keyboard, and I use all five fingers of my right hand, which is not riveted to a constant location over the keyboard: this makes for reasonably fast typing, maybe faster that some of you decadactylographers ;-) . I go with the previous argument however: bdw has the inconvenient of including a prepare step: bdw (move);(delete(word)) diw (delete((inner)word)) In my mental model, bdw is two steps, diw is one. Best regards, Tony. Tony, I had indeed not considered those who either typed with one hand or used a non-QWERTY keyboard. In retrospect, if I were typing with one hand, I think I would prefer bdw to diw simply because the keys for it are close together, allowing for faster entry. Bdw is definitely two steps, both mentally and in actuality. As someone else pointed out, you can repeat diw with a ., but not bdw, as it is not atomic. Regards, Salman.
RE: button t useless?
This might not be a huge deal, but bdw is typed entirely with the left hand if you're on a QWERTY keyboard (most people with English/US keyboards) while diw switches hands. Unless you're pecking at the keys with one hand, diw is simply much faster to type :) Salman. -Original Message- From: Tim Chase [mailto:[EMAIL PROTECTED] Sent: Thursday, April 26, 2007 9:48 AM To: zzapper Cc: vim@vim.org Subject: Re: button t useless? When the cursor is in the middle of a word you wish to delete diw has a distinct advantage over bdw But what is it? I think it's the mental model. diw is two mental steps: {action}{object} where {action} is delete and {object} is iw even though that {object} is two characters. bdw, OTOH, has a 3-step mental model of {prepare}{action}{motion} where you {prepare} with b, {action} with d over {motion} with w. When vimming, you begin to think in the flow okay...I want to delete something [hit 'd'] and it's this thing [provide object/motion]. The latter intrudes on this by requiring you to not start your deletion action until you've prepared for it. Or maybe that's just the warped way my own mind works :) -tim
RE: wish: allow a: in the function def
I uploaded GetVar a long long time ago to vim.sf.net (initially in 2002, updated for Vim 7 in 2006) that basically is called with the name of a variable and an optional default value. It checks w:, b:, t:, and finally g: before returning the specified default value (default default value is -1). There is also a VarExists function in there that just returns true/false (1/0) based on whether it was able to find any of those. I use these to override global plugin settings on a per-buffer basis, among other things. Salman. -Original Message- From: Marc Weber [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 25, 2007 10:24 AM To: vim-dev@vim.org Subject: Re: wish: allow a: in the function def So maybe one could make vimscript search a variable foo as l:foo, a:foo, (maybe also: w:foo, b:foo), s:foo, g:foo, and then throw an undefined variable name error if none exists. Or so. No. I don't want to go back to VB without using Option Explicit ;) Don't let vim find some value somewhere. This leads to failures not so easy to spot But you are right. This might be useful: Use buffer setting if it exists, if not use global one.. But you should be able to emulate this behaviour using the function exists: function GetSetting(name) if exists('b:'.a:name) exec 'return b:'.a:name elseif exists('g:'.a:name) exec 'return g:'.a:name else echoe Please define setting .a:name endif endfunction perhaps even add a optional parameter for a default value.. I'm using this very often: function! vl#lib#brief#args#GetOptionalArg( name, default, ...) if a:0 == 1 let idx = a:1 else let idx = 1 endif if type( a:default) != 1 throw wrong type: default parameter of vl#lib#brief#args#GetOptionalArg must be a string, use string(value) endif let script = [ if a:0 = . idx \ , let .a:name. = a:.idx \ , else \ , let .a:name. = .a:default \ , endif \ ] return join( script, \n) endfunction function GetSetting(name, ...) exec vl#lib#brief#args#GetOptionalArg('default', string(option not given)) if exists('b:'.a:name) exec 'return b:'.a:name elseif exists('g:'.a:name) exec 'return g:'.a:name else return default endif endfunction Then you can use let b = GetSetting('my_name','default value') or let b = GetSetting('my_name') which will set b to option not given if neither b:my_name nor g:my_name does exist HTH Marc
Extended :normal
Hello, Since tips on vim.sf.net have been disabled because of spam, I thought I would share this here. I find the :Normal command extremely useful: Behaves like the built-in normal command, except that it takes keys such as f8 right on the command-line. function! Normal( bang, args ) execute 'map Normal_map ' . a:args execute 'normal' . a:bang . ' Normal_map' unmap Normal_map endfunction com! -bang -nargs=+ Normal call Normal( q-bang, q-args ) Typically, when you call :normal, you can't embed keys in there easily -- an example: :normal ispancr/spanesc Produces: spancr/spanesc (Insert mode is automatically exited at the end of the normal command.) However, :Normal ispancr/spanesc Produces: span /span I use it all the time with things like :windo (I have a lot of setting toggles mapped to function keys) to get things the way I like them in one fell swoop. Also, if you prefer to use the old-style keys (c-v followed by the key to get the actual key on the command-line), :Normal still works. Please note that you CAN get this effect with the built in :normal, but you have to do something like this: :execute normal ispan\cr/span\esc (I've gone so far as to set up a command-line abbreviation to always convert :normal to :Normal in my configuration.) Hope this helps, Salman.
RE: VIM doesn't need new features?!?!
I really didn't think Peter said anything that was a flame. Perhaps he didn't read the whole thing, but I, too, initially walked away with the same conclusion was he did, and I *have* been using Vim for a long time. (I just know better because I've been here longer.) Suresh, on the other hand, was pretty much out of line and actually took it to the level of personal attacks. Makes me wonder if he's really Sven Guckes in disguise. Salman. -Original Message- From: Milan Vancura [mailto:[EMAIL PROTECTED] Sent: Monday, April 16, 2007 3:27 AM To: Vim development list Subject: Re: VIM doesn't need new features?!?! The preceding shows you have trouble reading -- that page has a link to a voting page, which page lists certain core features that could be added to vim. If your investigation into plugins was as casual as your reading of the above link, then your efforts at finding and evaluating existing plugins in relation to your notion of a project are likely to have been botched! Vim has many, many features. We don't really need more Peter, don't start flames, please. vim-dev list is a very valuable list exactly for the reason that people usualy don't try flaming here. It's easy to take one sentence without any context and become upset. Read more (as Suresh Govindachar already suggested) and your life will be nicer again. Please start with Suresh Govindachar's e-mail, the answer for you is already there. The sentence you started a flame with means that it seems we can add new features by some script languages (most usualy the internal vim script) and don't need to add every bell and whistle in the core vim code. And it's true for your problem too: core vim features are strong enough to allow project handling - but the exact implementation is up to your choice. There are several plugins ready at vim.org which you can use or modify. So again: please start reading at vim.org again with this information in mind. And stop the flame. If you have a concrete question, ask here or at vim-users. Thank you and have a nice day, Milan Vancura -- Milan Vancura, Prague, Czech Republic, Europe
RE: hello again
Hello. Look up :help on 'ts' (with the single quotes), 'sts', 'sw' and 'et'. Basically, you want to :set 'tabstop' to 8, 'shiftwidth' to whatever you like to indent and 'expandtab' to on. This will take care of new code that you write. To convert existing tab-based indents, set 'tabstop' to the actual indent (4, for example), type :retab! to retab the whole thing and then set tabstop back to 8. At least, that's how I play this game :) Hope this help, Salman. -Original Message- From: shawn bright [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 21, 2007 2:44 PM To: vimlist Subject: hello again hello again from the newbie. i was wondering if there is an option to use spaces instead of tabs in my indenting and tabbing, especially when in python. This wouldn't be an issue, but i have written most of my stuff in JEdit using soft tabs and now when i mess with one of the files in vim, i get problems about indentation not being right. just wondering. and thanks shawn
RE: Tips which are spam
Might be easier on the user to use the 'negative captcha' idea floating about online: Put a hidden form field called email, phone, login or some such that a bot is likely to fill and use CSS to hide it. A human won't see it, but a bot will (ignoring CSS). If the field ends up containing a value, it must have been filled by a bot; ignore the tip/note submission. Not foolproof, but it'll probably work here. Salman. -Original Message- From: Andy Wokula [mailto:[EMAIL PROTECTED] Sent: Monday, February 05, 2007 3:35 PM To: John Beckett Cc: vim Subject: Re: Tips which are spam John Beckett schrieb: Andy Wokula wrote: Currently there is much spam in recent comments: http://vim.sourceforge.net/tips/recent_notes.php Last time this was discussed I got the impression that there is a feeling that if no one reads the spam, then it is not a problem. But I think the situation is worse than that. The spammers don't care if anyone reads the tips. They want the optimisation to their search ranking in Google et al from having links to their site. Helping these leaches is no longer acceptable IMHO. Lots of places on the Internet have had to implement a simple logon or at least a captcha - anonymous posting can't be allowed. John E.g. posters must either login or solve simple math (or answer simple Vim questions, even better ;) next to the Add Note button. Should be fairly easy to add? Andy -- EOF ___ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
RE: Spam in Tips in Vim's website
While I'm not in a position to determine who gets to moderate tips, I would like to request that if anybody sees spam while looking through a tip and decides to mention it, please include the tip number(s) so a moderator can go in and address the issue. Thank you, Salman. -Original Message- From: DervishD [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 17, 2007 2:47 PM To: vim Subject: Spam in Tips in Vim's website Hi all :) I've noticed that there are still spam in the Tips comments at the vim website. Bram, do you need help with that? If you want, I can take a look at the comments and delete any spam I catch. I don't know how much spare time I'll have, but even with ~1500 tips, it shouldn't take more than a week or so. I've read your post in the Vim page saying that with the help of moderators, the spam had been eliminated, so probably the spam I've seen today is new. That's bad :((( Raúl Núñez de Arenas Coronado -- Linux Registered User 88736 | http://www.dervishd.net It's my PC and I'll cry if I want to... RAmen!
RE: Tips which are spam--clean up author/summary
Moderators can only mark tips and/or comments as spam. We can't make any other changes. -Original Message- From: Russell Bateman [mailto:[EMAIL PROTECTED] Sent: Wednesday, January 17, 2007 4:09 PM To: vim Subject: Re: Tips which are spam--clean up author/summary While (someone) is at it, tip #1472's author and summary need to be adjusted. Similarly, #1456's author field.
RE: Spam in Tips in Vim's website
I've subscribed and I've already picked some of the spam. Unfortunately, this only solves tips that *are* spam, not spam in comments (at least I can't catch that from reader without looking at every tip). Raúl Núñez de Arenas Coronado Spam in comments can also be addressed by moderators as of fairly recently. When you come across such a comment, you can mark the comment as spam, leaving the rest of the tip and comments alone. While you are correct that you may not be able to catch them all, they're only a problem if someone stumbles across them -- in which case, they need only mention it and any moderator (yes, I speak for you, too!) will happily remove it. There is a page (http://vim.sourceforge.net/tips/recent_notes.php) that lists the most recently added tip notes. The nice thing about it is that you can mark notes as spam right from here. Salman.
RE: Disable mapleader in insert mode
I realize this won't help that much, except as an example of another user with the mapleader change. I use a comma as well, and the only way I get the delay in insert mode is when I actually HAVE a few insert-mode mappings. So I'm not actually seeing the problem you are. I'm using Vim 7.109 -- dunno if this was introduced in later versions (or fixed in later, if you have an earlier version than 109) -- I haven't built a newer Vim since patch 109. Hope this helps, Salman. -Original Message- From: Ying Bian [mailto:[EMAIL PROTECTED] Sent: Thursday, November 30, 2006 7:20 AM To: vim@vim.org Subject: Disable mapleader in insert mode Vimers, I set my mapleader to comma (,). Although I do not have any insert-mode maps starting with comma, whenever I type , in insert mode, it still waits for a while (the value of timeoutlen). Is there any way to disable the mapleader in insert mode so that vim will be more responsive when I type the mapleader? -- B.Y.
RE: Matching non-capitalized words?
Make sure 'ignorecase' is off: :set noignorecase :%s/\[a-z]\+\//g Salman. -Original Message- From: William O'Higgins Witteman [mailto:[EMAIL PROTECTED] Sent: Tuesday, July 25, 2006 4:24 PM To: vim Subject: Matching non-capitalized words? How would I match (and then delete) all of the words in a buffer that are not capitalized? Thanks. -- yours, William
RE: Making * search for strings
I use the extreme version: vnoremap silent * yy:let @/='\(' . substitute( escape( @y, '$*^[]~\/.' ), '\_s\+', '\\_s\\+', 'g' ) . '\)'cr:set hlscr This escapes a lot of stuff, including replacing any whitespace with a generic expression that includes newlines. I like it because if you highlight 'a b' (without the quotes) and hit *, it will subsequently also match 'a b', 'a\nb' (where the \n indicates that the a and b are on different lines). I got the idea from a previous discussion on this list (might well have been Gerald posting his mappings earlier). Oh, and I also wrap the search string in \(\) to allow its use in later search/replace expressions. Lastly, I don't perform an actual search, but rather set the search register and turn on highlights. Why? I like to see all my matches, but I don't really want the cursor to move when I hit *. Clobbers the y register, but you can easily change the first two characters of the mapping to do something else... In a similar vein, by the way, if you want to search for something currently on the clipboard, try: noremap // :let @/[EMAIL PROTECTED]cr:set hlscr Regards, Salman. -Original Message- From: Gerald Lai [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 26, 2006 1:30 AM To: Suresh Govindachar Cc: vim@vim.org Subject: Re: Making * search for strings On Tue, 25 Apr 2006, Suresh Govindachar wrote: Hello, By default, * searches for words: /\stuff_below_cursor\ but I would like it to search for strings: /stuff_below_cursor One way is to use the following map * yiw:let @/[EMAIL PROTECTED]cr Is there a better way? (/yiw didn't work.) I found this somewhere in Vim tips: visual search vnoremap * y/\VC-r=substitute(escape(@@,/\\),\n,n,ge)CRCR vnoremap kMultiply y/\VC-r=substitute(escape(@@,/\\),\n,n,ge)CRCR vnoremap # y?\VC-r=substitute(escape(@@,?\\),\n,n,ge)CRCR HTH :) -- Gerald
RE: Making * search for strings
I use the extreme version: vnoremap silent * yy:let @/='\(' . substitute( escape( @y, '$*^[]~\/.' ), '\_s\+', '\\_s\\+', 'g' ) . '\)'cr:set hlscr This escapes a lot of stuff, including replacing any whitespace with a generic expression that includes newlines. I like it because if you highlight 'a b' (without the quotes) and hit *, it will subsequently also match 'a b', 'a\nb' (where the \n indicates that the a and b are on different lines). I got the idea from a previous discussion on this list (might well have been Gerald posting his mappings earlier). Good idea :) I'll adopt it for my kMultiply. Question, do you think it would be useful to extend this to numbers too? For example, visual matching 123 results in \d\+? I thought about doing substitutions to non-whitespace characters (numbers with \d\+ and letters/underscores with \w\+) but it seemed to match too many things. Admittedly, I will occasionally have something like this: Word1 generalStuff Word2 Where 'generalStuff' could be any word (I don't care about it, as long as it's flanked by Word1 and Word2); when that happens, I do end up manually modifying the search after the *, but that happens infrequently enough (whether with numbers or digits) that it doesn't inconvenience me that much. How about another mapping that does something like: :let @/=substitute(@/, '\d\+', '\\d\\+', 'g') That way, when you decide you really want generic numbers, you can just hit the mapping after the * to make it happen. Regards, Salman.
c-o vs. esc and gi
Hello, I just noticed something I thought I had seen before but wasn't sure; I have the following mappings in my _vimrc: nmap f2 :updatecr imap f2 c-of2 This allows me to hit f2 to save the current buffer if it has been modified (I think it's from the Borland Pascal days) and leaves me in the mode where I was when I hit the key. (I have a visual mode version, for the curious, which does escf2gv -- updates and returns my visual selection -- but that one works fine so wasn't part of my discussion here.) The inconsistency I have noticed is when I am at the end of a line, typing away (making the line longer). If, while in insert mode, I hit f2, it performs the update, but leaves the cursor just before the last character on the line (one character to the left of where I actually was). If, instead, I map f2 like this: imap f2 escf2gi The problem goes away. My question is, why is escaSingleCommandgi different from c-oaSingleCommand? Thank you! -- Salman
RE: c-o vs. esc and gi
Hmm.. My imap is definitely invoked (it does the save just fine; it just moves the cursor). I don't have any InsertEnter or InsertLeave autocommands, either (Vim 7f). I guess it must be some setting somewhere -- I'll start with a clean Vim and see what happens, unless someone else can shed some insight on this, please. At least now I know that it's an isolated case and doesn't happen to everybody else. Thanks, Salman. -Original Message- From: Yakov Lerner [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 25, 2006 9:58 AM To: Halim, Salman Cc: vim@vim.org Subject: Re: c-o vs. esc and gi On 4/25/06, Halim, Salman [EMAIL PROTECTED] wrote: nmap f2 :updatecr imap f2 c-of2 The inconsistency I have noticed is when I am at the end of a line, typing away (making the line longer). If, while in insert mode, I hit f2, it performs the update, but leaves the cursor just before the last character on the line (one character to the left of where I actually was). For me, cursor remains where it was after f2 in insert mode. I don't have paste and I see for sure that imapping is indeed invoked. Yakov
RE: Moderator for Vim Tips
Yongwei, I'm a moderator myself and just noticed something a few days ago: a perfectly legitimate tip had a follow-up comment that was one of the spam messages... Salman. -Original Message- From: Wu Yongwei [mailto:[EMAIL PROTECTED] Sent: Wednesday, April 19, 2006 9:35 PM To: vim@vim.org Subject: Re: Moderator for Vim Tips On 4/20/06, Jeremy Conlin [EMAIL PROTECTED] wrote: A few weeks (months?) ago a suggestion was made that the submissions to Vim tips be moderated. This is due to the address being used by spammers. Apparently nobody volunteered to do this because there are still inappropriate tips being submitted. I am willing to do this, but I don't have the expertise required to test all the tips. I can screen them to make sure they are appropriate. Would that agree with anyone? Jeremy Conlin There are quite a few moderators here. However, tips are not moderated *before* appearing online. They are deleted if found inappropriate. I just deleted one. If you check the recent tips, you will find some sequence numbers missing, which are deleted `tips'. Best regards, -- Wu Yongwei URL: http://wyw.dcweb.cn/
Vim 7.0d02
Hello, On Windows XP, the following line throws an error in my _vimrc: set sessionoptions-=options sessionoptions-=folds sessionoptions-=resize sessionoptions-=buffers sessionoptions+=slash,unix It's probably caused by the new tab page option added to sessionoptions (it isn't the first -= setting in my _vimrc). Thank you, Salman.