vim配置备份及tips

terminal有新建窗口、在窗口间切换、分割窗口、全屏显示、调整大小快捷键;

shift+F10开启terminal菜单;

shift+Prtsc 截取部分区域保存至Pictures;

shift+insert 可以从系统复制到terminal,分割窗口可以从一个文件复制到另一个文件;

mkdir 新建文件夹,rm -d 删除文件夹,touch 新建文件,rm -f 删除文件;

重命名文件:mv oldname  newname;

重定义路径:mv oldname  /*/*/newname;

:reg 查看寄存器内容,安装gnome才能看见 + 寄存器;

复制粘贴的时候选定,然后 “+y 就可以了,不要加冒号

 

vim中有很强大的 map 键盘映射功能;

按 v 进入visual模式,C-v 进入 visual block 模式,shift-v 进入 visual line 模式;

vim的命令默认不显示,配置中 set showcmd 会在最下一行显示;

编辑高亮显示时首先需要开启高亮,set corsorline;

set backspace=2 重启后就可以让backspace键在insert模式下删除了;

set list 显示tab、回车键;

set expandtab 将tab换成空格,以免格式错误;

gg=G 或  n==  (从当前行往下的n行)整理格式;

mac下可能需要新建 .vimrc 配置文件;

设置里点击要禁用的快捷键,按键盘“Backspace”键,就可以禁用了;

