Tuesday, September 30, 2008

SSH Remote Connections via Config

Thorsten has contributed the following ssh tip. Thanks Thorsten!

You wrote about ssh connects via gnome terminal:

http://dailyvim.blogspot.com/2008/09/gnome-terminal-tips.html

I'm using the config file of ssh to achieve the same goal:

just put the file "config" in your .ssh directory (chmod 600) with the
following lines:


host mysshhost
user root
identityfile /root/.ssh/my_ssh_key.ssh
port 34021
hostname 127.0.0.1
localforward 10100 localhost:10100
ForwardX11 yes


then back at the command line just try:

myhost:/ # ssh mysshhost

and voila, welcome to your ssh connected system (even the
bash-completion works with the config file, just do a ssh )

Monday, September 29, 2008

Question: Browsing Remote Filesystems

A Daily Vim reader asks the following question:

Travis, the feature that has me married to Kate (KDE text editor) is the file browser with bookmarks built in. Kate allows users to browse remote filesystems from within the app just like they could browse the local filesystem in a file manager. Furthermore, there is a bookmarks feature where users can bookmark specific directories / files on remote servers. Anythink like those two features in VIM?

Thanks!

Anybody have any ideas on this? I have a few ideas, but I'll wait and see if anybody else has a suggestions first.

Thursday, September 25, 2008

Whatprovides

If you're using a RedHat derivative that utilizes yum as it's package manager, you can use the `whatprovides' command to see what package provides a specific file.

Example:

yum whatprovides /usr/bin/vim

... grab a coffee ...

vim-enhanced.x86_64 1:6.3.046-0.40E.7.cent base
Matched from:
/usr/bin/vim

Debian derivatives provide a similar functionality via the apt-file package.

# sudo apt-get install apt-file
# sudo apt-file update
$ apt-file search /usr/bin/diff
diff: /usr/bin/diff

Friday, September 19, 2008

Unhighlight Current Search

If you want to un-highlight the currently highlighted search terms, issue the following command.

:noh

Friday, September 12, 2008

Search Register

You can manually push a value into the search register using the following syntax.

let @/='Some String'

This is particularly nice for script hacking when you want to highlight a group of strings in the current buffer.

Vimgrep Without Object Names

My friend Chris (Vim user extraordinaire) has contributed the following tip. It looks like it could be quite useful to any Java hackers in the crowd.

I constantly want to use :vimgrep to find usages/references to certain object types in my java code. However, when I :vimgrep for the object name, it (naturally) matches all of the 'import' statements, too. I've known for awhile that there was an idiom in the regex syntax to negate a previous atom (in this case, the 'import' at the beginning of the line) but I've never found a way to phrase it that works. Here it is:

.*ObjectName\&^\(import\)\@!

This matches any line meeting the following two constraints:
1) contains anything (.*) followed by ObjectName
2) starts (^) with something which isn't 'import' (\(import\)\@!)

the \@! says, match if the preceding atom does not match here -- since we put ^\(import\) this means match when the first thing in the line isn't import.

There may be better ways to do this, but it's the first I've found and I'm using it like crazy now... Enjoy!

Thanks Chris!

Question: Highlight From Insert?

Iyo writes:

"I offten do some coding in Vim and I miss an feature that will highlight
the word I`m writing in that moment and other same words. (It is mainly
for variables - sometimes I switched letters and afterwards I`m looking
for mistake for a quite long time. The NetBeans IDE has a feature like this.

I know about * but it`s for search in the text. I`m looking for something that work automaticly in insert mode."



Answer:

You can use ctrl-o from inside of insert mode to enter a command, but to me typing ctrl-o * while I'm hammering out some code feels awfully cumbersome. There's also the negative side-effect that * jumps forward, so you'd lose cursor position, which would assuredly interrupt workflow. Instead, I'd just define a simple mapping along the lines of the following.

imap <F2> <Esc>#*A

So, you're inside insert mode, you just typed a word, and you want to match all occurrences. You would simply hit F2, and it would backward match the word nearest the cursor. This has the negative side effect of jumping backwards; thereby, losing cursor position. To compensate, we add a * to jump forward followed by "A" to return to insert mode and insure you're at the end of the line. Obviously, you can substitute any keybinding you want for F2.

This seems to work well on my machine; although, there might be more optimal solutions. If anybody has one, feel free to share.