Re: paste staircasing
Thanks. On Mon, 12 Feb 2007, Zdenek Sekera wrote: Ben K. wrote: Thanks much. On Fri, 9 Feb 2007, Hugh Sasse wrote: On Fri, 9 Feb 2007, Ben K. wrote: Hi, Whenever I paste something into vim, it gets staircased. Is there a way to avoid copy/paste being staircased even when I have ai, cin or si turned on? I Yes, set paste. See :he paste for more on this. Also :he pastetoggle is good I have in my .vimrc: nmap :exe ":undo|:set paste|:normal .:set nopaste" set pastetoggle= The first line of which is to redo a botched paste, the second of which is to make the key turn this on an off. For me that only works in inset mode. Maybe someone can improve on this. I use this (it's in my .vimrc): "# - toggle paste "#(must have 'pastetoggle' set) set pastetoggle=" toggle 'paste' option map :set invpaste paste? imap:set invpaste/ It works both i normal as well insert mode. Hit in normal or insert mode and the 'paste' option will be inverted but also displayed at the bottom of your window. Stays until you hit again. Regards, ---Zdenek Regards, Ben K. Developer http://benix.tamu.edu
Re: paste staircasing
Thanks much. On Fri, 9 Feb 2007, Hugh Sasse wrote: On Fri, 9 Feb 2007, Ben K. wrote: Hi, Whenever I paste something into vim, it gets staircased. Is there a way to avoid copy/paste being staircased even when I have ai, cin or si turned on? I Yes, set paste. See :he paste for more on this. Also :he pastetoggle is good I have in my .vimrc: nmap :exe ":undo|:set paste|:normal .:set nopaste" set pastetoggle= The first line of which is to redo a botched paste, the second of which is to make the key turn this on an off. For me that only works in inset mode. Maybe someone can improve on this. [...] Since "pasting" usually has dedicated or no keystrokes (shift+insert/control+v or middle/right mouse button), is there a way for me to tell vim that ai, cin, or si should not interfere when I do pasting? I think the above will do what you want. I mostly work on unix platforms, so unix-only solution also works for me. This works in vim6 and 7. Definitely 7, pretty sure about 6. Thanks. Ben K. Developer http://benix.tamu.edu HTH Hugh Regards, Ben K. Developer http://benix.tamu.edu
paste staircasing
Hi, Whenever I paste something into vim, it gets staircased. Is there a way to avoid copy/paste being staircased even when I have ai, cin or si turned on? I usually need the options and it's cumbersome to turn them off only for pasting and on again after pasting. 770 | EPSY435,STAT303,EHRD489 | 900 | CPSC110,CPSC206 | If I open the file with vi (not vim) and paste the same, it does not happen. 770 | EPSY435,STAT303,EHRD489 | 900 | CPSC110,CPSC206 | Since "pasting" usually has dedicated or no keystrokes (shift+insert/control+v or middle/right mouse button), is there a way for me to tell vim that ai, cin, or si should not interfere when I do pasting? I mostly work on unix platforms, so unix-only solution also works for me. Thanks. Ben K. Developer http://benix.tamu.edu
Re: search within buffers
On Fri, 8 Dec 2006, Bill McCarthy wrote: Is there a way to do grep only within the open files (buffers)? I did :he grep and bufdo but it didn't seem to give me the option. Here's one I have in my vimrc: " Do a :vim on all listed buffers. To find "fopen": " :Bufvim /fopen/ function! s:bufvim( arg ) let a = "" let i = 1 while i <= bufnr("$") if buflisted(i) && bufname(i) != "" let a = a . ' ' . escape(bufname(i), ' \') endif let i = i + 1 endwhile exe "vim " . a:arg . a endfunction com! -nargs=1 Bufvim call bufvim( "" ) Thanks. Regards, Ben K. Developer http://benix.tamu.edu
Re: search within buffers
Thanks. By the way I'm seeing this error when I open the url: script:Can't open file: 'vs_scripts.MYI' (errno: 145) I guess it's from some maintenance work on mysql, but just in case. On Fri, 8 Dec 2006, Yegappan Lakshmanan wrote: Hi, On 12/8/06, Ben K. <[EMAIL PROTECTED]> wrote: Hi, Is there a way to do grep only within the open files (buffers)? I did :he grep and bufdo but it didn't seem to give me the option. You can try using the grep.vim plugin. You can download this plugin from: www.vim.org/scripts/script.php?script_id=311 This plugin provides the ":Bgrep" command to search for a pattern in all the open buffers. - Yegappan Regards, Ben K. Developer http://benix.tamu.edu
Re: search within buffers
Thanks. On Fri, 8 Dec 2006, A.J.Mechelynck wrote: Ben K. wrote: Hi, Is there a way to do grep only within the open files (buffers)? I did :he grep and bufdo but it didn't seem to give me the option. Thanks. Ben K. Developer http://benix.tamu.edu All the following is for Vim version 7 ONLY. To grep in all files named on the vim command-line, assuming no spaces in their names: :exe 'vimgrep /pattern/g' join(argv(), ' ') see :help :vimgrep :help join() :help argv() To grep in all loaded buffers it's (IIUC) more complicated: let buflist = [] let bufnr = 0 while bufnr < bufnr("$") let bufnr += 1 if buflisted(bufnr) let buflist += [ bufname(bufnr) ] endif endwhile exe 'vimgrep /pattern/g' join(buflist, ' ') Replace buflisted() by bufexists() to search also unlisted buffers. How to do the same if filenames can include spaces is left as an exercise to the user (it will be different for Unix shells or Dos shells). Best regards, Tony. Regards, Ben K. Developer http://benix.tamu.edu
search within buffers
Hi, Is there a way to do grep only within the open files (buffers)? I did :he grep and bufdo but it didn't seem to give me the option. Thanks. Ben K. Developer http://benix.tamu.edu
Re: question on gf and path
Thanks. On Sat, 2 Dec 2006, Marc Weber wrote: On Fri, Dec 01, 2006 at 10:30:26AM -0600, Ben K. wrote: Is there a way to make gf open "some.file" from this line? Include("/includes/some.file"); where the file is actually sitting under web server root, like /var/www/html/includes/some.file I tried adding "/var/www/html" to the :set path but vim will not recognize it. /var/www/html/; was the same. Basically I'm looking for a way to add "prefixes". On the same note, would it be possible to let gf open /var/www/html/includes/some.file when I gf on this string http://somehost.com/includes/some.file or by defining a new command (say wf)? That's exactly where you can use my little script (which will isntall some dependencies, too) Just add this into your ftplgugin/filetype.vim file: -- >8 -- >8 filetype_sourced.vim -- >8 -- >8 -- >8 noremap gf :call vl#ui#navigation#gfHandler#HandleGF() call vl#ui#navigation#gfHandler#AddGFHandler("[matchstr(expand(''),'Include(\"\\zs[^\"].*\\ze\")')]") -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< -- 8< and source the installer file http://www.mawercer.de/marcweber/vim/vimlib/installers/vimlib_gfhandler_installer_sourceme.vim (Don't be afraid. The installer will ask for confirmation before doing anything.) I would suggest saving it to another directory (eg ~/.vimlib or ~/.vim_gf) and adding this folder to your runtimepath. set runtimepath+=~/.vimlib Then its easy to remove it again if you don't like it. I think you can see that [matchstr ... does the interesting thing which is getting the file from under the cursor by calling expand('') and remvoving the Include text. You have to adjust it the way you like. You have to write your own code which removes /includes and adds /var/www/html/includes/ which would look like this: call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes'.matchstr(expand(''),'Include(\"/includes\\zs[^\"].*\\ze\")')]") You can even add different include directories: call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes1' call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes2' call vl#ui#navigation#gfHandler#AddGFHandler("['/var/www/html/includes3' Then you'll be asked which file to open if it doesn't exist. Unfortunately the documentation (http://www.mawercer.de/marcweber/vim/vimlib/docs/vl_ui_navigation_gfHandler_vim.html) isn't up to date because vim segfaults while creating it and I don't have the time to find the code causing it. If something doesn't work drop me a mail. HTH Marc Weber Regards, Ben K. Developer http://benix.tamu.edu
Re: question on gf and path
It worked and I appreciate the simpleness. Thanks. On Fri, 1 Dec 2006, Tim Chase wrote: Is there a way to make gf open "some.file" from this line? Include("/includes/some.file"); where the file is actually sitting under web server root, like /var/www/html/includes/some.file I tried adding "/var/www/html" to the :set path but vim will not recognize it. /var/www/html/; was the same. Basically I'm looking for a way to add "prefixes". Assuming you have "/var/www/html" in your path, the following pairing should help you out: nnoremap gf :exec 'e ' . findfile(substitute(expand(''), '^/*','','')) nnoremap f :exec 'sp ' . findfile(substitute(expand(''), '^/*','','')) The findfile() function also takes an extra parameter if you want to refrain from munging your actual path, you could do something like findfile(..., &path.',/var/www/html') On the same note, would it be possible to let gf open /var/www/html/includes/some.file when I gf on this string http://somehost.com/includes/some.file or by defining a new command (say wf)? A similar transformation could tweak the previous, something like substitute(expand(...), '^\(http://[^/]/\)\=/*','','') would strip off leading slashes and leading protocol+host. (that regexp/substitute() is untested, but should be approx. correct, save for possible needs to escape the "\" characters) Alternatively, you could map it to gf and f to maintain the original meanings, but create new mappings to provide the additional functionality. HTH, -tim Regards, Ben K. Developer http://benix.tamu.edu
Re: question on gf and path
I'll check it out. Thanks. On Fri, 1 Dec 2006, Yegappan Lakshmanan wrote: Hi, On 12/1/06, Ben K. <[EMAIL PROTECTED]> wrote: Is there a way to make gf open "some.file" from this line? Include("/includes/some.file"); where the file is actually sitting under web server root, like /var/www/html/includes/some.file I tried adding "/var/www/html" to the :set path but vim will not recognize it. /var/www/html/; was the same. Basically I'm looking for a way to add "prefixes". On the same note, would it be possible to let gf open /var/www/html/includes/some.file when I gf on this string http://somehost.com/includes/some.file or by defining a new command (say wf)? You may want to include look into the 'includeexpr' and 'include' options. In Vim7, the 'include' option supports the "\zs" and "\ze" regular expression atoms, so you can use this change the matched text. - Yegappan Regards, Ben K. Developer http://benix.tamu.edu
Re: question on gf and path (fwd)
Actually, making gf accept the change in buffer will help only in special cases. Since I can be in /AliasedDir/x/y/x or /DocRoot/a/b/c/d/e/f/ and still call /DocRoot/includes/some.file using include("/includes/some.file") ... and it's a frequent case. In this case include("__some_modification_to__... _includes/some.file") will not necessarily be convenient. But thanks anyway. Ben K. Developer http://benix.tamu.edu
Re: question on gf and path
On Fri, 1 Dec 2006, Yakov Lerner wrote: Also can be that leading '/' in "/includes/some.file" makes vim believe this is absolute pathname. Try on Include("includes/some.file"); That's where I want to get advice... That notation using DocumentRoot like "/includes/some.file" is universal in web applications. If I can temporarily change the buffer and trick vim to think the line is now Include("includes/some.file") it's somewhat OK, but gf requires me to actually save the source file before it will accept the change from "/includes..." to "includes". There are situations I cannot save it, e.g. if the source is on a live server, during the time this is changed, the web server will not be able to find the file and will generate errors. It's ok if there's no way as is. I'll prehaps look at recompiling. Thanks. Ben K. Developer http://benix.tamu.edu
question on gf and path
Is there a way to make gf open "some.file" from this line? Include("/includes/some.file"); where the file is actually sitting under web server root, like /var/www/html/includes/some.file I tried adding "/var/www/html" to the :set path but vim will not recognize it. /var/www/html/; was the same. Basically I'm looking for a way to add "prefixes". On the same note, would it be possible to let gf open /var/www/html/includes/some.file when I gf on this string http://somehost.com/includes/some.file or by defining a new command (say wf)? Thanks. Ben K. Developer http://benix.tamu.edu
Re: search between two brackets
I have a long source code consisting of multiple modules wrapped in {}. Sometimes I use "*" to find the next match. But I'd like to search only within the same module or class that I started from. (which is wrapped inside sub ... {}) Thanks all. It should be sufficient. I am not sure exactly what sort of highlighting you want. Since my purpose was "not" to go astray to another module, I just wondered if there can be some visual indication to tell me that I'm still in my { module }. Like flipping foreground and background of the rest of the file, or dimming the colors, etc. But the provided answer should be sufficient. Regards, Ben K. Developer http://benix.tamu.edu
search between two brackets
Vimmers, I have a long source code consisting of multiple modules wrapped in {}. Sometimes I use "*" to find the next match. But I'd like to search only within the same module or class that I started from. (which is wrapped inside sub ... {}) In the following example, I'd like * or "n" to at least let me know that I crossed the module boundary for instance 3. Or not match it at all. If there's a way to highlight between the matching brackets (open/close), it would also be helpful, even if it doesn't allow highlighting of the searched pattern. sub aaa { ... instance 1 # Begin by "*" ... instance 2 # This is OK. ... } sub bbb { ... instance 3 # This is not what I want ... } Is there a simple way to do it? Thanks. Ben K. Developer http://benix.tamu.edu
RE: gf question
On Thu, 26 Oct 2006, Max Dyckhoff wrote: set isfname-== On Thu, 26 Oct 2006, Russell Bateman wrote: progname="/usr/local/txserver" OK both worked. Thanks. I found from the help that visually selecting and then doing gf also works thought it's a bit cumbersome. Wrapping the RHS with "" seems a better style. Most of the existing shell scripts (supplied by vendors) don't seem to honor that. Thanks Ben K. Developer http://benix.tamu.edu
gf question
Vimmers, I find gf very convenient, but with shell scripts, I'd like a different behavior: In shell scripts, there should be no spaces around "=". progname=/usr/local/txserver Then if I do gf on /usr/local/txserver, vim thinks the whole line (including progname=) is the pathname and gives me a not-found error. Is there a way to change that? Regards, Ben K. Developer http://benix.tamu.edu
vimdiff same bg and fg colors
Thanks Tony and Brady. I got sufficient answers. Happy vimming, Ben K. Developer http://benix.tamu.edu
follow up - colorscheme on vimdiff
The previous setting gave me white on white in some cases so I added guibg. highlight cConstant ctermfg=white ctermbg=grey guifg=white guibg=grey highlight cString ctermfg=white ctermbg=grey guifg=white guibg=grey highlight cNumber ctermfg=white ctermbg=grey guifg=white guibg=grey Regards, Ben K. Developer http://benix.tamu.edu
color schemes same fg and bg on vimdiff
Vimmers, I use vimdiff in gnome-terminal and sometimes in GUI, but the default color scheme (I found somehow it's not the same as the "colors/default.vim") sometimes use the same color for both foreground and background. Most of the color schemes in the colors directory do the same (same or indiscernible fg and bg colors) I spent some time and found corresponding set the following for the c files I have at hand, so I add these lines in my .vimrc, but I guess I'll have to do the same for php and other languages I use. highlight cConstant ctermfg=white guifg=white highlight cString ctermfg=white guifg=white highlight cNumber ctermfg=white guifg=white Do these have something in common? I had to try a few times to find what they are... P.S.) Also, :help colorscheme says :colo[rscheme] {name} Load color scheme {name}. This searches 'runtimepath' for the file "colors/{name}.vim. The first one that is found is loaded. but somehow, none of my installations do that, if the first means alphabetically the first. Probably it'll be understandable if I look at the code, but just wanted to note here - in case someone has a ready answer. Happy vimming, Ben K. Developer http://benix.tamu.edu
Re: Search and Replace with a Regular Expression
For example, let's say I have some dates that look like this: 7-30-05 12-5-2006 10-2-06 What I'd like to end up with is this... 07/30/2005 12/05/2006 10/02/2006 Sorry this is a bit off topic: I just wanted to add that ms excel, or some databases, will recognize the data correctly, even if you supply them as is. You will not need to do any search and replace. At least, postgresql correctly recognizes the three examples you gave. Regards, Ben K. Developer http://benix.tamu.edu
Re: Select prev visual block + 5 hor pos more
With gv you can re-select the previous visual block. Is it possible to give a horizontal shift with it? Like + or - 5? Could you cut away the finished block and paste to another place, and do gv again? Not quite reliable, but may work. Regards, Ben K. Developer http://benix.tamu.edu
Re: Deleting a repetative pattern
How do I deleted per line all the 'odd' 200? If there are repeated 200 200 200 200 ... :%s/200\s\+200\s\+/200 zzz /g Regards, Ben K. Developer http://benix.tamu.edu
Re: Deleting a repetative pattern
How do I deleted per line all the 'odd' 200? :%s/ 200 200 200 / 200 zzz 200 /g :%s/ 200 / /g :%s/zzz/200/g Just an idea... Regards, Ben K. Developer http://benix.tamu.edu
Re: Sorting a file
Apologies, this email should have been a reply to the original post rather than to yours. == Line 18 | 123 Line 18 | 641 Line 19 |abc Line 19 | GHI Line 332 |xyz Line 332 | vcx Hi, an alternative FWIW :sort :g!/^Line/d Ben K. Developer http://benix.tamu.edu
Re: Sorting a file
Line 18 | 123 Line 18 | 641 Line 19 |abc Line 19 | GHI Line 332 |xyz Line 332 | vcx Hi, an alternative FWIW :sort :g!/^Line/d Regards, Ben K. Developer http://benix.tamu.edu
basic question: quick split like awk
Hi, Is there a way to split a line automatically like awk would? Given "A quick brown fox jumped over ", awk '{print $3}' ... ==> brown or like in perl split(':',$line)... I'd like to do within vim something like :s/{some notation}/\3 without having to define the pattern :s/\(\S\+\) \(\S\+\) \(\S\+\) ... /\3 ==> brown using white space, and if needed, by defining my own separator Thanks. Ben K. Developer http://benix.tamu.edu