home.


Tagged: vim


Vim: Change the colour of the folded line

You can fold/collapse lines in vim. Let’s say you do it manually, do :set foldmethod=manual.

Then highlight the lines you want to fold. Then press zf. You can open and close folds with za.

But the line vim gives you is an ugly light grey colour. You can change this to black via :hi Folded ctermbg=black.

I’m using cterm since I’m using the text console. Otherwise I’d use guiterm

vim

Remapping vim commands

Let’s take the command Control W <. This expands the left hand window in a split window.

The only problem with this is that you must first press control w, then shift, and then ,. At least on my keyboard.

Let’s remap this Control w < to Control w ,. This will save us pressing the shift key.

:nmap [press control v][press control w], [press control v][press control w]<

You can also put this in your .vimrc file for activation on startup.

Pressing control v allows you to then enter a control key in the command.

The n is nmap means this only applies in normal mode.

vim

Vim: rebind escape and caps lock on the command line

If you are using vim a lot, and touch type, you may find reaching up to press escape all the time ruins your typing.

You can rebind escape to caps lock, and vice versa, throughout all your X apps using xmodmap.

Use this in ~/.Xmodmap

clear Lock
keycode 9 = Caps_Lock
keycode 0x42 = Escape

And then use the command, probably in your ~/.bashrc, xmodmap ~/.Xmodmap to do the rebind.

vim unix

Vim: command line mode

First set -o vi and you can press escape (or whatever you’d bound that to) to use the vim commands on the current commanded typed in on the command line.

You can also press v and it will open up vim and you can edit the command in the full vim editor.

You made need to put EDITOR=vim in your .bashrc file.

vim unix

Vim: Use dash in autocomplete

If you start typing in vim, then press ctl n, vim will give you a list of autocomplete options.

In this list you can press ctl n and ctl p to navigate the list.

However, by default, vim won’t show you any autocomplete options with a dash in them.

For instance, if you have the text this-is-a-variable. And you start typing t, and then press ctl n, it will only show you this, not this-is-a-variable.

To make the autocomplete list include items that have a dash in them, add to the iskeyword option:

set iskeyword+=\-
vim vim-autocomplete

Page 1 of 4
Next