Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

Copy from Vim to VSCode causing extra tab

Having copied normaly indented text from Vim into the system clipboard using "+y, I paste it VSCode. Each line that is tab-indented will be indented two-tab width as the picture shows.

Code in Vim: Code in Vim

Code in VSCode copied from Vim: Code in VSCode copied from Vim

shiftwidth is set to 4 in my .vimrc and tab size is set to 4 in VSCode.

Below is my full .vimrc:

call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'jiangmiao/auto-pairs'

" Theme
Plug 'phanviet/vim-monokai-pro' 
Plug 'sainnhe/sonokai'
Plug 'crusoexia/vim-monokai'
Plug 'chriskempson/base16-vim'

" Syntax highlighting
Plug 'sheerun/vim-polyglot'

" Master Vim
Plug 'takac/vim-hardtime'

" Autocomplete
Plug 'ycm-core/YouCompleteMe'

" Full path fuzzy file, buffer, mru, tag, ... finder
Plug 'ctrlpvim/ctrlp.vim'

" Move line
Plug 'matze/vim-move'

" Window
Plug 'tpope/vim-vinegar'

" Status bar
Plug 'vim-airline/vim-airline'

" Git tool
Plug 'tpope/vim-fugitive'

" Comment stuff
Plug 'tpope/vim-commentary'

" Syntax checking
Plug 'vim-syntastic/syntastic'
call plug#end()

" Basics
set nocompatible
filetype plugin on
syntax on
set encoding=utf-8
set fileencoding=utf-8
set shiftwidth=4

" Enable autocompletion
set wildmode=longest,list,full

" Comment stuff
autocmd FileType apache setlocal commentstring=# %s
autocmd FileType c,cpp,java,lisp setlocal commentstring=// %s

" Relative number
set number relativenumber 
set nu rnu

" Disable automatic commenting on newline
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o

" Splits open at the bottom and the right 
set splitbelow splitright

" Shortcutting split navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l

" Treat numbers as decimals
set nrformats-=octal

" Theme
set t_Co=256
set background=dark
let g:sonokai_style = 'shusia'
let g:sonokai_enable_italic = 1
let g:sonokai_disable_italic_comment = 1
colorscheme monokai_pro
let g:airline_theme = 'sonokai'

" NERDTree
nmap <F6> :NERDTreeToggle<CR>

" Arrow keys are dead, stupid
noremap <Up> :echo "Arrow keys are dead, stupid!"<CR>
noremap <Down> :echo "Arrow keys are dead, stupid!"<CR>
noremap <Left> :echo "Arrow keys are dead, stupid!"<CR>
noremap <Right> :echo "Arrow keys are dead, stupid!"<CR>

inoremap <Up> <esc>:echo "Arrow keys are dead, stupid!"<CR>
inoremap <Up> <nop>
inoremap <Down> <esc>:echo "Arrow keys are dead, stupid!"<CR>
inoremap <Left> <esc>:echo "Arrow keys are dead, stupid!"<CR>
inoremap <Right> <esc>:echo "Arrow keys are dead, stupid!"<CR>

nnoremap ? :m .+1<CR>==
nnoremap ? :m .-2<CR>==

inoremap ? <Esc>:m .+1<CR>==gi
inoremap ? <Esc>:m .-2<CR>==gi

vnoremap ? :m '>+1<CR>gv=gv
vnoremap ? :m '<-2<CR>gv=gv
" Master Vim
let g:hardtime_default_on = 0

" ctrlp
let g:ctrlp_map = '<c-p>'

My computer's system version is macOS Catalina 10.15.7.

question from:https://stackoverflow.com/questions/65951743/copy-from-vim-to-vscode-causing-extra-tab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

there are 3 settings actually you should use for vim if you want all files with tabs with width 4 spaces

:set shiftwidth=4
:set tabstop=4
:retab

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...