Tag Archives: vim tips

Vim: select to the end of the line & select to the beginning of the line

[iframe src=”http://blip.tv/play/h61qgsmhGwA.html” width=”100%” height=”370″]

To select from your current cursor position to the end of the line, use:

(From Normal Mode/Command Mode): v (little v; will make cursor thin) $ (shift-4)

To select to the beginning of the line:

(From Normal Mode/Command Mode): v (little v; will make cursor thin) ^ (shift-6)

…and walla! Quick vim tip!

Use set selectmode= to disable select mode in Vim

Today I was using Vim and noticed that, while in insert mode, using <Shift-up|down|left|right> would cause Vim to go into select mode. Then, when I did a <Ctrl-c> to copy, <Ctrl-p> would not paste (I guess Windows key copy and paste do not work in select mode?).

Anyways, I was able to fix this problem by disabling selectmode all-together using:

set selectmode=

In the documentation it only gives key, cmd, and mouse and it took me awhile to figure out if you set it to nothing (NONE did not work) it will not enter select mode on either of these events.

This (and many other new things) will be present in 0.0.2 version of Aubrey’s gVim.

Vim tabbing awful for HTML, JavaScript, CSS, PHP

[iframe width=”100%” height=”340″ src=”http://www.youtube.com/embed/f7BafiLfNyA?hd=1″]

The video is a result of the following tip/fix:

I usually edit a .html or .php file and do HTML, PHP, CSS and JavaScript coding inside that filetype. Vim, as far as I can tell, just doesn’t get it when it comes to tabbing/indentation (especially with PHP). Vim ships with indenting files built in $VIMRUNTIME/indent. Even when I downloaded scripts that help support the indention built it, it still didn’t work. All I really wanted was for Vim to keep the indention of the previous line. Once I figured it out it solved all my tabbing/indention woes.

First I used…

[sourcecode]set noexpandtab
set autoindent &quot;keeps previous lines indent
set copyindent
set preserveindent
set softtabstop=0
set shiftwidth=4
set tabstop=4[/sourcecode]

… to get my tabs and indention working in Vim. Notice that autoindent and copyindent are the key settings that cause Vim to keep the previous line’s indentation.

Then, I disabled the shipped indentation rules that come with Vim…

[sourcecode]filetype indent off[/sourcecode]

This keeps Vim from loading any indenting rules, and now Vim will just follow the previous indention.

I’ve include my _vimrc file for you to examine. I may be releasing my Vim/_vimrc/Plugins, etc as an “ultimate Vim for HTML, PHP, CSS & Javascript” that everyone can use soon.

_vimrc-aubrey-island-javascript-php-html-css (txt)