New answers tagged

0

Unlike Maxin's answer, I'd recommend to use a ftplugin. They're really made to store the definition of filetype related mappings, commands, abbreviations, options, variables... While we shall use <buffer> with mappings and abbreviations, it's -b with commands. Now the problem is that you want to implement is quite complex. Vim main tool is regex. And ...


1

You cannot have a command started with lowercase letter, use :Stripdbg or :StripDbg To define a command available only in specific filetype you can define it in autocommand event with -buffer parameter: augroup cpp_group | au! au FileType cpp command! -buffer StripDbg call StripDbg() augroup end You have to implement StripDbg() function to do actual ...


0

OK, this answer worked for me: https://stackoverflow.com/a/2803985/1641112 For my particular problem, final solution is: autocmd BufWritePost *.md execute ':silent !VimwikiAll2HTML' | execute ':redraw!'


0

This should work to clear all Insert-mode mappings starting with space: let l:map = mapcheck(' ', 'i') while !empty(l:map) execute 'iunmap' l:map let l:map = mapcheck(' ', 'i') endwhile Unfortunately, there is no way to restrict mapcheck to buffer-local mappings only; however, the ugly loop does let us sidestep parsing command output, which may be ...


3

You can try to analyze the result of split(execute('imap <buffer> <space>'), "\n") From there, keep only the second field (IIRC). => ->map({k,v -> split(v)[1]}), and generate the clearing commands, => prefer ->map({k,v -> 'iunmap <buffer> '.split(v)[1]}) And finally ->execute(). TL;DR :call execute('imap <...


2

If your insert mode mappings are filetype specific then .vim/after/plugin/map.vim and autocmd VimEnter * imapclear would not work as they are executed before fitetype creates them. Also imapclear deletes all insert mode mappings including default ones. You can try to apply imapclear <buffer> on bufread/filetype event though: using after/ftplugin create ...


0

Instead of using the zf Normal mode command, it's easier if you use the :fold Ex command, which takes a range and fits naturally in a function. So you can easily fold the block starting on the first line that has Copyright and going up to the next line with CONNECTION using the following: function! FoldLicense() silent! /Copyright/,/CONNECTION/fold ...


3

I see that for some reason people like to use :bdelete to close buffers. That's a very strange practice, IMO. Let's recall what is that :bdelete all about. A buffer in Vim can 1) exist (bufexists() returns true); 2) be "loaded" (bufloaded() returns true), and 3) be "listed" (buflisted() returns true). Please, note that (2) and (3) are ...


5

Old one, but this has been added as per patch 8.1.0729 Problem: There is a SourcePre autocommand event but not a SourcePost. Solution: Add the SourcePost autocommand event. (closes #3739)


0

My recommendation is that you use BufRead to open the PDF and BufDelete to close it. Note that this should be set up at a global context, and not on the ftplugin for the tex filetype. Furthermore, you should match it by filename on *.tex (and other filenames you might want to match), rather than adding multiple per-buffer autocmd's attached to the filetype. ...


3

First you need to create your command as local to a buffer, :h :command-buffer tells us that is what the argument -buffer is for. Then I think it's better to use ftplugins (:h ftplugin) to do this kind of things rather and a Filetype autocommand which just duplicate a built-in mechanism. So you could create ~/.vim/after/ftplugin/rmd.vim and put that in it: ...


Top 50 recent answers are included