Plugin Roundup: vim-pasta, License Loader

Send in your Vim scripts for review through our contact form or @vimnews.

vim-pasta

vim-pasta by Marcin Kulik will cause text to automatically reindent when pasted. The standard p and P commands are remapped in Normal and Visual mode:

Basically it opens new, properly indented line (with o or O) in the place you're pasting to then it pastes the text with ]p. The result is nicely indented code with relative indentation between pasted lines preserved.

Filetypes can be black/white-listed if required. I'd probably use this to blacklist Markdown files for writing, for example.

Read More →

Vim 101: Visual Mode

Hint: To make your Vim look the same as my screenshots, download usevim-vimrc and run Vim with vim -u usevim-vimrc.

In a typical GUI editor, a block of text can be selected by clicking the mouse and dragging over a number of lines or characters. Vim introduced Visual mode which allows us to reuse the motion commands and operators that we've learned to manipulate blocks of text.

When in Normal mode, press v to start making a selection. The arrow keys or good ol' hjkl can be used to make a selection:

Visual mode

Read More →

How to Write a Cleaner vimrc

Writing a clean .vimrc comes down to taste, but there are a few things we can do to keep them tidy.

Work Without It

There are plenty of sources of Vim tips online. When we're busily programming away and hit a Vim configuration issue, it's only natural to find a snippet from one of these sites and paste it into ~/.vimrc. The problem comes when so many of these snippets have been pasted that we can't remember what they do anymore.

Vim can be loaded without a .vimrc by running it with vim -u NONE. At this point, settings can be entered in Command-line mode, allowing some experimentation.

Read More →

Plugin Roundup: gitvimrc.vim, Sauce

Send in your Vim scripts for review through our contact form or @vimnews.

gitvimrc.vim

gitvimrc.vim (GitHub: vim-scripts / gitvimrc.vim) by Joel Nothman is a small script that attempts to load a .vimrc file local to the current repository's root when loading a buffer from that repository. This could be used to keep an entire team's style consistent.

It might be worth setting secure if you plan on using this with untrusted open source projects.

Sauce

As an alternative to vimrc management, Sauce (GitHub: joonty / vim-sauce, License: MIT) by Jon Cairns helps manage multiple settings files, which can be used on a per-project basis. For example, running :Sauce MyProject would load the settings associated with MyProject.

Read More →

Vim 101: Marks

Part of the joy of using Vim is the ability to quickly move around a file, and even between files. Marks serve as a kind of bookmarking system, allowing positions within files to be saved and jumped to.

Some marks are persisted between sessions because Vim saves them in your .viminfo file, so chances are you already have some marks stored. To see a list, open Vim and type :marks. Notice how the list looks a little bit like registers -- the naming scheme for marks is similar.

Setting Marks and Jumping

Typing '0 will cause Vim to jump to the 0 mark, which is a "special mark" that represents the last file edited when Vim was exited.

Read More →

Dotfile Diving

I learn a lot about programming by reading open source code. The same is true of learning Vim by reading configuration files and Vim script source. Fortunately, since GitHub was launched with the slogan Social Coding, the imperative for sharing configuration files has never been stronger. Of course, there are other code sharing sites out there, and I encourage you to try them out, but a search for "dotfiles" on GitHub alone currently yields 11,610 results.

Lots of these repositories illustrate how well-known developers use Vim, from their .vimrc to the scripts and syntax highlighting files they use. Quite a few are derived from Joe Ferris' config_files repository. His Vim configuration file contains a lot of keyboard shortcuts for working with Ruby on Rails projects.

thoughtbot, inc also has a vimrc that leans towards Rails development. The thoughtbot employees also write about Vim at robots.thoughtbot.com.

Read More →

Plugin Roundup: vim-dasm, Vimified

Send in your Vim scripts for review through our contact form or @vimnews.

vim-dasm

vim-dasm (GitHub: pksunkara / vim-dasm) by Pavan Kumar Sunkara provides syntax highlighting for the assembler in 0x10c.com. The author also recommends setting indentation to two spaces:

au BufNewFile,BufReadPost *.dasm,*.dasm16 setl shiftwidth=2 expandtab

Vimified

Vimified by "Zaiste!" is basically a vimrc, bundled with Vundle and lots of plugins. The author calls it a "Vim configration framework", and has been using it to make it easier for new members to join his development team.

There's a discussion on Hacker News about it: Show HN: Vimified | Ultimate VIM configuration.

Read More →

Vim 101: Movement in Command-line Mode

Vim's command-line mode doesn't receive much attention, but it's useful to learn some of the more efficient ways to navigate text when it's active. Command-line mode is used to enter commands prefixed with a :, search patterns, and filter commands.

Basic movement is performed with the arrow keys -- left and right move the cursor one character at a time. Most people struggle when modifying a previously typed command, but there are ways to move around more quickly.

For example, let's say I want to write a new file, but I've accidentally typed in an edit command:

Read More →

Alternative Ways to Learn Vim

Vim has excellent documentation, and the interactive vimtutor isn't bad either. However, I don't blame anyone who seeks alternative ways to learn Vim.

Open Vim

Over the last few years several web applications have appeared that aim to demystify Vim. One of the most popular is Open Vim's tutorial, which is a web-based simulation of Vim that aims to teach everything from basic movement to visual block mode.

Read More →

Plugin Roundup: Ruby Debugging, Splice

Ruby Debugging

vim-addon-ruby-debug-ide (GitHub: MarcWeber / vim-addon-ruby-debug-ide) by Marc Weber may not have the most original name, but nonetheless it's an interesting ruby debugging interface for ruby-debug-ide19. It supports stepping, breakpoints, variables, and restarting the process. It requires a patched version of ruby-debug-ide19, and is still at an early stage.

The author has also written vim-addon-rdebug (GitHub: MarcWeber / vim-addon-rdebug). This script is a more minimal debugger that requires debug to be loaded in the ruby process.

Splice

Splice (GitHub: sjl / splice.vim, License: MIT/X11) by Steve Losh helps resolve conflicts during three-way merges. The Splice homepage has more details on installation and usage (Python is required).

Read More →