簡體   English   中英

在 VIM 上進入命令行模式(“:”)時,如何在狀態欄中顯示命令模式?

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

我從 VIM 開始(是的,只是 VIM,不是 NeoVIM 或任何其他),我在 my.vimrc 中配置了一個 StatusLine,它顯示了我所處的當前模式,所有模式都正確顯示,除了......當我進入命令行模式(“:”)我希望狀態行顯示“命令”,它顯示“正常”(我在底部添加了一個屏幕截圖,顯示狀態行)。

我正在尋找一種無需安裝任何插件的解決方案。 我搜索了很多這個問題,但我沒有找到與這個特定問題相關的任何內容......謝謝!

這是.vimrc (StatusLine 的內容從“>>>>> 狀態行”開始):

注意:我知道我有“set noshowmode”,但我已經做了“set showmode”,但它沒有用。 我只做了“設置 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
" ----------------------------------------------------------

在此處輸入圖像描述

我能得到的最接近的:

autocmd CmdlineEnter * redrawstatus

與往常一樣,自動命令屬於 augroups。 如果你不知道這意味着什么,這意味着你想將以下所有內容復制並粘貼到你的 vimrc 中,而不僅僅是我給出的第一行:

augroup statusline
    autocmd!
    autocmd CmdlineEnter * redrawstatus
augroup END

請注意,這不會影響所有狀態行,只會影響您在進入命令行之前所在的 window。 這個答案沒有經過全面測試,甚至測試超過 45 秒,我確信我忽略了一些邊緣情況,或者可以通過某些方法改進這個答案。 如果我想到這些,我會編輯這個。 CmdlineLeave是否值得添加,我不確定。 我確信添加CmdlineChanged是個壞主意。

現在為你的 vimrc 的 rest。 您可能希望在其中更改一些內容。 例如:

  • 取出set nocompatible
  • 使用syntax onsyntax enable ,但不能同時使用。 這是多余的
  • filetype plugin indent on可以是一行,不是三行,但我想沒關系
  • settings tabstop到 8 以外的東西可能會搞砸事情,你想要的任何行為幾乎肯定可以通過其他設置來實現
  • smartindent已過時,我信任的社區中的某些成員不再推薦
  • 通常會在path中添加** ,但這並不意味着這是一個好主意
  • 沒有hlsearch
  • 自動命令應該在 augroups 中
  • g:currentmode中, ^V^S是一個字符還是兩個字符? 如果他們是兩個,他們將不匹配

這就是我所看到的。 我相信還有更多其他人可以推薦。 如果您不想直接runtime它, defaults.vim是尋找 vimrc 想法的好地方。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM