Skip to main content
11 votes
Accepted

How do I manage and remember many abbreviations in my vimrc?

I don't know what's the best way to manage over 500 abbreviations. Maybe in the long term, as @statox explained, you could have a look at snippets to reduce this number. And if you want to auto-...
user9433424's user avatar
  • 6,138
10 votes

How do I manage and remember many abbreviations in my vimrc?

A wikia tip suggest a method to selectively display your abbreviations: You can list all of your abbreviations with :ab<CR> (replace ab by iab to list only insert mode abbreviations) And ...
statox's user avatar
  • 49.9k
8 votes
Accepted

How to make command-line abbreviations that only trigger at begining of line

First and foremost, for most cases like this you'll want to use a command! instead of an abbreviation. This allows you to create a custom command-line command that will not mess up other inputs. ...
Tumbler41's user avatar
  • 7,746
8 votes
Accepted

How to create multi-line abbreviations

yes, you can do with the ^M character in your abbrev, for example: iabbrev Doc #^M# function :^M#^M# returns :^M# will be transformed into: # # function : # # returns : # To get ^M you need to ...
nobe4's user avatar
  • 16.1k
7 votes
Accepted

cabbr definitions disturb searching in Vim

What you can do is use an expression abbreviation. This will allow you to use any Vim expression on the right-hand side, instead of just a static string. With getcmdtype() we can check if we're doing ...
Martin Tournoij's user avatar
7 votes
Accepted

How to put a new line character in an abbreviation?

Use <cr> instead of \n: iabbrev sm Summary<cr> You use generally use key notation in these cases, something you can find out more about by entering :h key-notation.
Peter Rincker's user avatar
6 votes
Accepted

Can vim automatically correct a spelling mistake if the word doesn't end in a space?

