我试图在我的VIM中实现代码折叠。 我相信它们的标准命令是za,zc,zo等。 据我所知,人们不需要做任何特别的事情来使这些命令发挥作用。 我主要是JS程序员。
但是这些命令都不能在我的VIM中运行。我正在使用VIM 7.2
下面是我的.vimrc文件 我提出我的整个.vimrc文件的原因是因为我猜可能有一个我正在使用的插件可能导致折叠命令不起作用。
如果有人知道这里有什么不妥之处..请指出。
" Start pathogen plugins "
call pathogen#infect()
" Automatic syntax highlight on "
syntax on
" Necessary for NerdCommenter to Work "
filetype plugin indent on
set nocompatible
source $VIMRUNTIME/vimrc_example.vim
" Replace tabs with spaces "
set expandtab
" Make tab 2 space wide
set tabstop=2
set shiftwidth=2
" If I am in an indented block of code, keep the indentation level when I "
" press enter "
set autoindent
" Stop vim from creating automatic backups "
set nobackup
set noswapfile
set nowb
set nowritebackup
" Show line numbers "
set number
" Shift+Tab unindents a line "
imap <S-Tab> <Esc><<i
nmap <S-tab> <<
" Remove trailing spaces when saving a file "
autocmd BufWritePre * :%s/\s\+$//e
" Highlight all occurances of search "
set hlsearch
" Ignore case during search
set ignorecase
" Show tabs and trailing spaces "
set list listchars=tab:.\ ,trail:·
" set colorscheme "
colorscheme desert
set background=dark
set ff=unix
set showtabline=2
set smarttab
set incsearch
" Store a history of commands "
set history=1000
" Number of undo levels "
set undolevels=1000
" Change title of tab "
set title
" Open nerdtree plugin when vim starts "
let g:nerdtree_tabs_open_on_console_startup=1
au BufNewFile,BufRead *.less set filetype=less
let g:DirDiffExcludes = ".svn,*.swp"
let Grep_Skip_Dirs = '.svn'
" smart way to move between windows
map <C-j> <C-W>j
map <C-k> <C-W>k
map <C-h> <C-W>h
map <C-l> <C-W>l
" useful mappings for managing tabs
map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove
set wrap linebreak nolist
nnoremap tp :tabprev<CR>
nnoremap tn :tabnext<CR>
nnoremap tf :tabfirst<CR>
nnoremap tl :tablast<CR>
highlight ExtraWhitespace ctermbg=red guibg=red
match ExtraWhitespace /\s\+$/
autocmd BufWinEnter * match ExtraWhitespace /\s\+$/
autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
autocmd InsertLeave * match ExtraWhitespace /\s\+$/
autocmd BufWinLeave * call clearmatches()
function! TrimWhiteSpace()
%s/\s\+$//e
endfunction
autocmd BufWritePre *.* :call TrimWhiteSpace()
答案 0 :(得分:0)
我相信要使折叠命令起作用,你需要设置foldmethod选项。在我看来,最简单的就是'缩进'。
答案 1 :(得分:0)
我用:
vmap <F4> zf
vmap <F5> zd
在我的.vimrc文件中。这允许我使用F4和F5键进行折叠/展开。