6

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

kocotian
  • 97
  • 1
  • 7

5 Answers5

22

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.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
4

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
SergioAraujo
  • 11,069
  • 3
  • 50
  • 40
1

On neovim, simply use the following autocmd.

autocmd TermOpen * setlocal nonumber norelativenumber
s1n7ax
  • 2,750
  • 6
  • 24
  • 53
1

create _terminal.lua

-- ~./config/nvim/lua/_terminal.lua
local api = vim.api

api.nvim_command("autocmd TermOpen * startinsert")             -- starts in insert mode
api.nvim_command("autocmd TermOpen * setlocal nonumber")       -- no numbers
api.nvim_command("autocmd TermEnter * setlocal signcolumn=no") -- no sign column

vim.keymap.set('t', '<esc>', "<C-\\><C-n>")                    -- esc to exit insert mode
  • setlocal is used so the rest of the editors buffers aren't impacted by the changes.

load _terminal.lua

-- ~./config/nvim/lua.init

require("_terminal)
casonadams
  • 956
  • 7
  • 7
0

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

autocmd TerminalOpen * setlocal nonumber norelativenumber
kalljy
  • 1