# Tag Info

33

First, map and noremap are similar in that that each create mappings for normal, visual, select and operator pending modes simultaneously. Vim details this in :help map-overview: Overview of which map command works in which mode. More details below. COMMANDS MODES ~ :map :noremap :unmap Normal, Visual, Select, Operator-...

11

:help modeline is pretty specific about this: No other commands than "set" are supported, for security reasons (somebody might create a Trojan horse text file with modelines). And not all options can be set. For some options a flag is set, so that when it's used the |sandbox| is effective[...] Hint: If you would like to do something else than ...

11

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-complete abbreviations, you could try the following code: augroup GetAbbrev autocmd! autocmd VimEnter * let s:abbrev_list = [] | \ call ...

10

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 you can list all the abbreviations with the same prefix with :ab prefix<CR> This is not as ideal as a completion on abbreviations but that could be a ...

8

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 type <C-v> <CR>.

8

You could write inside your vimrc: iab fo <BS>FOOBAR <BS> is the notation to use for the backspace key. For more information about special key names, see: :help key-notation

7

As it has been said, it's not possible by design. If you want something like modelines, you'll have to write your own plugin. In the early 2000 I wrote let-modeline that decodes a slightly different format of modelines (i.e. Vim: let var=expr) to set variables. For something more complex than a variable, I'd also use a local vimrc. However I wouldn't use ....

7

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. However, you can't override default vim commands with command!. So an abbreviation is probably acceptable here. Abbreviations can use the special <expr> ...

6

As explained in :help 40.1 (SPECIAL CHARACTERS): It is not possible to put a comment directly after a mapping, because the " character is considered to be part of the mapping. You can use |", this starts a new, empty command with a comment. Example: :map <Space> W| " Use spacebar to move forward a word So, you can use | in order to ...

6

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 caused by some specific configuration/plugin; thus you should follow the procedure described on Vim-FAQ 2.5: 2.5. I have a "xyz" (some) problem with Vim. ...

6

When you typing SE hit CTRL-v and then spacebar to insert space character. See :h i_CTRL-v for details.

6

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.

5

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 analyses what is before the cursor in order to expand the missing part. In the end, this is how snippets plugins are expanded (except they are much more advanced) ...

5

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 a normal Ex command or something else. cabbr <expr> csf getcmdtype() == ':' ? 'cscope find' : 'csf' See :help :map-<expr> for the documentation.

5

Perhaps like this: let s:TeXmaps = { \ 'a': '\alpha', \ 'b': '\beta', \ '->': '\to', \ '=>': '\Rightarrow' } function! <SID>IsTeXMath() return &ft ==# 'tex' && match(map( synstack(line('.'), col('.')), 'synIDattr(v:val, "name")' ), '\m^texMathZone[EX]\$') >= 0 endfunction for s:k in keys(s:TeXmaps) ...

5

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 example: :Abolish dopodiche{'} dopodiché

4

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:MaybeExpandAbbreviation(trigger) for key in keys(s:anywhere_abbreviations) if matchstr(getline('.'), repeat('.', strchars(key)) . '\%' . col('.') . 'c') ==# ...

4

Simply press in insert mode Ctrl]. This will trigger abbreviations to be expanded, without entering a space

4

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:tmp_abb = strpart(a:word, 0, l:start) let l:start += 1 execute 'iabbrev '.l:tmp_abb.' '.a:word endwhile endfunction You pass the string you want ...

4

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 the cursor position after your expanded abbreviation. One way around it is to make use of the Eatchar function mentioned at the help (there is no actual helptag ...

4

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 unless you know why you are using the recursive version. If you go with the mapping commands you'll see that when you start typing """ the ...

3

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 would only modify a search. The following code tries to define these commands: command! -nargs=+ Cab call s:StrictAbbr(<q-args>, 1) command! -nargs=+ ...

3

Your example already works, without messing with the 'iskeyword' setting. That is, because your example is an abbreviation of type end-id as can be read at :h abbreviations. Here is an example, that would only work, if you change your 'iskeyword' setting: :set isk+=, :iabbrev abc,def ABCDEF Now enter insert mode and type "abc,def" and see how this is ...

3

lh-brackets provides the Map4TheseContexts() function that takes care of detecting the context to do different things. " To be defined in a tex ftplugin -> ~/.vim/ftplugin/tex/your-shortcuts.vim :inoremap <buffer> <silent> a <c-r>=Map4TheseContexts('a', 'texMathZone', '\\alpha', 'a')<cr> " or: :inoremap <buffer> <...

3

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 Basically, it will substitute "else if" with "elif" (:%s/else if/elif/g) whenever a *.py file is: read (BufRead, e.g :split testfile.py) or written (...

3

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')<cr>" endfor

3

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 templates as plain text in some config file); much more comfortable to use (you can have several holes, placeholders and so on); much more powerful (you can run ...

3

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 \| inoreabbrev <buffer> <expr> tds strftime("%F %b %T") Or, use two autocommands: au setlocal autoindent expandtab tabstop=8 softtabstop=2 ...

3

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 the extra space that abbrev inserts. Edit (thanks to filbranden) - removing join(): iabbrev <silent> main <C-O>:put! =readfile(...)<CR><...

3

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 whatever you specify where I have "foobar". OTOH, if you enter W during a search then getcmdtype() returns / or ? and the ternary expression evaluates to ...

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