vim配置里设置映射无效,需要安装vim-gnome,卸载vim-tiny;

 esc键太难按了,可以用 Ctrl + [ 代替

 normal模式下按%,可以跳到匹配括号处

((, )), [[, ]], {{, }} 都可以跳转

set wildmenu 能帮你在命令行补全函数,带你走进补全的文明时代。但是要求laststus >= 2

set 后跟一个变量,再跟一个 ?可以查看变量的值 e.g. se ls? 输出laststatus=1

se cuc ( set cursorcolum) 有一个垂直的竖杠,帮看你的python代码有没有单行超过79字符

:Sex (嫑鄙视我 - -)在当前terminal查看当前文件夹,进行编辑或跳转



作者:Charles Wu
链接:https://www.zhihu.com/question/27478597/answer/36897603
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

 

vim真是太强了!

 

 vim配置备份:

 1 set showcmd  "默认
 2 set nowrap
 3 “set mouse=a
 4 set ruler            "默认
 5 set completeopt=preview,menu
 6 set novisualbell
 7 set matchtime=1
 8 set fillchars=vert:\ ,stl:\ ,stlnc:\
 9 set clipboard+=unnamed 
10 :set makeprg=g++\ -Wall\ \ %
11 autocmd FileType c,cpp map<buffer> <leader><space> :w<cr>:make<cr>
12 nnoremap <C-J> <C-W><C-J>
13 nnoremap <C-K> <C-W><C-K>
14 nnoremap <C-H> <C-W><C-H>
15 map<M-F2> :tabnew<CR>
16 map<F3> :tabnew .<CR>
17 map<C-F3> /be
18 
19  
20 
21 syntax on
22 set number
23 set shiftwidth=4
24 set tabstop=4
25 set scrolloff=3
26 set hlsearch
27 set confirm
28 set cindent
29 map<C-A> ggVG"+y
30 
31 map<F5> :call Run()<CR>
32 
33 func! Run()
34 
35     exec "w"
36 
37  if &filetype == 'c'
38 
39     exec "!g++ % -o %<"
40 
41     exec "!time ./%<"
42 
43  elseif &filetype == 'cpp'
44 
45      exec "!g++ % -o %<"
46 
47      exec "!time ./%<"
48 
49  elseif &filetype == 'java'
50 
51      exec "!javac %"
52 
53     exec "!time java %<"
54 
55  elseif &filetype == 'sh'
56 
57     :!time bash %
58 
59  elseif &filetype == 'python'
60 
61      exec "!time python %"
62 
63  elseif &filetype == 'html'
64 
65      exec "!firefox % &"
66 
67  elseif &filetype == 'go'
68 
69      " exec "!go build %<"
70 
71      exec "!time go run %"
72 
73  elseif &filetype == 'mkd'
74 
75      exec "!~/.vim/markdown.pl % > %.html &"
76 
77      exec "!firefox %.html &"
78 
79  endif
80 
81 endfunc
82 
83 
84 set cursorline
85 highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
86 nmap <c-v> "+gp
87 nmap <c-c> "+y
88 inoremap ( ()<ESC>i
89 inoremap [ []<ESC>i
90 inoremap { {}<ESC>i
91 inoremap ' ''<ESC>i
92 inoremap " ""<ESC>i
View Code

 

win10版

 1 syntax on
 2 set number
 3 set shiftwidth=4
 4 set tabstop=4
 5 set scrolloff=3
 6 set hlsearch
 7 set confirm
 8 set cindent
 9 set cursorline
10 
11 highlight CursorLine cterm=NONE ctermbg=black ctermfg=green guibg=NONE guifg=NONE
12 
13 nmap <c-v> "+gp
14 nmap <c-c> "+y
15 inoremap ( ()
16 inoremap [ []
17 inoremap { {}
18 inoremap ' ''
19 inoremap " ""
20 map<C-A> ggVG"+y
21 
22 map<F5> :call Run()<CR>
23 func! Run()
24    exec "w"
25 if &filetype == 'c'
26   exec "!g++ % -o %<"
27   exec "!%<"
28 elseif &filetype == 'cpp'
29   exec "!g++ % -o %<"
30   exec "!%<"
31 elseif &filetype == 'java'
32   exec "!javac %"
33   exec "java %<"
34 elseif &filetype == 'sh'
35   :!time bash %
36 elseif &filetype == 'python'
37   exec "python %"
38 elseif &filetype == 'html'
39   exec "!firefox % &"
40 elseif &filetype == 'go'
41   exec "!go build %<"
42   exec "go run %"
43 elseif &filetype == 'mkd'
44   exec "!~/.vim/markdown.pl % > %.html &"
45   exec "!firefox %.html &"
46 endif
47 endfunc
48 
49 
50 set diffexpr=MyDiff()
51 func! MyDiff()
52   let opt = '-a --binary '
53   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
54   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
55   let arg1 = v:fname_in
56   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
57   let arg1 = substitute(arg1, '!', '\!', 'g')
58   let arg2 = v:fname_new
59   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
60   let arg2 = substitute(arg2, '!', '\!', 'g')
61   let arg3 = v:fname_out
62   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
63   let arg3 = substitute(arg3, '!', '\!', 'g')
64   if $VIMRUNTIME =~ ' '
65     if &sh =~ '\<cmd'
66       if empty(&shellxquote)
67         let l:shxq_sav = ''
68         set shellxquote&
69       endif
70       let cmd = '"' . $VIMRUNTIME . '\diff"'
71     else
72       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
73     endif
74   else
75     let cmd = $VIMRUNTIME . '\diff'
76   endif
77   let cmd = substitute(cmd, '!', '\!', 'g')
78   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
79   if exists('l:shxq_sav')
80     let &shellxquote=l:shxq_sav
81   endif
82 endfunc
View Code

 

win10上的按键映射好像用不了。。不能一键运行,不太好用,不过比之前美观

 1 syntax on
 2 set number
 3 set ruler
 4 set shiftwidth=4
 5 set tabstop=4
 6 set scrolloff=3
 7 set hlsearch
 8 set confirm
 9 set cindent
10 set cursorline
11 set guifont=Cascadia\ Mono:h12
12 colorscheme desert 
13 set background=dark
14 highlight CursorLine cterm=NONE ctermbg=black ctermfg=blue guibg=NONE guifg=NONE
15 
16 nmap <c-v> "+gp
17 nmap <c-c> "+y
18 map <C-A> ggVG"+y
19 
20 map <F5> :call Run()<CR>
21 func! Run()
22    exec "w"
23 if &filetype == 'c'
24   exec "!g++ % -o %<"
25   exec "!%<"
26 elseif &filetype == 'cpp'
27   exec "!g++ % -o %<"
28   exec "!%<"
29 elseif &filetype == 'java'
30   exec "!javac %"
31   exec "java %<"
32 elseif &filetype == 'sh'
33   :! bash %
34 elseif &filetype == 'python'
35   exec "python %"
36 elseif &filetype == 'html'
37   exec "!firefox % &"
38 elseif &filetype == 'go'
39   exec "!go build %<"
40   exec "go run %"
41 elseif &filetype == 'mkd'
42   exec "!~/.vim/markdown.pl % > %.html &"
43   exec "!firefox %.html &"
44 endif
45 endfunc
46 
47 
48 set diffexpr=MyDiff()
49 func! MyDiff()
50   let opt = '-a --binary '
51   if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
52   if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
53   let arg1 = v:fname_in
54   if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
55   let arg1 = substitute(arg1, '!', '\!', 'g')
56   let arg2 = v:fname_new
57   if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
58   let arg2 = substitute(arg2, '!', '\!', 'g')
59   let arg3 = v:fname_out
60   if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
61   let arg3 = substitute(arg3, '!', '\!', 'g')
62   if $VIMRUNTIME =~ ' '
63     if &sh =~ '\<cmd'
64       if empty(&shellxquote)
65         let l:shxq_sav = ''
66         set shellxquote&
67       endif
68       let cmd = '"' . $VIMRUNTIME . '\diff"'
69     else
70       let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
71     endif
72   else
73     let cmd = $VIMRUNTIME . '\diff'
74   endif
75   let cmd = substitute(cmd, '!', '\!', 'g')
76   silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
77   if exists('l:shxq_sav')
78     let &shellxquote=l:shxq_sav
79   endif
80 endfunc
View Code

 

ubuntu标准版,仅含代码基本格式、复制粘贴和F5运行代码快捷键

set mouse=a 
set shiftwidth=4 
set tabstop=4 
set scrolloff=3 
set hlsearch 
set showmatch 
set confirm 
set cindent 
"set fdm=indent 
"set nobackup 
 
nmap <c-v> "+gp 
nmap <c-c> "+y 
map <C-A> ggVG"+y 
 
map <F5> :call Run()<CR> 
func! Run() 
    exec "w" 
    if &filetype == 'c' 
        exec "!gcc -Wall % -o %<.o" 
        exec "!./%<.o" 
    elseif &filetype == 'cpp' 
        exec "!g++ -Wall % -o %<.o" 
        exec "!./%<.o" 
    elseif &filetype == 'sh' 
        :! bash % 
    elseif &filetype == 'python' 
        exec "python %" 
    elseif &filetype == 'java' 
        exec "!javac %" 
        exec "!java %<" 
    endif 
endfunc 
View Code

 

插件

Yggdroot/indentLine 很好用,划线标明代码是否对齐,加上 filetype indent on 配置就可以很方便地写代码了。

 

posted @ 2018-11-30 16:32  参婵  阅读(515)  评论(0编辑  收藏  举报