Web Dev Blog

Looking for help with WordPress, Apache, Vim, Web Security and more. Here are a few tips.

Category: Vim

Automatically Change Indent When Pasting in Vim

For years I’ve been trying to figure out how to keep Vim from automatically indenting when I copy from one file to another.

Stackoverflow mentioned this page buy a developer named Marcin Kulik

Automatically set paste mode in Vim when pasting in insert mode

let &t_SI .= "\[?2004h"
let &t_EI .= "\[?2004l"

inoremap [200~ XTermPasteBegin()

function! XTermPasteBegin()
set pastetoggle=[201~
set paste
return ""

This code automatically turns off the Vim indent functionality when new text is pasted into a file. Just add it to your .vimrc file.

It’s the same as a set paste and set nopaste before and after pasting new text, but it happens automatically. I’ve tested it and it seems to be working PERFECT. I love it!

Search for a file name and insert it into a Vi (Vim) file

Something I’ve been trying to do for years and didn’t realize it was so easy. Know when you are editing an html file and want to insert a filename for an image or other asset without leaving Vim? There’s an easy way to do that.

Just use Ctl-X Ctl-f

Completing file names *compl-filename*

CTRL-X CTRL-F Search for the first file name that starts with the
same characters as before the cursor. The matching
file name is inserted in front of the cursor.
Alphabetic characters and characters in 'isfname'
are used to decide which characters are included in
the file name. Note: the 'path' option is not used
here (yet).