cscope: ctrl + ']' does not work - linux

I just installed cscope-15.8b, then go to linux-next folder, run "cscope -R", after build the tags, then open a file through "Find this file" // so far so good.
Now if I want to go to a symbol's defination, by ctrl + ], it will throw error: "E433: No tags file" "E426: tag not found".
If I open the cscope.out file, I will see it looks like broken (see below). How do Ifix this?
1 ^B
~<¡dio.h
>
2 ^B
~<¡dlib.h
>
3 ^B
~

The fact that the cscope.out file looks "broken" is normal, the file format is sort-of text but includes some non-printing characters as well.
Your problem is that ctrl + ] doesn't search cscope databases by default, it only searches ctags files which are entirely different. You need to set cscopetag in your .vimrc file to make it search both. From the vim help:
If 'cscopetag' is set, the commands ":tag" and CTRL-] as well as "vim -t"
will always use :cstag instead of the default :tag behavior. Effectively,
by setting 'cst', you will always search your cscope databases as well as
your tag files. The default is off.

Add these lines to your ~/.vimrc file:
set cscopetag
set csto=0
set tags=./tags,tags;/
cs add cscope.out
Better yet, copy this entire file into the ~/.vimrc file: http://cscope.sourceforge.net/cscope_maps.vim

Related

In Vim tab-completion of file names doesn't work

