Vim Tips Wiki
No edit summary
 
(Keep shebang line)
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 
{{review}}
 
{{review}}
  +
{{TipImported
{{Tip
 
 
|id=451
 
|id=451
  +
|previous=450
|title=KDE Konsole renameSession to edited file name
 
  +
|next=452
|created=March 28, 2003 7:21
+
|created=March 28, 2003
 
|complexity=intermediate
 
|complexity=intermediate
|author=warb--AT--tgf.tc.faa.gov
+
|author=warb
 
|version=6.0
 
|version=6.0
 
|rating=37/15
 
|rating=37/15
  +
|category1=Integration
|text=
 
  +
|category2=
In Kde the renameSession will set the Konsole name. Add this to your
 
 
}}
 
In KDE3 the renameSession will set the Konsole name. Add this to your [[vimrc]] file to name the session after the edited file.
 
autocmd BufReadPost * :silent !dcop $KONSOLE_DCOP_SESSION renameSession %
   
 
This one set the title to the current working dirctory when you leave vim.
.vimrc file to name the session after the edited file.
 
 
autocmd VimLeavePre * :silent !dcop $KONSOLE_DCOP_SESSION renameSession $PWD
   
  +
In KDE4 the qdbus will set the Konsole tab name. Create a script in your $PATH(for example: $HOME/bin) named as update_konsole_tab:
  +
<pre>
  +
#/bin/sh
  +
if [ "CHK$KONSOLE_DBUS_SESSION" == "CHK" ];then
  +
exit 0
  +
fi
   
  +
OLD_FORMAT="%d : %n"
  +
QDBUS_COMMAND="qdbus org.kde.konsole $KONSOLE_DBUS_SESSION"
   
  +
if [ "CHK$1" == "CHKset" ];then
autocmd BufReadPost * :silent !dcop $KONSOLE_DCOP_SESSION renameSession %
 
  +
$QDBUS_COMMAND org.kde.konsole.Session.setTabTitleFormat \
  +
0 "$2" 1>/dev/null 2>/dev/null
   
  +
fi
   
  +
if [ "CHK$1" == "CHKclean" ];then
}}
 
  +
$QDBUS_COMMAND org.kde.konsole.Session.setTabTitleFormat \
  +
0 "$OLD_FORMAT" 1>/dev/null 2>/dev/null
  +
fi
  +
</pre>
   
  +
Then add these lines into your [[vimrc]]:
== Comments ==
 
  +
<pre>
This one set the title to the current working dirctory when you leave vim.
 
  +
autocmd BufReadPost * :silent !update_konsole_tab set 'vim: %:t'
  +
autocmd VimLeavePre * :silent !update_konsole_tab clean
  +
</pre>
 
==Comments==
 
Dan thanks for the vim help, however I do not use konsole.
 
So I modified my .tcshrc with this:
   
  +
<pre>
autocmd VimLeavePre * :silent !dcop $KONSOLE_DCOP_SESSION renameSession $PWD
 
 
# This makes it possible to make vim automagically set the date and time
 
# in the title bar.
  +
#
 
alias vimdate '/bin/date "+%A, %B %e, %Y Time: %H:%M"'
 
setenv mydate `vimdate`
 
alias vi 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd`'
  +
</pre>
   
 
then I read the how to for setting or unsetting the title in vim, so I set my .vimrc with this:
   
  +
<pre>
 
 
:auto BufEnter * let &titlestring = $USER . " on " . hostname() . " :
me again
 
 
\ Viming: " . expand("%:p") . " Date: " . $mydate
, March 28, 2003 13:04
 
 
:set title titlestring=%<%F%=%l/%L-%P titlelen=70
----
 
  +
</pre>
Dan thanks for the vim help, however I do not use konsole.
 
So I modified my .tcshrc with this:
 
&#35; This makes it possible to make vim automagically set the date and time
 
&#35; in the title bar.
 
&#35;
 
alias vimdate '/bin/date "+%A, %B %e, %Y Time: %H:%M"'
 
setenv mydate `vimdate`
 
alias vi 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd`'
 
 
then I read the how to for setting or unsetting the title in vim,
 
so I set my .vimrc with this:
 
:auto BufEnter * let &amp;titlestring = $USER . " on " . hostname() . " :
 
\ Viming: " . expand("%:p") . " Date: " . $mydate
 
:set title titlestring=%&lt;%F%=%l/%L-%P titlelen=70
 
   
 
This with the .tcshrc mod will give you your name on machine Viming : filename : date and time.
 
This with the .tcshrc mod will give you your name on machine Viming : filename : date and time.
   
lamba--AT--faatc.com
 
, April 8, 2003 23:19
 
 
----
 
----
 
I might not always use kde, so I have my xterm do my title work for me.
great tip!
 
 
My .tcshrc for my xterms, looks like this:
  +
<pre>
 
### ---------------------------------------------------------------
 
