Long-range line duplication. The brief In the video, we tackle a simple problem.
With our cursor on line 16 of this file: Copy line 9 and place a duplicate below line 16, to produce this: Normal mode solutions We start with a naïve solution: kkkkkkk yy jjjjjjj p Our first refinement speeds up navigation using the goto line command (:help G), and the jumplist: 9G yy <C-o> p Ex command solutions. Edit remote files locally via SCP/RCP/FTP. I'm frequently editing files remotely, but if the network traffic is tight, then a normal Vim session turns into a tortuous event.
The solution to that was right under my nose: Vim's Network-Oriented File Transfers (:help netrw). Instead of editing the file remotely, it can be transfered from the host server, to a local copy, edited and then sent back when done. I know that you can do this manually, but it's a hassle, besides, if it can be done automatically, why not go for that?
You need the following installed and properly configured: Vim netrw.vim (distributed with Vim) scp, rcp, ftp or ftp+ To use, all you need is to specify the protocol, user, host and path to the file you want to edit: vim gvim Every time you write the file (:w etc) the file will get copied over to the source and you will be brought back to your session for further editing. If you already have an open session, then just issue the following commands: How I boosted my Vim » nvie.com. A few weeks ago, I felt inspired by articles from Jeff Kreeftmeijer and Armin Ronacher.
I took some time to configure and fine-tune my Vim environment. A lot of new stuff made it into my .vimrc file and my .vim directory. This blog post is a summary describing what I’ve added and how I use it in my daily work. Before doing anything else, make sure you have the following line in your .vimrc file: " This must be first, because it changes other options as side effectset nocompatible Step 0: make the customization process easier ¶ Before starting configuring, it’s useful to install pathogen. So, download pathogen.vim, move it into the .vim/autoload directory (create it if necessary) and add the following lines to your .vimrc, to activate it: " Use pathogen to easily modify the runtime path to include all" plugins under the ~/.vim/bundle directorycall pathogen#helptags()call pathogen#runtime_append_all_bundles() " change the mapleader from \ to ,let mapleader=","
Vim regexes are awesome. Two years ago I wrote about how Vim's regexes were no fun compared to :perldo and :rubydo.
Turns out I was wrong, it was just a matter of not being used to them. Vim's regexes are very good. They have all of the good features of Perl/Ruby regexes, plus some extra features that don't make sense outside of a text editor, but are nonetheless very helpful in Vim. Here are a few of the neat things you can do. Vim regexes are inconsistent when it comes to what needs to be backslash-escaped and what doesn't, which is the one bad thing. Without \v: :%s/^\%(foo\)\{1,3}\(.\+\)bar$/\1/ With \v: :%s/\v^%(foo){1,3}(.+)bar$/\1/ Far easier to read. One thing that :perldo and :rubydo can't do is span newlines; you can't combine two lines and you can't break one line into two.
But Vim's regexes can span newlines if you use \_. instead of .. :%s@<body>\v(\_.+)\V</body>@\1@ (Note: in real life, never use a regex to parse HTML or XML. See also :h \_. :%s/\v^(foobar)(baz)/\1/ to put the foobar back. See :h /\zs.