When I look at a file on one of our servers I see something like this:
<feff>sku;qty
productsku;1
When I download the file and open it with vi I don't see the <feff>
When I do :e ++bin I can see the <feff> but I also see ^M now
<feff>sku;qty^M
productsku;1^M
But I don't want to set the ^M. I just want to see the <feff>.
Another example is <80> which I had in another file.
How can I set up vim to show me those special chars?
~ EDIT ~
The command vi --version tells me the following:
VIM - Vi IMproved 7.0 (2006 May 7, compiled Aug 4 2010 07:21:08)
It also says that the system-vimrc-file is /etc/vimrc which has the following content:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=utf-8,latin1
endif
set term=builtin_ansi
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
I copied this and added it to my ~/.vimrc but none of these changes does what I want. A few things are in if cases so I might have to play around with these too.
Does anyone know if there are other files than the one stated in vi --version that will be read when editing a file?
:help 'bomb' explains Vim's behavior:
When Vim reads a file and 'fileencodings' starts with "ucs-bom", a
check for the presence of the BOM is done and 'bomb' set accordingly.
Unless 'binary' is set, it is removed from the first line, so that you
don't see it when editing.
So,
:set fencs-=ucs-bom
would turn this off, but then the encoding detection is broken, too! According to my experiments, explicit encoding setting (via :edit ++enc=ucs2-le) also sets 'bomb' and removes the <feff> mark. So, this avenue leads nowhere.
Alternatives
Editing in binary mode, as you've found out. I wouldn't recommend it, since it has drawbacks.
Including the indication in the statusline. You have to look somewhere else, but it's always visible, not just at the beginning of the document. Highly recommended as the right way™ in Vim. And easy to achieve, too:
set statusline+=\ %{&bomb?'BOM':''}
Related
I am a beginning vim user and I am a little confused. It looks like Vim is slower than Geany. And it is a very noticeable difference. When I hold any key in Geany it prints it without any lag (llllllll for example). In Vim it is slow and jumping. Autocomplete in vim is horrible in comparison to Geany. I thought Vim is as fast as light. It looks like it isn't. Is there any advice to change that, make vim faster?
This is my _vimrc file:
" This must be first, because it changes other options as side effect
set nocompatible
" Use pathogen to easily modify the runtime path to include all
" plugins under the ~/.vim/bundle directory
call pathogen#helptags()
call pathogen#infect()
" change the mapleader from \ to ,
let mapleader=","
" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>
set hidden
set nowrap " don't wrap lines
set tabstop=4 " a tab is four spaces
set backspace=indent,eol,start
" allow backspacing over everything in insert mode
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch " set show matching parenthesis
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
set smarttab " insert tabs on the start of a line according to
" shiftwidth, not tabstop
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set noerrorbells " don't beep
set nobackup
set noswapfile
filetype plugin indent on
autocmd filetype python set expandtab
if &t_Co >= 256 || has("gui_running")
colorscheme badwolf
endif
if &t_Co > 2 || has("gui_running")
" switch syntax highlighting on, when the terminal has colors
syntax on
endif
" Vim can highlight whitespaces for you in a convenient way:
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.
set pastetoggle=<F2>
set mouse=a " Enable mouse
set encoding=utf-8
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
set autochdir " working directory is always the same as the file you are editing
noremap <F5> :w !python %<CR>
inoremap <F5> <ESC>:w !python %<CR>
nmap <leader>t :NERDTree<CR>
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
set guifont=Hack:h10:cDEFAULT
let g:Powerline_symbols = 'fancy'
set laststatus=2
python from powerline.vim import setup as powerline_setup
python powerline_setup()
python del powerline_setup
filetype plugin on
set omnifunc=syntaxcomplete#Complete
au CompleteDone * pclose
set completeopt=longest,menuone,preview
set guioptions-=T
set nofoldenable " disable folding
nmap <silent> ,/ :nohlsearch<CR>
It could be a lot of things, not necessarily Vim's fault. Actually it's unlikely to be vim's fault.
First, get a feel for how fast Vim can be: run with vim -u NONE and comment out everything in your .vimrc - then do the single thing that seems slow.
Run without the -u NONE and compare. It should be just as fast, or some plugin is autoloaded and is causing problems. If so, try and temporarily move files away from the ~/.vim/bundle directory.
Next, uncomment half of your .vimrc and check if it causes the slowness or not. Keep commenting/uncommenting until you find the exact line.
Google the line that caused the slowness and find out if there are alternatives.
I'm guessing you could be doing an expensive operation with every scroll, such as checking the file syntax.
It's best to hunt down the slowness step by step.
Another issue may be slow terminal and/or drivers (so compare Vim with GVim). If you have a slow terminal with fancy fonts, transparency, small font and big screen size, terminals can be very, very, VERY slow.
If you use vim in terminal like me (and not GVim), I just found that, try, and it seems pretty good :
add this in your ~/.vimrc :
set timeoutlen=1000
set ttimeoutlen=0
and this (even more important) in your ~/.screenrc :
maptimeout 0
Since I did that, everything is better.
My vim started to fly after I added the following config to my vimrc, this is extremely useful when you keep vim running all day/week long editing a lot of different files with opening and closing them often.
function! CloseHiddenBuffers()
" >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
" close any buffers hidden
" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
let open_buffers = []
for i in range(tabpagenr('$'))
call extend(open_buffers, tabpagebuflist(i + 1))
endfor
for num in range(1, bufnr("$") + 1)
if buflisted(num) && index(open_buffers, num) == -1
exec "bdelete ".num
endif
endfor
endfunction
au BufEnter * call CloseHiddenBuffers()
I had a similar problem where pasting paragraphs of text or just typing at a typical speed would hang vim.
You could troubleshoot your .vimrc, and if you are, take a look at this question to see which plugins are slow. You could also skip the troubleshooting and use neovim, which is fully compatible with vim and asynchronous.
My issues with input lag disappeared once I started using it. It uses an async library libuv, which is the same library powering node. I'm using the same .vimrc as with vim (copied to ~/.config/nvim/init.vim), so it's not a matter of different plugins. I also see this responsiveness improvement on both Ubuntu 20.04 and Macos 10.14.
I'm posting this answer because I wish it had existed when I last read this question.
So vim just suddenly started flaking out on me today and I can't pinpont the problem. Haven't touch the configuration file and the last thing I worked on before I noticed the problem was updating my sshd_config and sshd_config.pacnew files.
What I noticed is that upon opening the sshd_config file is vim starting out in insert mode and automatically inserted a series special characters wherever the curser was at the moment. So it overwrites information in configuration files. I guess that can become somewhat problematic =)
So if I start a new file touch test_vim && vim test_vim this is what I see:
:bfff/00fe/00fe/13fe[>85;95;0c
I have a feeling this is going to be one of those things that's really stupid and I completely overlooked. Does anyone have any idea what's going on?
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last change: 2014 Feb 05
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
set undofile " keep an undo file (undo changes after closing)
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
This is a recent Vim bug. You should probably roll back to an earlier release while a proper fix is worked on.
You can have a look about changing the vim configuration files on this post
this is the official vim wiki page
Vim wiki
So the bug seems to affect urxvt terminals running with transparency. Using a different terminal, or in my case disabling transparency via /.Xresources will temporarily solve the issue until they release a patch.
SOLVED: bad colorscheme .vim file.
Whenever I start up vim, I always get a flood of errors and then a "Press ENTER or type command to continue" message. Then vim works fine.
I just have no idea what the cause of it is.I am on a Linux machine.
line 5045:
E488: Trailing characters: </div>
line 5048:
E488: Trailing characters: <script crossorigin=
line 5049:
E488: Trailing characters: <script async=
line 5052:
E488: Trailing characters: <script async src=
line 5053:
E488: Trailing characters: </body>
line 5054:
E488: Trailing characters: </html>
Press ENTER or type command to continue
Here is my .vimrc file. It is just the example one with some editing. I am still a beginner.
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last change: 2011 Apr 15
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
syntax enable
colorscheme solarized
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
execute pathogen#infect()
set nopaste
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
set number
Vim complains about HTML tags, so it looks like you've installed a bad Vimscript, grabbing a (formatted) web page instead of the raw contents.
Either go back to the page and copy/paste from the browser, or (e.g. in GitHub) get the raw file contents and save that.
I'm using VIM for writing some basic C algorithms. I have some key binded to SCCompile plugin and when I press it it will compile my program. If there is no problem it will show me press any key, and then I'm back in VIM with opened file. But if there is some problem or warning, it will just show me that error and I don't know how can I get back to my file.
Is there some command how can I get back to project? Or do I need reopen it?
There is my .vimrc file:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=ucs-bom,utf-8,latin1
endif
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" All of your Plugins must be added before the following line
call vundle#end() " required
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set nocompatible
filetype plugin indent on
syntax on
silent! runtime macros/matchit.vim
set autochdir
set backspace=indent,eol,start
set foldenable
set hidden
set incsearch
set laststatus=2
set ruler
set switchbuf=useopen,usetab
set tags=./tags,tags;/
set wildmenu
nnoremap gb :buffers<CR>:sb<SPACE>
set number
set tabstop=4
set shiftwidth=4
set softtabstop=4
set fo=cqt
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
autocmd!
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
" don't write swapfile on most commonly used directories for NFS mounts or USB sticks
autocmd BufNewFile,BufReadPre /media/*,/mnt/* set directory=~/tmp,/var/tmp,/tmp
" start with spec file template
autocmd BufNewFile *.spec 0r /usr/share/vim/vimfiles/template.spec
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
filetype plugin on
if &term=="xterm"
set t_Co=8
set t_Sb=[4%dm
set t_Sf=[3%dm
endif
" Don't wake up system with blinking cursor:
" http://www.linuxpowertop.org/known.php
let &guicursor = &guicursor . ",a:blinkon0"
autocmd Filetype c nmap <buffer> <F5> :SCCompileAF -std=c99 -Wall -Wextra -pedantic <CR>
execute pathogen#infect()
From what I can tell the SCCompile plugin is supposed to make it easier to compile thing in Vim. I cannot vouch for this claim but the plugin's documentation states that if an error during compiling then you should use the quickfix list.
To understand this process it is probably easier to first understand Vim's native :make / quickfix workflow.
:make
Running :make will execute the make program, 'makeprg'. Then parse the output with 'errorformat' and put each entry into the quickfix list.
Typically 'makeprg' defaults to the make command which runs a Makefile. However you can change your 'makeprg' via the :compiler command or set it directly.
You can also pass extra arguments to :make. e.g. :make clean
Note: running :make will often show the output of the command at the bottom of the screen with a prompt asking to press enter. Just press enter as all the output will be available in the quickfix list.
quickfix list
After you run :make your quickfix list will hold the output of compiler.
Use the following command to navigate the quickfix list.
:copen to open the quickfix window
:cclose to close the quickfix window
:cnext/:cprev to move to the next/previous item
:cc to print out at the bottom the current error or :cc 3 to show a specific error in this example 3
Personally I use Tim Pope's unimpaired plugin to navigate the quickfix list.
Back to using SCCompile
From what I can tell SCCompile is wrapper around :make that handles setting up 'makeprg' and/or 'errorformat'. Therefore SCCompile is just a drop in replacement for :make. To compile just execute your SCCompile mapping and then use the quickfix list to check your errors.
Please take a look at SCCompile's documentation: :h SingleCompile-overview and :h SingleCompile-contents.
Conclusion
As you are a newbie then I would suggest creating a Makefile and using :make because that will keep things very simple and as well as have a nice record of how you compiled your program.
I would also suggest you look into create a mapping to run :make. Example:
nnoremap <f5> :make<cr>
For more information see
:h :make
:h 'makeprg'
:h 'errorformat'
:h :compiler
:h quickfix
:h :cc
:h :cope
:h :cnext
I am getting garbage characters on pressing of arrow keys when I open a vim file.
I have also defined following in my ~/.vimrc:
set nocompatible
I am using putty for login. Is this a putty issue?
Please help
EDIT: if I remove my ~/.vimrc, then problem is also removed.
I have used following code as .vimrc file, and it has resolved all my problem.
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
Just save the above text as
.vimrc