Indent Detector

What's the worst culprit for bad indentation that you've ever seen? For me Xcode springs to mind. Maybe Xcode isn't inherently bad, but somehow when I open projects authored with it in Vim I see a ridiculous mix of tabs and spaces that makes no sense. I think it downplays the importance of keeping tab settings the same as the rest of your team. It really makes understanding diffs and pull requests on GitHub a messy process.

I recently found Indent Detector (GitHub: luochen1990/indent-detector.vim, License: MIT) by Luo Chen. It attempts to detect mixed indentation and show a warning on bufEnter and bufWrite. It also tries to switch the indentation settings to match the current style.

The time taken to detect indentation is limited, so opening large files shouldn't lock up Vim. It also keeps quiet when readonly files are opened to avoid showing errors when reading help files.

Read More →

The netrw Style Options

I use netrw a fair bit mainly because of Tim Pope's vinegar.vim plugin. I press - to see a list of files in the current directory, and then navigate around using Vim shortcuts and search. You can open netrw in a similar way without installing vinegar.vim, just type :e . and you'll see a list of files.

The way Vim displays files in this view is actually configurable -- you can press i to toggle through the available view types. This is what the "long" view looks like:

netrw long

Read More →

Set Complete

When in Insert mode, you can trigger completion for a word by using CTRL-P. This cycles forward through the list of matches -- CTRL-N goes backwards. The documentation for the complete (:help 'complete') has options for configuring the behaviour of these commands, and I also wrote about it in Vim 101: Completion Compendium.

I'll show you a few useful things you can do with 'complete'. Let's look at what complete options you've got set in Vim. To see them, type :set complete. I see the following: complete=.,w,b,u,t,i. This breaks down to:

  • .: Scan the current buffer
  • w: Scan buffers from other windows
  • b: Scan buffers from the buffer list
  • u: Scan buffers that have been unloaded from the buffer list
  • t: Tag completion
  • i: Scan the current and included files

You probably instinctively know what Vim is doing when you press CTRL-P -- it shows matches for things that it has "seen" during the current session. But you can actually make it do some pretty cool things that aren't the default settings.

Read More →

Better ga and Characterize.vim

betterga (GitHub: manicmaniac/betterga) by Ryosuke Ito is an extended version of the :ascii command. This command is typically invoked with ga, and shows the ASCII value of the character under the cursor in decimal, hexidecimal, and octal.

Ryosuke's version of ga adds some useful extra information, including unicode details. For example:

  • <a> [LATIN SMALL LETTER A] 97, Hex 0x61, Octal 0141
  • <®> [REGISTERED SIGN] 174, Hex 0xae, Octal 0256
  • <∆> [INCREMENT] 8710, Hex 0x2206, Octal 021006

The template is defined with g:betterga_template, so you can change what values get displayed.

Read More →

Vim REST Console

Vim REST Console (GitHub: diepm/vim-rest-console, License: MIT) is a plugin for sending and viewing HTTP requests from RESTful services. It uses cURL, and allows you to type URLs and then get responses back in a separate window.

To make a request, you need to be in a buffer with a file type of "rest": :set ft=rest. Then, type the protocol and hostname on one line, followed by the HTTP method and path on another:

http://localhost:9200
GET /_cat/nodes?v

Once you're ready type the trigger key to make the request, which is C-j by default. The results will be displayed in a split window.

Read More →

Reed Esau's Writing Plugins

I've used Vim to write most of the prose I've ever written, and I use my default programmer-oriented configuration for writing. There's now a growing collection of plugins designed to help prose writers who favour Vim, so I've got an alternate "writing mode" vimrc.

Reed Esau has created some great writing plugins for Vim. One is vim-pencil. It adds better support for text formats like Markdown, soft line wrap versus hard line breaks, and wrap mode autodetection based on the modeline. Another cool feature is Pencil creates undo points when certain punctuation characters are used in Insert mode. This is important because writing prose doesn't lend itself to switching out of Insert mode as much as programming.

Other writer-focused plugins by Reed include vim-lexical, which improves thesaurus and dictionary completion, vim-textobj-quote for coping with typographic quote characters, and vim-textobj-sentence, which makes the native sentence detection better.

Read More →

Hardy: Arduino Support for Vim

That Arduino IDE isn't too bad, but you'd probably prefer to use Vim for Arduino development. Hardy (GitHub: 4Evergreen4/vim-hardy) provides Arduino support for Vim. With it, you can type :ArduinoVerify to check an Arduino file, and :ArduinoUpload to compile and upload it. You'll still need to have installed the Arduino IDE for this to work, because it comes with the tools required for compilation.

Hardy also includes an Arduino syntax file. The name "Hardy" comes from the fact "Arduino" means "hardy friend" in Italian, and this script is a friend of Arduino (or a friend of yours if you're not a fan of the IDE).

Read More →

ShellCheck

ShellCheck is a static analysis tool for shell scripts. Shell scripting isn't necessarily difficult, but the syntax is hard to get the hang of, particularly if you rarely write shell scripts. ShellCheck is a Haskell program that runs through your scripts and provides warnings and suggestions for improvements. It will help if you're a beginner, but it also catches more subtle issues that even more advanced users may miss.

ShellCheck

I ran it on a script I use for updating usevim images, and it noticed I was using cat where a redirection would have sufficed.

Read More →

dotenv.vim

Yesterday Tim Pope published a new plugin called dotenv.vim (GitHub: tpope/vim-dotenv, License: Vim). It reads variables from a .env or Procfile and sets the corresponding variables in Vim.

This is useful if you have Procfiles for web applications and want to trigger the same commands for local development. Tim notes that you can use dotenv.vim with projectionist.vim and dispatch.vim to get a default :Start of foreman start for projects with a Procfile, which is ideal if you're working on lots of Heroku projects.

Read More →