New answers tagged

1

The most accurate and compliant way is to extend filetypes with after/ftplugin/{text,markdown}.vim. Your "no extension" files can probably be detected as "text" filetype as well (or create a completely new filetype if you like). Then the actual functionality should be shared by a common autoloaded script. But if you don't care then a ...


1

You can use the value of &filetype to determine if you are in a buffer without a filetype or with one of the filetype you want to target. One example could be like this: function! DoStuff() if (exists('b:StuffDone') || index(['', 'text', 'markdown'], &ft) < 0) return endif let b:StuffDone = 1 echo "Doing stuff for&...


2

There is an autocommand event InsertLeave. It is triggered when you leave Insert mode permanently with ESC or temporarily with Ctrl+O, but not if you leave Insert mode with Ctrl+C.


0

You can use winsaveview() and winrestoreview() to restore the view across the :edit operation. At this point, it's much easier if you define a function to perform the operation: function! SwiftFormat() silent !swiftformat % let view = winsaveview() silent edit call winrestview(view) redraw! endfunction augroup swiftFormat autocmd! ...


2

Just in case someone still wondering about this, now you can use autocmd. autocmd CmdlineEnter /,\? :cnoremap <CR> <CR>zz autocmd CmdlineLeave /,\? :cunmap <CR> It's basically remap enter when in search mode and unmap if leave search mode. It was inpired by example from :help 'incsearch' and you can use it without incsearch.


0

noremap <leader>w <Cmd>:call mkdir(expand("%:p:h"),"p")<CR>:w<CR> I use the above mapping to save a file with a new directory path. In above command %:p = "<full path to>nonExisitingDirectory/newFile.txt", :h removes the filename "newFile.txt". After execution of expand() function the ...


4

The answer you linked is the right direction: ftplugins are made exactly for this purpose, check the doc: (:h ftplugin) If you have things that you want used in both c and cpp ftplugins you could put it in a function in ~/.vim/autoload/cscope.vim and then in ~/.vim/after/ftplugin/c.vim and ~/.vim/after/ftplugin/cpp.vim you can simply call this function. ...


Top 50 recent answers are included