简体   繁体   English

在 VIM 上进入命令行模式(“:”)时,如何在状态栏中显示命令模式?

[英]How can I show COMMAND mode in statusline when entering command-line mode ( “ : ” ) on VIM?

I'm starting on VIM (yes, just VIM, not NeoVIM or any other) and I have a StatusLine configured in my.vimrc and which shows the current mode I'm in and all modes are shown correctly except... when I enter Command-line mode (": ") I want the statusline to show "COMMAND" and it shows "NORMAL" (I added a screenshot at the bottom showing the StatusLine).我从 VIM 开始(是的,只是 VIM,不是 NeoVIM 或任何其他),我在 my.vimrc 中配置了一个 StatusLine,它显示了我所处的当前模式,所有模式都正确显示,除了......当我进入命令行模式(“:”)我希望状态行显示“命令”,它显示“正常”(我在底部添加了一个屏幕截图,显示状态行)。

I'm looking for a solution where I don't have to install any plugin.我正在寻找一种无需安装任何插件的解决方案。 I searched a lot for this problem and I didn't find anything related with this specific problem... Thanks!我搜索了很多这个问题,但我没有找到与这个特定问题相关的任何内容......谢谢!

Here is the .vimrc (StatusLine stuff begins where it says " >>>>> Status line"):这是.vimrc (StatusLine 的内容从“>>>>> 状态行”开始):

Note: I know that I have "set noshowmode", but I already did "set showmode" and it didn't work.注意:我知道我有“set noshowmode”,但我已经做了“set showmode”,但它没有用。 I only did "set noshowmode" because I don't need the mode to be shown twice...我只做了“设置 noshowmode”,因为我不需要显示两次的模式......

" ------------------   VIM Configuration   -------------------------

set nocompatible " VI compatible mode is disabled so that VIm things work
syntax on " enable syntax processing
syntax enable
set encoding=utf-8

filetype indent on " load filetype-specific indent files
filetype on
filetype plugin on " load filetype specific plugin files


" >>>>> Spaces & Tabs
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set smartindent
" ----------------------------------------------------------


" >>>>> Buffers
set hidden " Allows having hidden buffers without saving them
" ----------------------------------------------------------


" >>>>> UI Config 

set number  " show line numbers 
set colorcolumn=80  "Know where I am
highlight ColorColumn ctermbg=white
set nowrap
set scrolloff=8

set wildmenu  " visual autocomplete for command menu 

set nobackup " backup file is immediately deleted upon successfully writing the original file.
set noswapfile

let python_highlight_all=1
set omnifunc=syntaxcomplete#Complete
" ----------------------------------------------------------


" >>>>> Searching

set path+=**
set incsearch         " search as characters are entered
set ignorecase        " Ignore case in searches by default
set smartcase         " But make it case sensitive if an uppercase is entered
" ----------------------------------------------------------


" >>>>> Status line

" status bar colors
au InsertEnter * hi statusline guifg=black guibg=#d7afff ctermfg=black ctermbg=magenta
au InsertLeave * hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan
hi statusline guifg=black guibg=#8fbfdc ctermfg=black ctermbg=cyan

" default: set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)

" Status Line Custom
let g:currentmode={
    \ 'n'  : 'Normal',
    \ 'no' : 'Normal·Operator Pending',
    \ 'v'  : 'Visual',
    \ 'V'  : 'V·Line',
    \ '^V' : 'V·Block',
    \ 's'  : 'Select',
    \ 'S'  : 'S·Line',
    \ '^S' : 'S·Block',
    \ 'i'  : 'Insert',
    \ 'R'  : 'Replace',
    \ 'Rv' : 'V·Replace',
    \ 'c'  : 'Command',
    \ 'cv' : 'Vim Ex',
    \ 'ce' : 'Ex',
    \ 'r'  : 'Prompt',
    \ 'rm' : 'More',
    \ 'r?' : 'Confirm',
    \ '!'  : 'Shell',
    \ 't'  : 'Terminal'
    \}

