How to disable line numbers in neovim terminal?

Viewed 4736

I come with a question: How to disable line numbers on neovim terminal? I tried this:

autocmd BufRead,Filetype term://* set nonu

but this doesn't work.

I use set number relativenumber in init.vim file.

I tried nonumber, number!, but for terminal anything of this doesn't work and when i normally wrote :set nonu or :set number!, but instead of 3 2 1 17 1 2 3 i got 3 2 1 0 1 2 3

4 Answers

You can remove them by typing in a terminal buffer:

:setlocal nonumber norelativenumber

Additionally, you can add:

autocmd TermOpen * setlocal nonumber norelativenumber

In your init.vim config file to keep this setting on each neovim session.

Grouping autocommands helps to avoid duplicating them:

augroup neovim_terminal
    autocmd!
    " Enter Terminal-mode (insert) automatically
    autocmd TermOpen * startinsert
    " Disables number lines on terminal buffers
    autocmd TermOpen * :set nonumber norelativenumber
    " allows you to use Ctrl-c on terminal window
    autocmd TermOpen * nnoremap <buffer> <C-c> i<C-c>
augroup END

Now I have a init.lua on my neovim, so here it is (The terminal specific settings are on terminal_job):

-- autocommands
--- This function is taken from https://github.com/norcalli/nvim_utils
function nvim_create_augroups(definitions)
  for group_name, definition in pairs(definitions) do
    api.nvim_command('augroup '..group_name)
    api.nvim_command('autocmd!')
    for _, def in ipairs(definition) do
      local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ')
      api.nvim_command(command)
    end
    api.nvim_command('augroup END')
  end
end

local autocmds = {
    reload_vimrc = {
        -- Reload vim config automatically
        {"BufWritePost",[[$VIM_PATH/{*.vim,*.yaml,vimrc} nested source $MYVIMRC | redraw]]};
    };
    packer = {
        { "BufWritePost", "plugins.lua", "PackerCompile" };
    };
    terminal_job = {
        { "TermOpen", "*", [[tnoremap <buffer> <Esc> <c-\><c-n>]] };
        { "TermOpen", "*", "startinsert" };
        { "TermOpen", "*", "setlocal listchars= nonumber norelativenumber" };
    };
    restore_cursor = {
        { 'BufRead', '*', [[call setpos(".", getpos("'\""))]] };
    };
    save_shada = {
        {"VimLeave", "*", "wshada!"};
    };
    resize_windows_proportionally = {
        { "VimResized", "*", ":wincmd =" };
    };
    toggle_search_highlighting = {
        { "InsertEnter", "*", "setlocal nohlsearch" };
    };
    lua_highlight = {
        { "TextYankPost", "*", [[silent! lua vim.highlight.on_yank() {higroup="IncSearch", timeout=400}]] };
    };
    ansi_esc_log = {
        { "BufEnter", "*.log", ":AnsiEsc" };
    };
}

nvim_create_augroups(autocmds)
-- autocommands END

On neovim, simply use the following autocmd.

autocmd TermOpen * setlocal nonumber norelativenumber

Not for Neovim, but Vim, put in your .vimrc

autocmd TerminalOpen * setlocal nonumber norelativenumber
Related