Use of a language map is needed to cover things like f
and r
, see :help language-mapping
.
set iminsert=1
for mode in ['n', 'x', 'c', 'l']
execute mode . 'noremap : ;'
execute mode . 'noremap ; :'
endfor
#!/bin/sh | |
# Caps as Ctrl | |
setxkbmap -option ctrl:nocaps | |
# Ctrl as Esc when not chorded | |
xcape -e 'Control_L=Escape' | |
# Swap semi-colon and colon | |
xmodmap -e 'keycode 47 = colon semicolon' |
Use of a language map is needed to cover things like f
and r
, see :help language-mapping
.
set iminsert=1
for mode in ['n', 'x', 'c', 'l']
execute mode . 'noremap : ;'
execute mode . 'noremap ; :'
endfor
Show the git object for the current line or selection. Different from git log -L
as I'm only interested in the current text (also I don't deem line based ancerstory particularly intersting).
Commit hashes are pulled from git blame
. We need to pass -f
and --show-email
to ensure the time is always shown as the forth field. This is considered important as I want to sort upon the time to ensure the commits passed to git show
are in chronological order.
I "prime" less
with a search pattern to allow me to quickly page though the interesting bits of the output. I do this along with passing the -R
flag via the LESS
environment variable as to override other options that may be set there that could potentially interfere, such as -F
.
The use of a UNIX pipeline is a little ugly but it is far more concise than the equivalent Vim script.
function! Gshow() range
In an effort to consolidate my focus in Vim I wondered what it would be like if I limited myself to a single window. This notion came about because I knew I wasn't utilizing things like tags, jumps, and the quickfix list as effectively could be done.
It's important to remember that no configuration is a substitute for discipline when learning to change. This is simply a journey I went on and sharing what I learnt about Vim along the way.
In lieu of a set verymagic
option in Vim we need to have plethora of
mappings to insert \v
.
The AutoVeryMagic()
function / command-line mapping is the main item
of interest here. It should only insert \v
where needed.
augroup AutoVeryMagic
autocmd!
autocmd CmdlineEnter /,\? if empty(getcmdline()) | call feedkeys('\v', 'n') | endif
Many people (myself included) have set wildcharm=<C-Z>
as suggested by :help 'wildcharm'
in their config. However in mappings I often see this is repeated
explicitly, e.g.
nnoremap <key> :buffer<Space><C-Z><S-Tab>
I prefer to refer to the setting itself, avoiding repetition and also making things more portable. A conversion of the above would be as follows.
A simplified variant of vim-addon-qf-layout.
grep -H
|
function! QuickFixFormat()
let qflist = map(getqflist(),
\ "extend(v:val, {'filename' : bufname(v:val.bufnr)})")
Enable hlsearch
whenever the cursor is on any part of a match and
disable hlsearch
otherwise.
Whenever the cursor is moved the current line is checked if it contains a match for the current search. If it does a range is created that can be compared to the cursor's current column. This matching is repeated for the current line until no more matches are found.
function! AutoHL() abort
Some user commands are intended as replacements for built-in commands,
for example :Grep
may replace :grep
. Given the existence of such
a "replacement" user command when typing :grep
it would be convenient
to have it replaced with :Grep
for the sake of muscle memory.
For other user commands a similar replacement scheme may be desirable simply to avoid having to chord with the shift key.
We can achieve this with command-line abbreviations.
Searching in Vim isn't limited to /
and ?
however those other
searches don't have the same easy one key command to move through
matches and I'm lazy. So let's make N
and n
move to the next match
for whatever the last type of search was performed. I'm mainly
interested in the quickfix list but I've written this generically so it
can be easily adapted to other sources.
function! Cycle(type, forward) abort
try