From 592e412bbaae75ba534cef25bc4258a814c4d1a1 Mon Sep 17 00:00:00 2001 From: Chris Coley <chris@codingallnight.com> Date: Fri, 2 Mar 2018 14:55:09 -0800 Subject: [PATCH] Adding a macro to add a modeline to a file --- vimrc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vimrc b/vimrc index 349a9db..88f7f7f 100644 --- a/vimrc +++ b/vimrc @@ -8,6 +8,7 @@ set showmode " Show which mode you're in set ruler " Display cursor position in the lower right corner "set number " Line numbers. ruler makes this redundant set showmatch " Show matching [] () {} etc... +set showcmd " Show commands as you type them set smartindent " Let vim help with indentation set nowrap " Do not wrap lines longer than the window set scrolloff=5 " Minimum number of lines to keep above/below the cursor @@ -16,6 +17,7 @@ set backspace=2 " Make Backspace work like you expect set formatoptions+=ro " Automatically insert the comment character when you " hit <Enter> (r) or o/O (o) in a comment block set commentstring=#%s " The comment style for line comments +let mapleader='\' " The <leader> key " Tab options @@ -75,6 +77,18 @@ autocmd BufEnter * let &titlestring = expand("%:t") . " - %{$USER}@" . hostname( autocmd VimLeave * let &titleold = $USER . "@" . hostname() | set title +" Enable modeline +set modeline +set modelines=5 + +" Append a modeline at the end of a file. Uses '#' comment character +nnoremap <leader>ml :call AppendModeline()<CR> +function! AppendModeline() + let l:modeline = printf(&commentstring, printf(" vi: set ts=%d sts=%d sw=%d %set ft=%s: ", &tabstop, &shiftwidth, &softtabstop, &expandtab ? '' : 'no', &filetype)) + call append(line("$"), l:modeline) +endfunction + + " Filetype specific settings autocmd FileType dns setlocal commentstring=;%s autocmd FileType gitconfig setlocal commentstring=;%s -- GitLab