When I try to open a file in Vim (Linux) for editing, when I press TAB, Vim autocompletes filename only with filenames from the current directory. However, having searched on the Web, I suppose that from version 7 Vim should support bash-like filename autocompletion using filenames from all the directories in the search path.
Say, there is a file file1 in a directory dir1 (which directory is also in the environment variable PATH).
I type the following commands in Vim:
set path=/dir1
set wildmode=list:longest
And then, when I type:
:e fil<TAB>
The filename is not autocompleted. How to enable this feature in Vim?
Tab-completion works. You just expect it to do something it is not actually supposed to do.
:e[dit] and its siblings (:sp[lit], :vs[plit], :tabe[dit]) don't use the path option at all, no matter what version of Vim you have.
Use :fin[d] fil<Tab> instead (and :sf[ind], :vert sf[ind], :tabf[ind]).
Use set path=/dir1/** to make :find recursive.
See :help 'path' and :help :find.
edit
It is generally considered "good practice" to start Vim from the root of your project:
$ cd /path/to/project
$ vim somefile
The main advantage being that it sets Vim's "current directory" to a usable value that allows you to browse your project relatively easily or use external programs on your project in a clean and intuitive way.

.vimrc backupdir several directories

I would like to create backup file in several directories after :w in vim, if statement is true. Vim :help says, that you need to put commas between directories and nothing else. But it's not working for me. It reads only the first directory. I tried different ways, such as usingset backupdir+=, or ~/. instead of ..
set backup
set nowritebackup
set backupdir=~/Dropbox
if expand("%")==".vimrc"
set backupdir=.,~/.vim/backUpDir/,~/Dropbox
endif
In .vimrc expand returns
:echo expand("%")==".vimrc"
1
vim --version
VIM - Vi IMproved 7.4
MacOS X (unix) version
I do not believe this is possible without custom plugin. If you read the vim help carefully, it says that the backup file will be created in the first directory in the list where this is possible. So the behavior you are seeing is by design.
*'backupdir'* *'bdir'*
'backupdir' 'bdir' string (default for Amiga: ".,t:",
for MS-DOS and Win32: ".,c:/tmp,c:/temp"
for Unix: ".,~/tmp,~/")
global
{not in Vi}
List of directories for the backup file, separated with commas.
- The backup file will be created in the first directory in the list
where this is possible. The directory must exist, Vim will not
create it for you.
If you really want to be able to backup to multiple directories, I would suggest writing a function to do this, and attaching it to BufWritePre.

VIM Undofile displays at Terminal login

Upon opening a new terminal window, the most recent VIM undofile to be written displays as the first line, generally with some form of error. Why is this displaying, and is there any way to prevent it? Adding .hushlogin to my home directory didn't work.
Context: My .dotfiles are versioned in a Git repo, containing a symlinked .Vim directory. I'm using homebrew installations of ZSH, iTerm2, and Git.
Message: /Users/joshuaberk/.dotfiles/vim/vim.symlink/undo/%Users%joshuaberk%.dotfiles%system%env.zsh:1: unmatched
The (potentially relevant) portion of my .Vimrc is included below (Undofile settings are in "Backup").
" Search/Substitution/Completion
set ignorecase " removes case sensitivity by default
set smartcase " adding ≥1 uppercase = case sensitivity
set incsearch " do incremental searching
set gdefault " substitute all matches in line (not first)
set showmatch " quickly jump to matching bracket
set completeopt=menu,longest " disable preview window on completion
set wildmenu
set wildmode=list:longest,full
" Backup
set undofile
set undodir=~/.vim/undo
set backupdir=~/.vim/backups
set directory=~/.vim/swaps
set history=50
set autoread " updates VIM file if changed elsewhere
set hidden " hide buffers instead of closing them
set clipboard+=unnamed " system clipboard by default
In the comments, you say you're using Zach Holman's dotfiles. Within the zsh dotfiles, there's a section that looks for all *.zsh files and loads them. It's looking for everything under $ZSH:
config_files=($ZSH/**/*.zsh)
Which, by default, is the whole dotfiles directory:
export ZSH=$HOME/.dotfiles
And your .vimrc is setting your undofiles to be within .vim (which is a symlink into that dotfiles directory).
You can patch around this by removing all those undo files:
cd ~/.vim/undo
rm *.zsh
But how do you fix it permanently? I couldn't find any especially satisfying way. You can't customise the name of the undofile Vim uses, but you can customise its location. Maybe you're going to tell Vim to save its undos outside of your .dotfiles directory:
set undodir=/tmp/vim/undo
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
You could tell Vim to not save undofiles for .zsh files:
autocmd FileType zsh set noundofile
Or, you could tell zsh to STFU about errors in your config files by changing your .zshrc to print error messages to /dev/null:
for file in ${(M)config_files:#*/path.zsh}
do
source $file 2> /dev/null
done
This one seems like the worst option; it's going to make your life Hell if you introduce a typo in one of your other .zsh files. I'd go for option 1 or 2, depending on how much you want to keep your undo history across reboots.

ctags not working as expected with Vim plus general setup problems (C programming)

I have installed cvim and NodeTree plugins and generated an exuberant ctags file for my build tree.
This is what my ~/.vim/.vimrc file looks like:
:noremap :TlistToggle
:let Tlist_Show_One_File = 1
:let Tlist_Exit_OnlyWindow = 1
:let Tlist_Use_Right_Window = 1
set tags=./tags;/
set number
set tabstop=4
set incsearch
When I start editing a file, I notice that Ctrl ] does not work and I have to resort to typing ta: funcname - which gets tiring after a while. Interestingly enough, Ctrl T pops me off the tag stack as expected - I don't understand whats going on - how do I fix this?
Incidentally, vim (appears to) completely ignores the contents of my .vimrc file and I always have to type the same commands in the editor, so as to get the settings I want - very annoying.
Last but not the least, I used to be able to type :make in the editor window, drop to the console and then have the build results displayed in a little window which I can then go to and select a line (with an error or warning say), and then have the editor automagically take me to the offending line - unfortunately, I don't remember the plugin (or commands) I used to allow me to build from within vim.
So, how do I:
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
Fix my .vimrc file so that contents are actually applied to my vim session.
Find the appropriate plugin to install to allow builds (using make) from within vim
You're asking about a weird mix of problems.
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
The tags functionality is working; I suspect that you have a mapping blocking Ctrl-]. Try
:verbose nmap <C-]>
and
:nunmap <C-]>
Fix my .vimrc file so that contents are actually applied to my vim session.
:echo $MYVIMRC
will tell you the location of the .vimrc that Vim uses. Also, check the output of :scriptnames which scripts get loaded, and read :help vimrc to understand the logic Vim applies.
Find the appropriate plugin to install to allow builds (using make) from within vim
That's built into Vim. With the appropriate 'makeprg' set (it defaults to make), you can run :make. Vim parses the output (through the 'errorformat' option), and you can open the quickfix list via :copen.
Your vimrc is:
~/.vim/.vimrc
If you run Vim 7.4, it should be:
~/.vim/vimrc
or
~/.vimrc
If you run Vim 7.3 or older, it should be:
~/.vimrc
And... what Ingo said.

Vim and ctags: tag filenames

Is it possible to have ctags generate tags for filenames as well? I would like to be able to jump to a file given a filename. :find seems to be awfully slow compare to tags...
Try running ctags -R --extra=f .
The --extra=f option tells ctags to:
"Include an entry for the base file name of every source file (e.g. "example.c"), which addresses the first line of the file."
When you open vim, you can the use :tag <filename> to jump to the first line of the file.
You can open the filename under the cursor with gf
http://vim.wikia.com/wiki/Open_file_under_cursor
You can also use cscope:
:cs find f <filename>
or, if you've setup cscope in vim as recommended in :help cscope, put the cursor on top of a filename, and press <C-_>f.
Have you tried setting your path and then using vim's 'gf' command?

Resources