I have the following .gvimrc:


# -----------------------------------
# This file is sourced AFTER .vimrc
# -----------------------------------
set mousehide

# Set fonts for gvim
# fontsize = 11 with the 14'' MacBook you have exactly two columns
# with textwidth = 78
var fontsize = 18
var fontface = "Arial"
var fontsize_tail = ""

if has("gui_win32")
     fontsize = 14
     fontface = "FiraCode_NFM:h"
     fontsize_tail = ":cANSI:qDRAFT"
     set guioptions-=T
    # Open gvim in full-screen
    au GUIEnter * simalt ~x
elseif has("gui_macvim")
     fontsize_tail = ""
     fontface = "Fira\ Code:h"

&guifont = fontface .. string(fontsize) .. fontsize_tail

def ChangeFontsize(n: number)
    var old_redraw = &lazyredraw
    set lazyredraw

    fontsize = fontsize + n
    &guifont = fontface .. string(fontsize) .. fontsize_tail

    &lazyredraw = old_redraw

# Some commands
command! FontsizeIncrease :vim9cmd ChangeFontsize(1)<cr>
command! FontsizeDecrease :vim9cmd ChangeFontsize(-1)<cr>

However, when I call :FontsizeIncrease of :FontsizeDecrease I have a E488: Trailing character ^M but I cannoty figure out where such an ^M is. I tried to :!dos2unix ~/.gvimrc but with no success. I am working on MacOs Sonoma.


1 Answer 1


When creating user commands with command, the trailing enter is somewhat implicit. You do not need to add <cr>. The leading colon is also implicit and not needed.

This is all in contrast to mappings.

  • Ah correct! These things are really difficult to remember.
    – Barzi2001
    Commented Nov 23, 2023 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.