Tagged: 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

Vim: Change tabs to spaces and set how many spaces on tab press

When you press tab in vim, you normally get a tab character inserted in your text.

You can turn this off via set expandtab. When you press tab now, you get spaces.

To alter how many spaces you get on tab press, issue set tabstop=4.

Finally, to alter how to spaces you get when you indent text with >, issue set shiftwidth=4.


Nvim: Pains while moving from vim

I’ll probably use nvim now since we can remotely control it with python or what have you.

However, there are annoyances in moving over (I’m on 0.1.3).

  1. By default, the ruler isn’t there. You don’t automatically get the current line number.
  2. By default, if you attempt to use your mouse to copy some text, it’ll modify nvim’s visual mode. I just want to paste some text to the X clibboard buffer (there are probably better way but meh).
  3. By default, there’s an annoying white statusline at the bottom of the page.
  4. By default, set list doesn’t show the eol character.

You can avoid all this by putting this in yout .config/nvim/init.vim file:

set ruler
set laststatus=0
set mouse=v
set listchars=tab:-\ ,trail:-,nbsp:+,eol:$

In addition, in gnu screen or tmux, the escape key is harder to press. You can put maptimeout 10 in your .screenrc to fix in this gnu screen. It’s something to do with nvim using a new library for user input, I believe.

Anyway, we’re on 0.1.3, so thing will change.


Page 1 of 3