# This is where cd is overloaded and it adjusts the prompt.
  +
#
 
# cds: change directory hybrid queueish stack
 
set cds = ( $HOME )
  +
#
 
alias cd 'if ( ${#cds} >= 4 ) shift cds;\\
 
chdir \!*;\\
 
setprompt;\\
 
set cds = ( $cds $cwd );\\
 
echo $cds'
  +
#
 
alias lastdir 'if ( ${#cds} <= 1 ) set cds = ( $cds $cwd );\\
 
@ idx = ${#cds} - 1;\\
 
chdir $cds[$idx];\\
 
setprompt;\\
 
set cds = ( $cds[1-$idx] );\\
 
echo $cds;\\
 
unset idx'
  +
#
 
setprompt
  +
#
 
### ---------------------------------------------------------------
  +
#
  +
#
 
### ---------------------------------------------------------------
 
# This is where the title bar of the xterm is set.
  +
#
 
alias date '/bin/date "+%A, %B %e, %Y Time: %H:%M:%S"'
  +
#
 
if ($?tcsh) then
 
# set prompt="$host{`whoami`}%\!: "
  +
#
 
if ($?term) then
 
alias cwdcmd 'echo -n "^[]2;" "$USER on $host : $cwd `date`^G"'
 
cwdcmd
 
endif
 
#else # regular csh
 
# set prompt="$hostnm{`whoami`}\!: "
 
# if ($term == xterm) echo -n "^[]0;$hostnm^G"
 
endif
  +
#
 
### ---------------------------------------------------------------
  +
</pre>
   
 
Note: In the alias cwdcmd line, after the `echo -n "^[]2;" the ^[ is a control h, I think.
gregf--AT--bigtimegeeks.com
 
, April 9, 2003 9:31
 
----
 
Is there a smart way to set the title of the session to QString::NULL if on
 
leaves vim? Because with this DCOP-call the session will keep the name
 
until you a) close the session or b) edit another file in vim...
 
   
 
This is why I aliases vi to 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd`
cniehaus--AT--kde.org
 
 
When I do a cd `pwd` it automatically changes my title bar to:
, April 11, 2003 15:11
 
 
me on machine : $PWD day, date, Time: time.
----
 
Hi,
 
   
 
This works with xterm, aterm, wterm, kterm, rxvt, and konsole.
I might not always use kde, so I have my xterm do my title work for me.
 
 
Please feel free to email me if you would like me to send you a copy.
My .tcshrc for my xterms, looks like this:
 
&#35;&#35;&#35; ---------------------------------------------------------------
 
&#35; This is where cd is overloaded and it adjusts the prompt.
 
&#35;
 
&#35; cds: change directory hybrid queueish stack
 
set cds = ( $HOME )
 
&#35;
 
alias cd 'if ( ${&#35;cds} &gt;= 4 ) shift cds;\\
 
chdir \!*;\\
 
setprompt;\\
 
set cds = ( $cds $cwd );\\
 
echo $cds'
 
&#35;
 
alias lastdir 'if ( ${&#35;cds} &lt;= 1 ) set cds = ( $cds $cwd );\\
 
--AT-- idx = ${&#35;cds} - 1;\\
 
chdir $cds[$idx];\\
 
setprompt;\\
 
set cds = ( $cds[1-$idx] );\\
 
echo $cds;\\
 
unset idx'
 
&#35;
 
setprompt
 
&#35;
 
&#35;&#35;&#35; ---------------------------------------------------------------
 
&#35;
 
&#35;
 
&#35;&#35;&#35; ---------------------------------------------------------------
 
&#35; This is where the title bar of the xterm is set.
 
&#35;
 
alias date '/bin/date "+%A, %B %e, %Y Time: %H:%M:%S"'
 
&#35;
 
if ($?tcsh) then
 
&#35; set prompt="$host{`whoami`}%\!: "
 
&#35;
 
if ($?term) then
 
alias cwdcmd 'echo -n "^[]2;" "$USER on $host : $cwd `date`^G"'
 
cwdcmd
 
endif
 
&#35;else &#35; regular csh
 
&#35; set prompt="$hostnm{`whoami`}\!: "
 
&#35; if ($term == xterm) echo -n "^[]0;$hostnm^G"
 
endif
 
&#35;
 
&#35;&#35;&#35; ---------------------------------------------------------------
 
   
 
Also I run Debian, so there for everything is generic; so I had to figure out how to
Note: In the alias cwdcmd line, after the `echo -n "^[]2;" the ^[ is a control h,
 
I think.
 
 
This is why I aliases vi to 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd`
 
When I do a cd `pwd` it automatically changes my title bar to:
 
me on machine : $PWD day, date, Time: time.
 
 
This works with xterm, aterm, wterm, kterm, rxvt, and konsole.
 
Please feel free to email me if you would like me to send you a copy.
 
 
Also I run Debian, so there for everything is generic; so I had to figure out how to
 
 
modify/customize everything with dot files; this way I learn more by doing it myself.
 
modify/customize everything with dot files; this way I learn more by doing it myself.
   
 
----:
lamba--AT--faatc.com
 
, April 11, 2003 22:53
 
----
 
If you want to change you tab labels in KDE's konsole check this out:
 
http://www.kde-look.org/content/show.php?content=6976
 
 
semovrs--AT--concord.edu
 
, February 18, 2006 18:06
 
----
 
<!-- parsed by vimtips.py in 0.456010 seconds-->
 

Revision as of 09:22, 14 October 2014

Tip 451 Printable Monobook Previous Next

created March 28, 2003 · complexity intermediate · author warb · version 6.0


In KDE3 the renameSession will set the Konsole name. Add this to your vimrc file to name the session after the edited file.

autocmd BufReadPost * :silent !dcop $KONSOLE_DCOP_SESSION renameSession %

This one set the title to the current working dirctory when you leave vim.

autocmd VimLeavePre * :silent !dcop $KONSOLE_DCOP_SESSION renameSession $PWD

In KDE4 the qdbus will set the Konsole tab name. Create a script in your $PATH(for example: $HOME/bin) named as update_konsole_tab:

#/bin/sh
if [ "CHK$KONSOLE_DBUS_SESSION" == "CHK" ];then
    exit 0
fi

OLD_FORMAT="%d : %n"
QDBUS_COMMAND="qdbus org.kde.konsole $KONSOLE_DBUS_SESSION"

if [ "CHK$1" == "CHKset" ];then
    $QDBUS_COMMAND org.kde.konsole.Session.setTabTitleFormat \
        0 "$2" 1>/dev/null 2>/dev/null

fi

if [ "CHK$1" == "CHKclean" ];then
    $QDBUS_COMMAND org.kde.konsole.Session.setTabTitleFormat \
        0 "$OLD_FORMAT" 1>/dev/null 2>/dev/null
fi

Then add these lines into your vimrc:

autocmd BufReadPost * :silent !update_konsole_tab set 'vim: %:t'
autocmd VimLeavePre * :silent !update_konsole_tab clean

Comments

Dan thanks for the vim help, however I do not use konsole. So I modified my .tcshrc with this:

# This makes it possible to make vim automagically set the date and time
# in the title bar.
#
alias vimdate '/bin/date "+%A, %B %e, %Y Time: %H:%M"'
setenv mydate `vimdate`
alias vi 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd`'

then I read the how to for setting or unsetting the title in vim, so I set my .vimrc with this:

:auto BufEnter * let &titlestring = $USER . " on " . hostname() . " :
 \ Viming: " . expand("%:p") . " Date: " . $mydate
:set title titlestring=%<%F%=%l/%L-%P titlelen=70

This with the .tcshrc mod will give you your name on machine Viming : filename : date and time.


I might not always use kde, so I have my xterm do my title work for me. My .tcshrc for my xterms, looks like this:

### ---------------------------------------------------------------
# This is where cd is overloaded and it adjusts the prompt.
#
# cds: change directory hybrid queueish stack
set cds = ( $HOME )
#
alias cd 'if ( ${#cds} >= 4 ) shift cds;\\
 chdir \!*;\\
 setprompt;\\
 set cds = ( $cds $cwd );\\
 echo $cds'
#
alias lastdir 'if ( ${#cds} <= 1 ) set cds = ( $cds $cwd );\\
 @ idx = ${#cds} - 1;\\
 chdir $cds[$idx];\\
 setprompt;\\
 set cds = ( $cds[1-$idx] );\\
 echo $cds;\\
 unset idx'
#
setprompt
#
### ---------------------------------------------------------------
#
#
### ---------------------------------------------------------------
# This is where the title bar of the xterm is set.
#
alias date '/bin/date "+%A, %B %e, %Y Time: %H:%M:%S"'
#
if ($?tcsh) then
# set prompt="$host{`whoami`}%\!: "
#
 if ($?term) then
 alias cwdcmd 'echo -n "^[]2;" "$USER on $host : $cwd `date`^G"'
 cwdcmd
 endif
#else # regular csh
# set prompt="$hostnm{`whoami`}\!: "
# if ($term == xterm) echo -n "^[]0;$hostnm^G"
endif
#
### ---------------------------------------------------------------

Note: In the alias cwdcmd line, after the `echo -n "^[]2;" the ^[ is a control h, I think.

This is why I aliases vi to 'setenv mydate `vimdate` ; /usr/bin/vim \!* ; cd `pwd` When I do a cd `pwd` it automatically changes my title bar to:

me on machine : $PWD day, date, Time: time.

This works with xterm, aterm, wterm, kterm, rxvt, and konsole. Please feel free to email me if you would like me to send you a copy.

Also I run Debian, so there for everything is generic; so I had to figure out how to modify/customize everything with dot files; this way I learn more by doing it myself.


: