Archive for the ‘vim’ Category

Clear highlighting on escape in normal mode

December 22, 2016 Leave a comment

How to disable highlighted text after doing a search in vim?

Added the following to my .vimrc

 " Clear highlighting on escape in normal mode
 nnoremap <esc> :nohlsearch<return><esc>
 nnoremap <esc>^[ <esc>^[

System details:
vagrant box running ubuntu/trusty64


Categories: vim Tags: ,

Custom Colors

December 21, 2016 Leave a comment

I had set up my vim to run flake8 when I save python files. The issue now was that the quickfix window would display the errors in white/white-grey text on a yellow background. That proved to be really hard to read.

white on yellow

1. One option was to change my colorscheme to something that would display the text. (Many hours later I still had not found a colorscheme that I liked.)
2. Change the color for just that “aspect”.

So I went with option 2 and changed the color. Which resulted in black on yellow and is now much easier to read.

While in vim look at the current colors that are already set. (:highlight or :hi)



The colors I wanted to change were for ‘Search’. So while still in vim

:highlight Search term=reverse ctermbg=11 ctermfg=0  guibg=Yellow

To make this permanent I added the following to .vimrc

highlight clear
highlight Search term=reverse ctermbg=11 ctermfg=0  guibg=Yellow


Categories: vim Tags:


December 21, 2016 Leave a comment


QuickFix is designed to display compiler errors — a list of errors is displayed and can be selected to jump to a specific file and line.

:cn — Go to the next location in the list
:cp — Go to the previous location
:ccl — Close the quickfix window

Depending on where your quickfix window is. You can use below keys to move in and out of the window. (If quickfix window is at the bottom part of your screen)
CTRL-w + j — Move into the quickfix window
CTRL-w + k — Move out of the quickfix window

The window commands will work here. See link in source section below for more details.


Categories: python, vim Tags:

Tab navigation

December 20, 2016 Leave a comment

In normal mode, you can type:

gt go to next tab
gT go to previous tab
{i}gt go to tab in position i

Note that the gt command counts from one. That means 3gt will jump to the third tab. Also note is 0gt and 1gt mean the same thing: jumping to the first tab.

Categories: vim Tags: ,


December 19, 2016 Leave a comment

Auto indent in vim was killing me! Every time I wanted to copy and paste some code into vim, it would auto indent the already indented code. So things were looking messy. A fix was to do “:set paste” before pasting code. Adding “set paste” to my .vimrc did not help cause for some reason code was getting auto indented when I pasted, so I had to “set nopaste”, then “set paste” to get it to ignore indentation.

Installing vim-bracketed-paste worked for me.



Vim also handles newlines specially. When I am manually typing out code, vim will add extra space characters each time I hit return so that the resulting indentation is correct. Unfortunately when pasting into vim these extra spaces end up making a mess because the content I’m pasting already includes the correct indentation.

The usual work around for this is to manually run “:set paste” inside vim before pasting, but I often forget. The vim-bracketed-paste plugin uses code from Chis Page to do this automatically for me, so the content I paste into vim does not get automatically indented but the lines I type manually still do. You can install this plugin using pathogen, or by copy-pasting the code into your ~/.vimrc.


Categories: vim Tags: ,

Running vim commands on the cli

May 4, 2016 Leave a comment

I am trying to configure ansible to install some vim plugins. When doing this manually the steps are you git clone the repo, then run a vim command. How to do the same when using a script?

From the vim manual


-c {command}
{command} will be executed after the first file has been read. {command} is interpreted as an Ex command. If the {command} contains spaces it must
be enclosed in double quotes (this depends on the shell that is used). Example: Vim “+set si” main.c
Note: You can use up to 10 “+” or “-c” commands.

–cmd {command}
Like using “-c”, but the command is executed just before processing any vimrc file. You can use up to 10 of these commands, independently from “-c”

Some examples:

vim "+PromptlineSnapshot ~/ lightline" "+q"


vim -c "PromptlineSnapshot ~/ lightline" -c "q"


Categories: ansible, bash, vim Tags:

xterm colors

April 30, 2016 Leave a comment

Editing a file using vim looks like this:
Screen Shot 2016-04-30 at 12.29.40

instead of this (ie note the colors):
Screen Shot 2016-04-30 at 12.30.06

This happens to me on freshly set up vagrant boxes. I am yet to find a permanent solution.

Run the following command and try again.

$ export TERM=xterm-256color