As mentioned in the comments, the simple abbreviation iabbr funciton function works on my setup and in vanilla vim, without any need of type space -- it is triggered by the (. Your problem is being ...
mMontu's user avatar
  • 6,640
5 votes
Accepted

Case-insensitive abbreviations

You could use the abolish plugin. For your example you could use the following: :Abolish perche{'} perché It changes perche' to perché, Perche' to Perché and PERCHE' to PERCHÉ. For the second ...
mMontu's user avatar
  • 6,640
5 votes
Accepted

How do I make abbreviations expand for minimal prefixes?

If you really want to use abbreviations, I'm afraid you'll have to either define one abbreviation for each leading part. or to define a mapping on a trigger like <tab> (or whatever) that ...
Luc Hermitte's user avatar
  • 17.4k
5 votes
Accepted

iabbrev with <CR> and <Space>

You'll probably have less troubles using mappings than abbreviations. Also using the non recursive version of the abbreviations commands (noreabbrev) and mappings (noremap) is usually a better idea ...
statox's user avatar
  • 49.9k
4 votes

How do I make abbreviations expand for minimal prefixes?

Here is a little function that may help you, because I don't think you can do otherwise: function! s:ExpandAbbrev(word, start) let l:start = a:start while l:start < len(a:word) let l:...
nobe4's user avatar
  • 16.1k
4 votes

Backspace in insert abbreviation

As an alternative, here's a way to define and expand abbreviations that expand anywhere: let s:anywhere_abbreviations = { \ 'fo': 'FOOBAR', \ 'ab': 'ABBREVIATION', \ } function! s:...
djjcast's user avatar
  • 921
4 votes
Accepted

Abbreviations add spaces when they shouldn't

This happens usually, because the abbreviation is triggered once you type a final space after the characters that trigger the abbreviation, e.g. after tdSpace, so that the final space gets added at ...
Christian Brabandt's user avatar
4 votes
Accepted

Inserting abbreviation from file

Thanks to D. Ben Knoble I ended up using: iabbrev <silent> main <C-O>:put! =join(readfile(...), \"\n\")<CR><esc>A last <esc>A is needed in order to account for ...
Alexandru Dinu's user avatar
4 votes

How to prevent inoremap mapping from being "run" inside iabbrev?

Use inoreabbrev instead. This will prevent the recursive inoremap.
Amplify's user avatar
  • 151
3 votes
Accepted

How to make abbrev ignore my custom keybindings?

inoreabbrev (insert-mode non-recursive abbreviation) is the command that will ignore custom mappings when executing the abbreviations. To remove abbreviations without leaving vim use iunabbrev [lhs]. ...
Lucas Payne's user avatar
3 votes
Accepted

Substitute an insert-mode input immediately

As a follow-up: an actual answer is to use a snippet plugin, such as UltiSnips. Snippet plugins are: already done; designed precisely for that kind of things; much easier to set up (just write ...
Maëlan's user avatar
  • 263
3 votes

cabbr definitions disturb searching in Vim

You could also define 2 custom commands :Cab and :Sab which would make the definition of such abbreviations easier. :Cab would define an abbreviation which would only affect an Ex command, while :Sab ...
saginaw's user avatar
  • 6,766
3 votes

Backspace in insert abbreviation

To summarize the two simplest answers that came out of this: You can use a backspace directly in an abbreviation -- various special characters are documented under :help keycodes. So, e.g.: :iab ...
goldilocks's user avatar
3 votes
Accepted

One abbreviation for various commands with different prefix?

You could use a loop and exec: for l in ["python", "vim", "bash"] exec 'autocmd FileType * iabbrev' l."code ```" l."```<left><left><left><cr>jjO<C-R>=Eatchar('\s')&...
muru's user avatar
  • 24.9k
3 votes

Abbreviation-likes containing spaces

This might not be the perfect answer, but I kind of solved the problem by creating the following augroup: augroup filetype_python autocmd! autocmd BufRead,BufWrite *.py :%s/else if/elif/g augroup END ...
lsrdg's user avatar
  • 450
3 votes

Abbreviations for local filtype buffers only

When creating an autocommand, the :au part interprets | as a command separator. Just like for mappings, you need to escape it: au setlocal autoindent expandtab tabstop=8 softtabstop=2 shiftwidth=2 \| ...
D. Ben Knoble's user avatar
  • 26.3k
3 votes

Make 'cabbrev' work from command-line but not search prompt?

If you use a mapping instead of an abbreviation then this'll do... :cnoremap <expr> W (getcmdtype() == ':') ? "foobar" : "W" From command-line you get W resolving to ...
B Layer's user avatar
  • 19.9k
2 votes
Accepted

Shortcut / abbreviation to insert text block

Sure, you've got a couple options. Use an abbreviation: iabbrev zlc %TC:ignore<CR>\iffalse If you type zlcEnter in insert mode it will fill in the text. iabbrev is an abbreviation that only ...
Tumbler41's user avatar
  • 7,746
2 votes
Accepted

Remap <ENTER> so it makes new line and insert a datestamp

Try with the following :inoremap <CR> <Esc>:put =strftime('%H%M%S')<CR>A This will map your enter key when in insert mode (inoremap) so that It exits to command mode (<Esc>) ...
Spiros's user avatar
  • 136
2 votes
Accepted

How to get abbreviations to work inside nnoremap

nnoremap is a non-recursive mapping. This means that it will not take your abbreviation into account. Change it to: iab xdate <c-r>=strftime('%c')<cr> nmap <leader>w i#xdate<...
Tumbler41's user avatar
  • 7,746
2 votes

Abbreviation-likes containing spaces

You'll have to analyse the context of the text you've typed to know what you want to insert. For instance, you could have a if abbreviation that detects there is a else just before. BTW: don't remove ...
Luc Hermitte's user avatar
  • 17.4k
2 votes
Accepted

Wrong abbreviation expansion

So this is a bug of vim-latex v1.9.0 that is fixed in v1.10.0. I finally managed to reproduce the issue you reported and after using git bisect on the vim-latex sources, I managed to narrow it down ...
filbranden's user avatar
  • 28.8k
2 votes

Substitute an insert-mode input immediately

I found a kind of solution by reading :help abbreviations: fun! EatBlank() let c = nr2char(getchar(0)) return (c =~ '\s' || c == "\r") ? '' : c endfun iabbrev <buffer> begin! begin end<...
Maëlan's user avatar
  • 263
2 votes
Accepted

autocmd changes only applying to new files

If I edit an existing .js or .php file it uses a cached version(I'm assuming) of the command before I editted it. I was under the impression autocmd! would clear any existing commands. autocmd! ...
user938271's user avatar
  • 5,957

Only top scored, non community-wiki answers of a minimum length are eligible