set laststatus=2
set noshowmode
set statusline=
set statusline+=%0*\ %n\                                 " Buffer number
set statusline+=%1*\ %<%F%m%r%h%w\                       " File path, modified, readonly, helpfile, preview
set statusline+=%3*│                                     " Separator
set statusline+=%2*\ %Y\                                 " FileType
set statusline+=%3*│                                     " Separator
set statusline+=%2*\ %{''.(&fenc!=''?&fenc:&enc).''}     " Encoding
set statusline+=\ (%{&ff})                               " FileFormat (dos/unix..)
set statusline+=%=                                       " Right Side
set statusline+=%2*\ col:\ %02v\                         " Column number
set statusline+=%3*│                                     " Separator
set statusline+=%1*\ ln:\ %02l/%L\ (%3p%%)\              " Line number / total lines, percentage of document
set statusline+=%0*\ %{toupper(g:currentmode[mode()])}\  " The current mode

hi User1 ctermfg=007 ctermbg=239 guibg=#4e4e4e guifg=#adadad 
hi User2 ctermfg=007 ctermbg=236 guibg=#303030 guifg=#adadad
hi User3 ctermfg=236 ctermbg=236 guibg=#303030 guifg=#303030
hi User4 ctermfg=239 ctermbg=239 guibg=#4e4e4e guifg=#4e4e4e
" ----------------------------------------------------------



" >>>>> Netrw (File Tree)

let g:netrw_banner=0        " disable annoying banner
let g:netrw_browse_split=4 " open in prior window
let g:netrw_altv=1          " open splits to the right                    
let g:netrw_liststyle=3     " tree view
let g:netrw_list_hide=netrw_gitignore#Hide()
let g:netrw_list_hide.=',\(^\|\s\s\)\zs\.\S\+'
let g:netrw_winsize = 75
" ----------------------------------------------------------

在此处输入图像描述

The closest I can get:我能得到的最接近的:

autocmd CmdlineEnter * redrawstatus

As always, autocommands belong in augroups.与往常一样,自动命令属于 augroups。 If you don't know what that means, it means that you want to copy and paste all of the following into your vimrc, not just that first line I gave:如果你不知道这意味着什么,这意味着你想将以下所有内容复制并粘贴到你的 vimrc 中,而不仅仅是我给出的第一行:

augroup statusline
    autocmd!
    autocmd CmdlineEnter * redrawstatus
augroup END

Notice that this will not affect all statuslines, just the window which you were in before entering the command line.请注意,这不会影响所有状态行,只会影响您在进入命令行之前所在的 window。 This answer is not fully tested, or even tested for more than 45 seconds, and I'm sure there's some edge case I have overlooked or some ways this answer can be improved.这个答案没有经过全面测试,甚至测试超过 45 秒,我确信我忽略了一些边缘情况,或者可以通过某些方法改进这个答案。 I will edit this if I think of those.如果我想到这些,我会编辑这个。 Whether CmdlineLeave is worth adding, I'm not sure. CmdlineLeave是否值得添加,我不确定。 I am sure that CmdlineChanged is a bad idea to add.我确信添加CmdlineChanged是个坏主意。

Now for the rest of your vimrc.现在为你的 vimrc 的 rest。 There are some things you probably want to change in it.您可能希望在其中更改一些内容。 For instance:例如:

  • take out set nocompatible取出set nocompatible
  • use syntax on or syntax enable , but not both.使用syntax onsyntax enable ,但不能同时使用。 It's redundant这是多余的
  • filetype plugin indent on can be one line, not three, but I guess it doesn't matter filetype plugin indent on可以是一行,不是三行,但我想没关系
  • settings tabstop to something other than 8 can screw with things, and any behavior that you want can almost certainly be achieved with other settings settings tabstop到 8 以外的东西可能会搞砸事情,你想要的任何行为几乎肯定可以通过其他设置来实现
  • smartindent is outdated and no longer recommended by certain members of the community whom I trust smartindent已过时,我信任的社区中的某些成员不再推荐
  • adding ** to path is commonly done, but that doesn't mean it's a good idea通常会在path中添加** ,但这并不意味着这是一个好主意
  • no hlsearch ?没有hlsearch
  • autocommands should be in augroups自动命令应该在 augroups 中
  • in g:currentmode , are ^V and ^S each one character or two?g:currentmode中, ^V^S是一个字符还是两个字符? They won't match if they're two如果他们是两个,他们将不匹配

And that's as far as I looked.这就是我所看到的。 I'm sure there's more others can recommend.我相信还有更多其他人可以推荐。 If you don't want to directly runtime it, defaults.vim isn't a bad place to look for vimrc ideas.如果您不想直接runtime它, defaults.vim是寻找 vimrc 想法的好地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM