Re: VimTips Wiki: New Direction
On Tue, 06 Mar 2007 22:29:35 +0100 Tobias Pflug <[EMAIL PROTECTED]> wrote: > Looking at : > http://en.wikibooks.org/wiki/Learning_the_vi_editor/Vim/TipsSandbox/Tip_1:_the_super_star > > my thoughts: > > 1. focus/structure: > > At the moment there is a bit of a lack of focus when I look at the > page. The eye-catcher is more or less the box with the > author/creator/etc meta information. The focus should however be on > the actual text/body of the tip. So maybe the text should be in a > (differently colored?) box to gain more attention and separate it > from comments and meta info etc. Same goes with the info boxes for > comments on the tip and the comments contents. I'd also suggest to > maybe separate tips with horizontal lines (maybe even removing the > info boxes..) Also what about perhaps indenting the comments a bit to > the right? I totally agree. The page is too messy. I would rather have something looking like: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/502304 Also the vimtips should perhaps be like an archive so that one can write the best solutions in the wiki?
RE: How to paste without replace the content in buffer
> -Original Message- > From: Peng Yu [mailto:[EMAIL PROTECTED] > Sent: Saturday, March 10, 2007 10:38 PM > To: vim@vim.org > Subject: How to paste without replace the content in buffer > > Hi, > > Suppose I want to replace "string1" with "string2" in a file from vim. > > 1. Highlight "string1" (in visual mode) and then type "y". > 2. Highlight "string2" (in visual mode) and then type "p". > > However, the problem with the above procedure is that > "string2", instead of "string1", is in buffer. That is if I > highlight "string3" > and then type "p", "string3" will be replaced with "string2" > instead of "string1". > > I'm wondering if there is any way to avoid change the content > in the buffer? You might want to consider using one of my plugins: YankRing.vim : Maintains a history of previous yanks and deletes http://www.vim.org/scripts/script.php?script_id=1234 Vim already maintains a list of numbered registers containing the last 9 deletes. These previous deletes can be referenced using [register]p, so "1p will paste the last delete, "2p the 2nd last delete. For more information see |quote_number|. Vim does not provide any mechanism to reference previous yanked text. In Emacs this feature is called the "kill ring". The yankring plugin allows the user to configure the number of yanked and deleted text. A split window can be used to choose which element(s) from the yankring you wish to paste. Alternately after text has been pasted (using p), it can be replaced with a previous value from the yankring with a single key stroke. A tutorial is included to take you through the various features of the plugin. After you have installed the plugin just run: :h yankring.txt :h yankring-tutorial The yankring can be interacted with in two ways: a GUI or via maps. ... More details and features to go with it. Have a look at the webpage for more details. HTH, Dave
RE: replace upper-case with lower-case
> -Original Message- > From: Bin Chen [mailto:[EMAIL PROTECTED] > Sent: Thursday, March 08, 2007 9:44 PM > To: vim@vim.org > Subject: replace upper-case with lower-case > > I want to replace below scheme within one command, that is > left the capitalization the same but replace the word. > > SS->SS > ss->ss For all the people that responded on this thread, you may want to look at this script which I think is great: " KeepCase - Match mixed case while substituting /*{{{*/ " Author: Michael Geddes " http://www.vim.org/scripts/script.php?script_id=6 " Usage: Using KeepCase or KeepCaseSameLen defined here, do a substitution "like this: " " %s/\u\/\=KeepCaseSameLen(submatch(0), 'new_word')/g " " * KeepCase( original_word , new_word ) " returns the new word maintaining case " simply uses heuristics to work out some different common situations " given NewWord " Word --> Newword " WORD--> NEWWORD " word--> newword " WoRd--> NewWord " woRd--> newWord HTH, Dave
RE: [PATCH] minor doc update
> OTOH, the svn repository is known to "lag behind" the other > repositories, > sometimes by a week or more: diffing against it runs the risk of > forking the > code. IIUC, the "latest on nluug.nl" is also the "latest official > version" at > any point in time. You can compare the first line of the version you > have with > the one I showed above. I think it is wise to always diff against the > latest > known version, whichever it be: IOW, if your version is earlier than > mine, it > will "imminently" be obsoleted, even if your patch is not accepted. Excellent point. Bram - what is your preference for documentation patches? cheers
Re: [PATCH] minor doc update
Michael Wookey wrote: Michael Wookey wrote: Attached is a small patch to update the information for 'listchars' in options.txt. There was no linkage to the highlight groups that listchars uses. cheers Are you sure you diffed against the latest version of the file? In the version I have, *options.txt* For Vim version 7.0. Last change: 2007 Feb 28 your patch matches at an offset of +22 lines (starting at line 4324 instead of 4302). Note: Changes to the runtime files are often "silently applied" to the files on the ftp/rsync/cvs/svc servers without being reflected in an official "patch". I performed the diff against what is in the svn repository since that will be a 'constant' and a known revision number. This avoids breakage against a 'point in time' diff against what happens to be the latest on ftp.nluug.nl at any given time. OTOH, the svn repository is known to "lag behind" the other repositories, sometimes by a week or more: diffing against it runs the risk of forking the code. IIUC, the "latest on nluug.nl" is also the "latest official version" at any point in time. You can compare the first line of the version you have with the one I showed above. I think it is wise to always diff against the latest known version, whichever it be: IOW, if your version is earlier than mine, it will "imminently" be obsoleted, even if your patch is not accepted. Also, my mail client was a bit too smart with the group list and I inadvertently sent the patch to the general vim list and not vim-dev. cheers Best regards, Tony. -- After [Benjamin] Franklin came a herd of Electrical Pioneers whose names have become part of our electrical terminology: Myron Volt, Mary Louise Amp, James Watt, Bob Transformer, etc. These pioneers conducted many important electrical experiments. For example, in 1780 Luigi Galvani discovered (this is the truth) that when he attached two different kinds of metal to the leg of a frog, an electrical current developed and the frog's leg kicked, even though it was no longer attached to the frog, which was dead anyway. Galvani's discovery led to enormous advances in the field of amphibian medicine. Today, skilled veterinary surgeons can take a frog that has been seriously injured or killed, implant pieces of metal in its muscles, and watch it hop back into the pond just like a normal frog, except for the fact that it sinks like a stone. -- Dave Barry, "What is Electricity?"
RE: [PATCH] minor doc update
> Michael Wookey wrote: > > Attached is a small patch to update the information for 'listchars' > in > > options.txt. There was no linkage to the highlight groups that > > listchars uses. > > > > cheers > > Are you sure you diffed against the latest version of the file? In the > version > I have, > > *options.txt* For Vim version 7.0. Last change: 2007 Feb 28 > > your patch matches at an offset of +22 lines (starting at line 4324 > instead of > 4302). > > Note: Changes to the runtime files are often "silently applied" to the > files > on the ftp/rsync/cvs/svc servers without being reflected in an official > "patch". I performed the diff against what is in the svn repository since that will be a 'constant' and a known revision number. This avoids breakage against a 'point in time' diff against what happens to be the latest on ftp.nluug.nl at any given time. Also, my mail client was a bit too smart with the group list and I inadvertently sent the patch to the general vim list and not vim-dev. cheers
Re: [PATCH] minor doc update
Michael Wookey wrote: Attached is a small patch to update the information for 'listchars' in options.txt. There was no linkage to the highlight groups that listchars uses. cheers Are you sure you diffed against the latest version of the file? In the version I have, *options.txt* For Vim version 7.0. Last change: 2007 Feb 28 your patch matches at an offset of +22 lines (starting at line 4324 instead of 4302). Note: Changes to the runtime files are often "silently applied" to the files on the ftp/rsync/cvs/svc servers without being reflected in an official "patch". Best regards, Tony. -- Hell hath no fury like a bureaucrat scorned. -- Milton Friedman
Re: Best way to repeat a sequence of keystrokes/commands with a single keypress ?
Tim Chase wrote: [...] You can read about ":s"ubstitute commands and the various flags at :help :s :help :s_flags This is a jet-fuel-powered version of search-and-replace that one finds in most editors. The {pattern} portion has an incredible degree of complexity for finding precisely the match you intend, including context, repetitions, and the like. Far too much erudition can be found at :help pattern far too much indeed, but there is a nice summary at :help pattern-overview There are also tricks that can be done in the replacement portion as well: :help sub-replace-special It's prob. more than you want/need at the moment, but after tapping the power of vim's search&replace, it bugs me to use s&r in any other app. [...] Best regards, Tony. -- There was a young man of St. John's Who wanted to bugger the swans. But the loyal hall porter Said, "Pray take my daughter! Those birds are reserved for the dons."
Re: Best way to repeat a sequence of keystrokes/commands with a single keypress ?
Ivan Vecerina wrote: [...] While editing a file, I decide to rename "someIdentifier" to "someIdentifier_" - I will need to append the underscore to several (but usually not all) instances of the word. [...] Here's how I would do that: Let's assume your current directory (as shown by ":pwd") is the top directory of the project in question, and that you want to check all *.pro, *.cpp, *.c and *.h files in that directory and below. :args ./**/*.pro ./**/*.cpp ./**/*.[ch] :argdo 1,$s/\/\0_/gc | update The first line sets the argument list to the project files. The second line runs a common set of commands on all the files in the argument list, as follows: 1,$ from first to last line of the file s/substitute what? \end-of-word (zero-length) / replace by what? \0the whole matched string _ plus an underscore / start of replace flags g everywhere (not only first time) in the line c with "confirmation" prompt | update then write the file if modified The confirmation prompt takes care of your "...(but usually not all)..." restriction by showing you each possible replace in turn, asking for a yes/no decision. The ":update" command saves each file (if modified) before examining the next, and is not needed if at least one of 'autowrite' and 'autowriteall' is on (which is not the default). Best regards, Tony. -- Sex is one of the nine reasons for reincarnation ... the other eight are unimportant. -- Henry Miller
[PATCH] minor doc update
Attached is a small patch to update the information for 'listchars' in options.txt. There was no linkage to the highlight groups that listchars uses. cheers options_listchars.patch Description: options_listchars.patch
Re: visual problem
Simon Jackson schrieb: I have a problem when i am in visual mode and i have text highlighted. Instead of being able to run a command, it just overwrites my selected text instead. im sure its because of something in my vimrc but i just cant pinpoint it, can anyone help? P.S.: If anyone sees some errors in my vimrc or maybe how something can be done more efficiently please let me know. filetype on " detect the type of file filetype plugin indent on" enable filetype plugin second line is enough set gdefault " Use 'g' flag by default with :s/foo/bar/ Can result in obscure errors with some badly written plugin, that does not reset 'gdefault' to the default. ! Looks like you're not happy with set selectmode=mouse,key,cmd au FileType helpfile set nonumber " no line numbers when viewing help au FileType helpfile nnoremap " Enter selects subject au FileType helpfile nnoremap " Backspace to go back Does this work for you? On helpfiles, :set ft? returns "help", not "helpfile". highlight Pmenu guibg=black gui=bold Works as long as you don't change colorschemes. Andy -- EOM ___ Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de
Re: visual problem
Simon Jackson wrote: I have a problem when i am in visual mode and i have text highlighted. Instead of being able to run a command, it just overwrites my selected text instead. im sure its because of something in my vimrc but i just cant pinpoint it, can anyone help? Would you please give an example of the problem? Regards, C Campbell
Re: Best way to repeat a sequence of keystrokes/commands with a single keypress ?
> Thank you (and Jürgen too), @@ is an easy first step for > me. Glad to have some easy first steps to help you out. >> Alternatively, problems can often be rephrased in terms >> of an Ex command that uses the ":%s" or ":g"/":v" to >> perform changes across the entire file. > > [...] > >> By changing your thinking to exploit these commands, >> sometimes you can get easy consistent changes without >> having to manually touch each bit with a macro. > > I admit that I am currently more of a visual "n.n.nn.nn." kind > of person. I should take some time to get into using Ex. > > If I may seek further guidance with a concrete example: Of course :) > While editing a file, I decide to rename "someIdentifier" to > "someIdentifier_" - I will need to append the underscore to > several (but usually not all) instances of the word. The typical way to do this would be something like :%s/\/&_/g If you want confirmation, you can use :%s/\/&_/gc which will prompt you for each instance of "someIdentifier" that it finds, and append an underscore if you answer "y" to the question. The "\<" and "\>" ensure that there are word-boundaries (as defined by your 'iskeyword' setting) which prevent it from finding and replacing things like "wholesomeIdentifier" and "someIdentifier2" The ampersand in the replacement stands for "whatever it was that I found, drop it here in the replacement". This is shorthand for :%s/\/someIdentifier_/g > The same would happen if I want to rename "wonderfulFoo" to > > "wonderfulBar". I tend to type: *fFceBar Similarly, one would do something like :%s/\/wonderfulBar/g (again with the "c"onfirmation flag if you want to confirm each replacement) You can read about ":s"ubstitute commands and the various flags at :help :s :help :s_flags This is a jet-fuel-powered version of search-and-replace that one finds in most editors. The {pattern} portion has an incredible degree of complexity for finding precisely the match you intend, including context, repetitions, and the like. Far too much erudition can be found at :help pattern There are also tricks that can be done in the replacement portion as well: :help sub-replace-special It's prob. more than you want/need at the moment, but after tapping the power of vim's search&replace, it bugs me to use s&r in any other app. > But then I cannot use "n.nn." to repeat (but maybe "n;.nn;."). > How would I use Ex or another approach to save me some typing > during the process described above (for example repeatedly > appending '_' to an identifier) ? If you have trouble with the above, you can do some transitional work as long as you don't mind a little mental arithmetic. For you first example, you can use the regular search command as you normally do: /someIdentifier but append /someIdentifier/e which will drop your cursor at the end of the match (where you can use "a_" followed by to append the underscore) rather than at the beginning of it. This will allow you to use your "n.nn.n.nn." method, as it will put you in the right place. For your second example, you have to do a little tweaking, as you want to be 3 characters from the end, you have to use /someIdentifier/e-2 (curses on those silly fence-post issues) followed by "ceBar" followed by to "c"hange to the "e"nd of the word. This too is repeatable with your "n.nn.n.n." pattern. This is because the "n" and "N" operators remember the offset as well, so they position you at the right place. To read more on this, you can hit the help at :help search-offset > And can this trick still be easily applied if only some instances > of the identifiers are to be replaced ? If you can identify them by certain factors, then vim can handle them. If, for instance, you only wanted to do the above search&replace on lines containing "function" at the beginning of the line, you could use :g/^function/s/\/wonderfulBar/g Things can get crazy-complex when you start building these, but the expressive power allows you the freedom to make surgically precise strikes on your text, for things like "replace every instance of 'footnoteN' where N is an arbitrary positive integer, with 3 added to N, but only from the 314th line of my file through the end of text as determined by the last line containing the word 'APPENDIX' from the end of the file" (avert your eyes if you're easily daunted) :314,$?APPENDIX?s/footnote\zs\(\d\+\)/\=submatch(0)+3/g from which you can discern the basic skeleton: :{range}s/{pattern}/{replacement}/{flags} where range = 314,$?APPENDIX? pattern = footnote\zs\(\d\+\) replacement= \=submatch(0)+3 flags = g (pedant's note: if APPENDIX falls on the last line, it won't find it) > [ wow... I'll be called a nuthead for asking such a question > anywhere else on the net ... hopefully not here ;) ] The vim-list is yet one more of Vim's amazing assets. It's a friendly bunch, and rather on-topic (barring semi-off-topic discussions about moving
Re: Best way to repeat a sequence of keystrokes/commands with a single keypress ?
[ again, trying to workaround messy newline conversions ] Thank you (and Jürgen too), @@ is an easy first step for me. Next: "Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] : Alternatively, problems can often be rephrased in terms of an : Ex command that uses the ":%s" or ":g"/":v" to perform : changes across the entire file. [...] : By changing : your thinking to exploit these commands, sometimes you : can get easy consistent changes without having to : manually touch each bit with a macro. I admit that I am currently more of a visual "n.n.nn.nn." kind of person. I should take some time to get into using Ex. If I may seek further guidance with a concrete example: While editing a file, I decide to rename "someIdentifier" to "someIdentifier_" - I will need to append the underscore to several (but usually not all) instances of the word. Starting in normal mode at the first instance of "someIdentifier", I would type: *ea_ But then I cannot use the "n.nn." routine to modify subsequent identifiers -- because the '.' will not apply the change at the end of the word. (I would have to type "ne.nne.") The same would happen if I want to rename "wonderfulFoo" to "wonderfulBar". I tend to type: *fFceBar But then I cannot use "n.nn." to repeat (but maybe "n;.nn;."). So: I like using the n-dot pair of commands, but I can only take advantage of it if I rewrite the whole identifier. How would I use Ex or another approach to save me some typing during the process described above (for example repeatedly appending '_' to an identifier) ? And can this trick still be easily applied if only some instances of the identifiers are to be replaced ? Thanks ! Ivan [ wow... I'll be called a nuthead for asking such a question anywhere else on the net ... hopefully not here ;) ] Sucker-punch spam with award-winning protection. Try the free Yahoo! Mail Beta. http://advision.webevents.yahoo.com/mailbeta/features_spam.html
Re: Best way to repeat a sequence of keystrokes/commands with a single keypress ?
Thank you (and Jürgen too), @@ is an easy first step for me. Next: "Tim Chase" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] : Alternatively, problems can often be rephrased in terms of an Ex : command that uses the ":%s" or ":g"/":v" to perform changes : across the entire file. [...] : By changing : your thinking to exploit these commands, sometimes you can get : easy consistent changes without having to manually touch each bit : with a macro. I admit that I am currently more of a visual "n.n.nn.nn." kind of person. I should take some time to get into using Ex. If I may seek further guidance with a concrete example: While editing a file, I decide to rename "someIdentifier" to "someIdentifier_" - I will need to append the underscore to several (but usually not all) instances of the word. Starting in normal mode at the first instance of "someIdentifier", I would type: *ea_ But then I cannot use the "n.nn." routine to modify subsequent identifiers -- because the '.' will not apply the change at the end of the word. (I would have to type "ne.nne.") The same would happen if I want to rename "wonderfulFoo" to "wonderfulBar". I tend to type: *fFceBar But then I cannot use "n.nn." to repeat (but maybe "n;.nn;."). So: I like using the n-dot pair of commands, but I can only take advantage of it if I rewrite the whole identifier. How would I use Ex or another approach to save me some typing during the process described above (for example repeatedly appending '_' to an identifier) ? And can this trick still be easily applied if only some instances of the identifiers are to be replaced ? Thanks ! Ivan [ wow... I'll be called a nuthead for asking such a question anywhere else on the net ... hopefully not here ;) ] It's here! Your new message! Get new email alerts with the free Yahoo! Toolbar. http://tools.search.yahoo.com/toolbar/features/mail/
Re: autocomplete from BufReadCmd
On 3/12/07, Raphael Bauduin <[EMAIL PROTECTED]> wrote: > vim comandline completion if programmable: > :helpgrep -complete=file > :helpgrep -complete=custom This is what I need. However, I hoped to be able to define it for standard vim commands such as split, edit, etc Isn't there a way to specify a custom completion if the filename starts with radiant/ , like I defined the autocommands for filename starting with radiant/ ? Examples of what I want to achieve: :split radiant/p -> :split radiant/pages/ :split radiant/l -> :split radiant/layouts/ :split radiant/ -> cycles through pages,layouts,snippets :split radiant/pages/ -> :split radiant/pages/Home\ Page This should also work with edit, vsplit, etc As far as I know, the builtin filename-completion for builtin commands is not customisable. However. You can use the command-refirection trick to remap some builtin commands to your own commands (which will have your own completion): http://www.vim.org/tips/tip.php?tip_id=1285 Tip #1285: remap builtin commands like :e Yakov
Re: autocomplete from BufReadCmd
vim comandline completion if programmable: :helpgrep -complete=file :helpgrep -complete=custom This is what I need. However, I hoped to be able to define it for standard vim commands such as split, edit, etc Isn't there a way to specify a custom completion if the filename starts with radiant/ , like I defined the autocommands for filename starting with radiant/ ? Examples of what I want to achieve: :split radiant/p -> :split radiant/pages/ :split radiant/l -> :split radiant/layouts/ :split radiant/ -> cycles through pages,layouts,snippets :split radiant/pages/ -> :split radiant/pages/Home\ Page This should also work with edit, vsplit, etc If you want to see the complete code of the vim script, it is available at http://www.raphinou.com/radiant.vim/ Thanks Raph -- Web database: http://www.myowndb.com Free Software Developers Meeting: http://www.fosdem.org
Re: autocomplete from BufReadCmd
On 3/11/07, Raphael Bauduin <[EMAIL PROTECTED]> wrote: Hi, I've written a BufReadCmd so that when I edit files starting with radiant/ (I am working with http://www.radiantcms.org ), it lets me edit a certain field of a certain row determined by the path following the radiant/prefix: :au BufReadCmd radiant/* ruby ReadFile( VIM::evaluate( "expand('')")) For example, this command :split radiant/pages/Home\ Page/articles/First\ Post/body lets me edit the body of the First post located in the section acticles which is itself under the Home Page. Similarly :split radiant/layouts/1 lets me edit the layout with id 1. As my first example shows, the length of the path to enter can grow, and I would like to add autocompletion like there is when editing a file on the filesystem. The problem is that I didn't find any documentation for that. Does anyone of you have a pointer to documentation on how to implement this? Raph -- Web database: http://www.myowndb.com Free Software Developers Meeting: http://www.fosdem.org I am not sure I understand your request right. However, try this: 1. set wildmode=list:longest set wildmenu 2. Press tab when typing pathname on the commandline. You will get completion menu. 3. vim comandline completion if programmable: :helpgrep -complete=file :helpgrep -complete=custom Yakov