When I try to open a file for editing using vim I get this following message and error detected message.
Jashs-MacBook-Pro:hello jashjacob$ vim hello.rb
--- Auto-Commands ---
filetypedetect BufRead
*if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat | runtime! scripts.vim | endif
*if !did_filetype() && expand("<amatch>") !~ g:ft_ignore_pat && (getline(1) =~ '^#' || getline(2) =~ '^#' || getline(3) =~ '^#'^I|| getline(4) =~ '^#' || getline(5) =~ '^#') | setf conf | endif
Error detected while processing /usr/share/vim/vimrc:
line 18:
E116: Invalid arguments for function line("'"") > 0 && line ("'"") <= line("$") |
E15: Invalid expression: line("'"") > 0 && line ("'"") <= line("$") |
Press ENTER or type command to continue
Have my vim editor files been damaged/modified ? How can i fix the error detected while processing /usr/share/vim/vimrc ?
/usr/share/vim/vimrc config file contains the following
" Configuration file for vim
set modelines=0 " CVE-2007-2438
" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible " Use Vim defaults instead of 100% vi compatibility
set backspace=2 " more powerful backspacing
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
if ! exists("g:leave_my_cursor_position_alone") |
if line("'"") > 0 && line ("'"") <= line("$") |
exe "normal g'"" |
endif |
endif
" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup
I'm not a vimscript guru, so perhaps someone will be able to offer more of a fix, but I can suggest that if you just want to get vim working again you could comment out the function that's causing the trouble. Precede each line with a double-quote symbol (") and you should be able to get on with things.
Like so:
" When editing a file, always jump to the last cursor position
"autocmd BufReadPost *
" if ! exists("g:leave_my_cursor_position_alone") |
" if line("'"") > 0 && line ("'"") <= line("$") |
" exe "normal g'"" |
" endif |
" endif
If you want to preserve this functionality, you might have to learn a little vimscript. :)
I think these error messages could also come from the fact that you missed or miss-placed "set nocompatible" in your .vimrc. That will cause your Vim misunderstood the backslashes used to continue long lines in it's scripting files. It's better to put "set nocompatible" at the very beginning of your .vimrc file.
If you see "if !did_filetype() ..." in the error message and compared it with the code in /usr/share/vim/vim{yourversion}/filetype.vim you can tell that there should be a "\" in between "" and "if".
see this entry for more details
YOU ARE NOT SUPPOSED TO DO ANYTHING IN /usr/share/vim/.
That file you have edited is not yours and should not be changed at all. These are the files and places where you can do whatever you want:
~/.vim/ <-- put your plugins and colorschemes in this directory
~/.vimrc <-- add your options and mappings to this file
As for your question:
Those lines were not added by a plugin, they were added by you or someone else who has access to your machine.
They throw an error because the dumbass who pasted them somehow thought it was a good idea to remove the line-continuation backslashes that are in the "original" (or this "original", or that one, or the older link in the post that leads to a 404, or the simpler version that is in $VIMRUNTIME/vimrc_example.vim).
Never run a command you find on the internet unless you are sure it won't cause troubles.
Related
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':''}
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 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
Right now I have the following in my .vimrc:
au BufWritePost *.c,*.cpp,*.h !ctags -R
There are a few problems with this:
It's slow -- regenerates tags for files that haven't changed since the last tag generation.
I have to push the enter button again after writing the file because of an inevitable "press Enter or type command to continue".
When you combine these two issues I end up pushing the additional enter too soon (before ctags -R has finished), then see the annoying error message, and have to push enter again.
I know it doesn't sound like a big deal, but with the amount of file writes I do on a given day it tends to get really annoying. There's gotta be a better way to do it!
au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &
The downside is that you won't have a useful tags file until it completes. As long as you're on a *nix system it should be ok to do multiple writes before the previous ctags has completed, but you should test that. On a Windows system it won't put it in the background and it'll complain that the file is locked until the first ctags finishes (which shouldn't cause problems in vim, but you'll end up with a slightly outdated tags file).
Note, you could use the --append option as tonylo suggests, but then you'll have to disable tagbsearch which could mean that tag searches take a lot longer, depending on the size of your tag file.
Edit: A solution very much along the lines of the following has been posted as the AutoTag vim script. Note that the script needs a vim with Python support, however.
My solution shells out to awk instead, so it should work on many more systems.
au FileType {c,cpp} au BufWritePost <buffer> silent ! [ -e tags ] &&
\ ( awk -F'\t' '$2\!="%:gs/'/'\''/"{print}' tags ; ctags -f- '%:gs/'/'\''/' )
\ | sort -t$'\t' -k1,1 -o tags.new && mv tags.new tags
Note that you can only write it this way in a script, otherwise it has to go on a single line.
There’s lot going on in there:
This auto-command triggers when a file has been detected to be C or C++, and adds in turn a buffer-local auto-command that is triggered by the BufWritePost event.
It uses the % placeholder which is replaced by the buffer’s filename at execution time, together with the :gs modifier used to shell-quote the filename (by turning any embedded single-quotes into quote-escape-quote-quote).
That way it runs a shell command that checks if a tags file exists, in which case its content is printed except for the lines that refer to the just-saved file, meanwhile ctags is invoked on just the just-saved file, and the result is then sorted and put back into place.
Caveat implementor: this assumes everything is in the same directory and that that is also the buffer-local current directory. I have not given any thought to path mangling.
I wrote easytags.vim to do just this: automatically update and highlight tags. The plug-in can be configured to update just the file being edited or all files in the directory of the file being edited (recursively). It can use a global tags file, file type specific tags files and project specific tags files.
I've noticed this is an old thread, however...
Use incron in *nix like environments supporting inotify. It will always launch commands whenever files in a directory change. i.e.,
/home/me/Code/c/that_program IN_DELETE,IN_CLOSE_WRITE ctags --sort=yes *.c
That's it.
Perhaps use the append argument to ctags as demonstrated by:
http://vim.wikia.com/wiki/Autocmd_to_update_ctags_file
I can't really vouch for this as I generally use source insight for code browsing, but use vim as an editor... go figure.
How about having ctags scheduled to run via crontab? If your project tree is fairly stable in it's structure, that should be doable?
To suppress the "press enter" prompt, use :silent.
On OSX this command will not work out of the box, at least not for me.
au BufWritePost *.c,*.cpp,*.h silent! !ctags -R &
I found a post, which explains how to get the standard ctags version that contains the -R option. This alone did not work for me. I had to add /usr/local/bin to the PATH variable in .bash_profile in order to pick up the bin where Homebrew installs programs.
In my opninion, plugin Indexer is better.
http://www.vim.org/scripts/script.php?script_id=3221
It can be:
1) an add-on for project.tar.gz
2) an independent plugin
background tags generation (you have not wait while ctags works)
multiple projects supported
There is a vim plugin called AutoTag for this that works really well.
If you have taglist installed it will also update that for you.
The --append option is indeed the way to go. Used with a grep -v, we can update only one tagged file. For instance, here is a excerpt of an unpolished plugin that addresses this issue. (NB: It will require an "external" library plugin)
" Options {{{1
let g:tags_options_cpp = '--c++-kinds=+p --fields=+imaS --extra=+q'
function! s:CtagsExecutable()
let tags_executable = lh#option#Get('tags_executable', s:tags_executable, 'bg')
return tags_executable
endfunction
function! s:CtagsOptions()
let ctags_options = lh#option#Get('tags_options_'.&ft, '')
let ctags_options .= ' '.lh#option#Get('tags_options', '', 'wbg')
return ctags_options
endfunction
function! s:CtagsDirname()
let ctags_dirname = lh#option#Get('tags_dirname', '', 'b').'/'
return ctags_dirname
endfunction
function! s:CtagsFilename()
let ctags_filename = lh#option#Get('tags_filename', 'tags', 'bg')
return ctags_filename
endfunction
function! s:CtagsCmdLine(ctags_pathname)
let cmd_line = s:CtagsExecutable().' '.s:CtagsOptions().' -f '.a:ctags_pathname
return cmd_line
endfunction
" ######################################################################
" Tag generating functions {{{1
" ======================================================================
" Interface {{{2
" ======================================================================
" Mappings {{{3
" inoremap <expr> ; <sid>Run('UpdateTags_for_ModifiedFile',';')
nnoremap <silent> <Plug>CTagsUpdateCurrent :call <sid>UpdateCurrent()<cr>
if !hasmapto('<Plug>CTagsUpdateCurrent', 'n')
nmap <silent> <c-x>tc <Plug>CTagsUpdateCurrent
endif
nnoremap <silent> <Plug>CTagsUpdateAll :call <sid>UpdateAll()<cr>
if !hasmapto('<Plug>CTagsUpdateAll', 'n')
nmap <silent> <c-x>ta <Plug>CTagsUpdateAll
endif
" ======================================================================
" Auto command for automatically tagging a file when saved {{{3
augroup LH_TAGS
au!
autocmd BufWritePost,FileWritePost * if ! lh#option#Get('LHT_no_auto', 0) | call s:Run('UpdateTags_for_SavedFile') | endif
aug END
" ======================================================================
" Internal functions {{{2
" ======================================================================
" generate tags on-the-fly {{{3
function! UpdateTags_for_ModifiedFile(ctags_pathname)
let source_name = expand('%')
let temp_name = tempname()
let temp_tags = tempname()
" 1- purge old references to the source name
if filereadable(a:ctags_pathname)
" it exists => must be changed
call system('grep -v " '.source_name.' " '.a:ctags_pathname.' > '.temp_tags.
\ ' && mv -f '.temp_tags.' '.a:ctags_pathname)
endif
" 2- save the unsaved contents of the current file
call writefile(getline(1, '$'), temp_name, 'b')
" 3- call ctags, and replace references to the temporary source file to the
" real source file
let cmd_line = s:CtagsCmdLine(a:ctags_pathname).' '.source_name.' --append'
let cmd_line .= ' && sed "s#\t'.temp_name.'\t#\t'.source_name.'\t#" > '.temp_tags
let cmd_line .= ' && mv -f '.temp_tags.' '.a:ctags_pathname
call system(cmd_line)
call delete(temp_name)
return ';'
endfunction
" ======================================================================
" generate tags for all files {{{3
function! s:UpdateTags_for_All(ctags_pathname)
call delete(a:ctags_pathname)
let cmd_line = 'cd '.s:CtagsDirname()
" todo => use project directory
"
let cmd_line .= ' && '.s:CtagsCmdLine(a:ctags_pathname).' -R'
echo cmd_line
call system(cmd_line)
endfunction
" ======================================================================
" generate tags for the current saved file {{{3
function! s:UpdateTags_for_SavedFile(ctags_pathname)
let source_name = expand('%')
let temp_tags = tempname()
if filereadable(a:ctags_pathname)
" it exists => must be changed
call system('grep -v " '.source_name.' " '.a:ctags_pathname.' > '.temp_tags.' && mv -f '.temp_tags.' '.a:ctags_pathname)
endif
let cmd_line = 'cd '.s:CtagsDirname()
let cmd_line .= ' && ' . s:CtagsCmdLine(a:ctags_pathname).' --append '.source_name
" echo cmd_line
call system(cmd_line)
endfunction
" ======================================================================
" (public) Run a tag generating function {{{3
function! LHTagsRun(tag_function)
call s:Run(a:tag_function)
endfunction
" ======================================================================
" (private) Run a tag generating function {{{3
" See this function as a /template method/.
function! s:Run(tag_function)
try
let ctags_dirname = s:CtagsDirname()
if strlen(ctags_dirname)==1
throw "tags-error: empty dirname"
endif
let ctags_filename = s:CtagsFilename()
let ctags_pathname = ctags_dirname.ctags_filename
if !filewritable(ctags_dirname) && !filewritable(ctags_pathname)
throw "tags-error: ".ctags_pathname." cannot be modified"
endif
let Fn = function("s:".a:tag_function)
call Fn(ctags_pathname)
catch /tags-error:/
" call lh#common#ErrorMsg(v:exception)
return 0
finally
endtry
echo ctags_pathname . ' updated.'
return 1
endfunction
function! s:Irun(tag_function, res)
call s:Run(a:tag_function)
return a:res
endfunction
" ======================================================================
" Main function for updating all tags {{{3
function! s:UpdateAll()
let done = s:Run('UpdateTags_for_All')
endfunction
" Main function for updating the tags from one file {{{3
" #note the file may be saved or "modified".
function! s:UpdateCurrent()
if &modified
let done = s:Run('UpdateTags_for_ModifiedFile')
else
let done = s:Run('UpdateTags_for_SavedFile')
endif
endfunction
This code defines:
^Xta to force the update of the tags base for all the files in the current project ;
^Xtc to force the update of the tags base for the current (unsaved) file ;
an autocommand that updates the tags base every time a file is saved ;
and it supports and many options to disable the automatic update where we don't want it, to tune ctags calls depending on filetypes, ...
It is not just a tip, but a small excerpt of a plugin.
HTH,
Auto Tag is a vim plugin that updates existing tag files on save.
I've been using it for years without problems, with the exception that it enforces a maximum size on the tags files. Unless you have a really large set of code all indexed in the same tags file, you shouldn't hit that limit, though.
Note that Auto Tag requires Python support in vim.