From aa31766bae5038d2fe49b05b1b635813279f1423 Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 30 Oct 2022 03:38:29 +0100 Subject: [PATCH] vimrc: add AppendModeline func --- .vim/vimrc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.vim/vimrc b/.vim/vimrc index 23fd9a9..3830569 100644 --- a/.vim/vimrc +++ b/.vim/vimrc @@ -1243,6 +1243,18 @@ set exrc set secure +" Append modeline before first line in buffer. +" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX +" files. +function! AppendModeline() + let l:modeline = printf(' vim: set ts=%d ft=%s fenc=%s ff=%s :', + \ &tabstop, &filetype, &fileencoding, &fileformat) + let l:modeline = substitute(&commentstring, '%s', l:modeline, '') + call append (line('^'), l:modeline) +endfunction +nnoremap ml :call AppendModeline() + + function! AskQuit (msg, proposed_action) if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 exit