Automatically positioning cursor when opening a file
I'm having trouble automatically positionning the cursor when opening an existing file. Basically, all of my files have a standard header (copyright blurb, etc.), and I'd like to have the cursor positionned after it at the start of editing. When opening a new file, I have the following in my .vimrc: autocmd BufNewFile *.cc 0r! $HOME/bin/cc-init % autocmd BufNewFile *.hh 0r! $HOME/bin/hh-init % autocmd BufNewFile *.sh 0r! $HOME/bin/sh-init % autocmd BufNewFile *.mk,GNUmakefile 0r! $HOME/bin/gmake-init % autocmd BufNewFile *.cc,*.hh,*.sh,*.mk,GNUmakefile +1d autocmd BufNewFile *.cc,*.hh,*.sh,*.mk,GNUmakefile ?^$? This inserts the header (and a trailer with emacs and vim commands, e.g. for filetype, tabstop etc.), and leaves the cursor positionned at the last empty line (which happens to be after the header for a just created file, or after the include guards in the case of a .hh file). I'd like something similar when I open the file, but autocmd BufReadPost *.cc,*.hh,*.sh,*.mk,GNUmakefile :1 autocmd BufReadPost *.cc,*.hh,*.sh,*.mk,GNUmakefile /^$/ leaves the cursor at the top. Changing the event to BufWinEnter or BufEnter works well when I open the file, but causes the cursor position to be lost if I leave the window, then later come back to it. From the documentation, I'd expect BufReadPost to work, but it doesn't. Also, while I'm at it: is there any reason why 1G doesn't work, but :1 does, to start from a known point. -- James Kanze (GABI Software)mailto:[EMAIL PROTECTED] Conseils en informatique orient�e objet/ Beratung in objektorientierter Datenverarbeitung 9 place S�mard, 78210 St.-Cyr-l'�cole, France, +33 (0)1 30 23 00 34
Re: run make! from subdirs
On 2/20/07, Ilia N Ternovich [EMAIL PROTECTED] wrote: Someone noticed that if I add this line into .vimrc: autocmd BufEnter * :cd %:p:h I'll be able to run :make and vim will automatically look at the directory where currently opened file is located for Makefile. But if I have directory structure like this: [d]ProjectDir main.cpp Makefile [dir]SrcDir1 file1.cpp [dir]SrcDir2 file2.cpp this command do not work. Makefile is located in root ProjectDir and if I open for example file1.cpp from SrcDir1, vim can't locate Makefile and I HAVE TO SWITCH TO ANOTHER BUFFER which contains some source from ProjectDir in order to compile program... Is there any opportunity to solve this situation. I have to recompile project very often while debug sessions, and there is really huge dir hierarchy... Setting VIMINIT to something like: source $HOME/.vimrc | autocmd BufEnter * :cd $PROJECTROOT should do the trick. You can either define a shell function to turn this on and off, or use an alias (or a simple shell script) to invoke vim with something like: VIMINIT=source $HOME/.vimrc | autocmd BufEnter * :cd $PROJECTROOT vim $@ so you have a general command vim, and a project specific command projectvim (or whatever). Alternatively, you can define a shell script pmake (for project make) which does the cd, then executes the real make. Then set makeprg=pmake. -- James Kanze (GABI Software) email:[EMAIL PROTECTED] Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Re: Web-based editing [Was :wq vs ZZ]
On 2/16/07, Cameron Simpson [EMAIL PROTECTED] wrote: On 15Feb2007 15:30, James Kanze [EMAIL PROTECTED] wrote: | On 2/15/07, Bram Moolenaar [EMAIL PROTECTED] wrote: | I'm using It's All Text! now. Just had to create a shell script to | start gvim, because it doesn't allow you to give arguments to the | command. I'm using this (on Unix, obviously): | #!/bin/sh | gvim -f $@ | I can't seem to get it to work; gvim comes up all right, but as | if it was started without any file arguments. Adding an echo to | the shell script shows that in fact, it isn't being passed any | arguments. Is there something special I have to do in the | preferences of It's All Text! to tell it how to pass a | filename. Um, no? It should just work. IAT only lets you supply the path to the edit command, so it must pass the file as an argument - it seems to for my setup. That's what I would have thought. You're certain the script gets not arguments - you're echoing $# and $* ? My script, exactly: #! /bin/sh export DISPLAY=padev054:0.1 echo Options: $@ $HOME/tmp/firefoxVim.log $HOME/gnu/i686/bin/gvim -f $@ Having pressed the edit button, the vim window is open: $ cat ~/tmp/firefoxVim.log Options: $ ps -ef | egrep -i vim jakan20652 17342 0 09:57 pts/400:00:00 /bin/sh /home/team02/jakan/bin/firefoxVim jakan20655 20652 0 09:57 pts/400:00:00 /home/team02/jakan/gnu/i686/bin/gvim -f (My script is in $HOME/bin/firefoxVim.) FWIW: firefox is running on a Linux 2.6.9 kernel (Redhat, I think) on an Intel based PC. The X Server (machine padev054) is a Sun Sparc under Solaris 2.8, and I've got synergy managing the keyboard and the mouse (server on the Sparc). Off hand, I don't see how any of that could make a difference (except maybe the machine on which firefox is running). Firefox is version 2.0.0.1 (en-US version), and It's All Text! is version 0.3.3. I have no idea where to start looking beyond that. For the moment, I'm still copy/pasting, as I did before. | Store this in a file, make it executable, and set it from | Tools/Add-ons/It's All Text/Preferences | The plugin can be found here: | https://addons.mozilla.org/firefox/4125/ | Warning: If you set the preferences to use Vim firefox gets stuck. | Not if you've started it from an xterm; vim comes up in the | xterm. (But Firefox does hang until you exit vim.) That's surprising. After a few more trials: it doesn't completely hang, but some things don't work. In particular, If you try to close the window, it doesn't close. -- James Kanze (GABI Software) email:[EMAIL PROTECTED] Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Re: Web-based editing [Was :wq vs ZZ]
On 2/15/07, Bram Moolenaar [EMAIL PROTECTED] wrote: I'm using It's All Text! now. Just had to create a shell script to start gvim, because it doesn't allow you to give arguments to the command. I'm using this (on Unix, obviously): #!/bin/sh gvim -f $@ I can't seem to get it to work; gvim comes up all right, but as if it was started without any file arguments. Adding an echo to the shell script shows that in fact, it isn't being passed any arguments. Is there something special I have to do in the preferences of It's All Text! to tell it how to pass a filename. Store this in a file, make it executable, and set it from Tools/Add-ons/It's All Text/Preferences The plugin can be found here: https://addons.mozilla.org/firefox/4125/ Warning: If you set the preferences to use Vim firefox gets stuck. Not if you've started it from an xterm; vim comes up in the xterm. (But Firefox does hang until you exit vim.) -- James Kanze (GABI Software)mailto:[EMAIL PROTECTED] Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Strange behavior when auto-indenting C++ code
I'm getting different formatting results when auto-indenting than when I use the = command. Basically: In order to be sure that there isn't some side effect from some of my other configuration stuff, I invoke vim with: vim -N -u NONE -U NONE toto.cc Following that, I enter the following commands: :set sw=4 :set cinoptions=(0U0 :set cindent I then enter input mode, and enter: Foo::Foo( int i, double d ) : i( i ) , d( ::func( d ) ) { } What appears on the screen (and in the file) is what I want: Foo::Foo( int i, double d ) : i( i ) , d( ::func( d ) ) { } Now, however, I select the entire code (using V), and enter =, to reformat the function. I then get: Foo::Foo( int i, double d ) : i( i ) , d( ::func( d ) ) { } For some reason, the first line is indented, and the second isn't. Where as I would expect that both forms of indenting would give the same results. Any ideas what I'm doing wrong? (FWIW: I'm using vim 6.4, compiled with just about all of the available options, on a Sun Sparc under Solaris 2.8. I've compiled it with the X11-Motif GUI, but the above behavior is observable even in non-GUI mode.) -- James Kanze (GABI Software) email:[EMAIL PROTECTED] Conseils en informatique orientée objet/ Beratung in objektorientierter Datenverarbeitung 9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34