Vim

Make Vim Remember The Cursor’s Last Position After Exiting

So you edit a file in vim, you exit vim, and after a while you want to edit the file again. Many times it’s nice to have the cursor placed in the same position you left it. Here’s how to make this happen:

1. Add this to your ~/.vimrc file  (or to /etc/vim/vimrc to enable to the feature system-wide):

if has(“autocmd”)
au BufReadPost * if line(“‘\”") > 1 && line(“‘\”") <= line(“$”) | exe “normal! g`\”" | endif
endif
2. Check if the file ~/.viminfo  exists. If it doesn’t, create it:
touch ~/.viminfo

› Continue reading

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Thursday, September 9th, 2010 Vim 3 Comments

Fix Bad Indentation When Pasting Text To Vim

The problem is this:

You’re editing a buffer in vim, you copy a text (say, code snippet) from another place (say, Firefox), and you paste it inside vim (with middle mouse button / shift+insert). Most chances you won’t like what vim has just did to your text.

The problem is that vim doesn’t “know” that you’re actually pasting a text, and it thinks that you’re typing. So, if you have indentation enabled, it will re-indent your text.

The solution is simple: Whenever you want to paste text from outside vim into vim. Type this in command mode:

:set paste

So now vim knows that you’re going to paste text, and it will not touch it.

To disable the paste mode:

:set nopaste

As easy as that ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags:

Friday, July 16th, 2010 Vim No Comments

NumPad Problems When Using Vim over Tmux

I use vim as my main text editor, and I usually split the screen to edit a few buffers in parallel. To make resizing the windows faster, I mapped the numpad keys “/*-+” to resize the windows (see original vim tip here).

Recently, I started to use tmux, and opened vim, split the windows as usual, and tried to resize them. It didn’t work :)

I use Ubuntu 10.04 (Don’t remember the exotic name..), and I found that the latest tmux package in their repo is 1.1-1.

Anyway, version 1.1-1 has a bug with the NumPad. The solution is to download the source of tmux 1.2 and build it. It depends on libevent so you’ll need to get it first:

this is how to make it work:

1. sudo apt-get install libevent-dev

2. Get the source tarball of tmux from here.

3. tar xzf tmux-1.2.tar.gz

4. cd tmux-1.2

5. ./configure

6. make

7. sudo make install

Done. Now your life is better. Have fun ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , , ,

Saturday, July 3rd, 2010 Vim 2 Comments

Vim Tip – Convert Code To HTML

If you wrote some elegant code, and want to publish it as a HTML page, you can easily do that in vim:
In command mode, type this:

:TOhtml

A new buffer will be opened with the HTML source, just save it:

:wq

If the original file name was “mycode.c”, you’ll find a new file in the same directory named “mycode.c.html”. Open it with your favourite web browser.

Wow, not?
Have fun ;-)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Saturday, April 24th, 2010 Vim No Comments

Make Shell Scripts Executable By Default

If you use vim to write shell scripts, you might want to save the “chmod +x” command after saving the script.

By adding the following line to your vimrc file (typically, it’s located at ~/.vimrc), scripts will automatically become executable.

au BufWritePost * if getline(1) =~ “^#!” | if getline(1) =~ “/bin/” | silent !chmod a+x <afile> | endif | endif

(meaning, if the file includes #! with “/bin/” in the path, apply “chmod a+x” on this file).

via shell-fu.

Have fun ;)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , , ,

Saturday, September 26th, 2009 Vim No Comments

Edit The Command Line With Vim

This is a quick (and great) tip I found at Daily Vim:

Open a linux terminal, and type some (long) command.
Now type [ctrl]+[x] and then [ctrl]+[e]
The command should be moved now to a vim window.
Edit the command (fix typos, change parameters, etc..) and save.
The command will now be executed.
Enjoy ;)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: , ,

Monday, June 1st, 2009 Vim No Comments

Posting to WordPress from Vim

Hi,
I just discovered a cool vim plugin called Vimpress which allows one to post directly from vim.
Actually, this post is published using Vimpress.
I think I’ll be using it for short/simple posts.

That’s it, c ya :)

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit Post to StumbleUpon

Tags: ,

Friday, February 20th, 2009 Short Posts No Comments
my email
my photo
Hi,
My name is Amir Watad. I have a BSc. in biomedical engineering from The Biomedical Engineering school , Technion , Israel, and a BSc. in electrical engineering from The Electrical Engineering school , Technion , Israel.
I'm a Verification Engineer in Mellanox Technologies Ltd.
I love Linux, the Command Line and the OpenSource Community.
I used to write Poems (Arabic) when I was able to find time for this.
February 2012
S M T W T F S
« Sep    
 1234
567891011
12131415161718
19202122232425
26272829  
SEO Powered by Platinum SEO from Techblissonline

Twitter links powered by Tweet This v1.7.4, a WordPress plugin for Twitter.