I am using vim with Ag.vim(silver-searcher) and i came across a problem.
the Ag plugin defines Ex mode commands such as :Ag and :AgFromSearch.
but while :Ag lets me pass options to the shell's ag command such as -G which lets me whitelist files, :AgFromSearch doesn't let me..
so my question is - is there any pretty solution to this? or should i just imitate the way the plugin implements :AgFromSearch with :Ag and pass through it the options?
Ag.vim is deprecated; you should consider moving back to using Ack.vim.
The maintainer of Ack.vim is open to supporting the Ag community.
The :AckFromSearch allows for passing extra options like the -G. You first must configure the Ack.vim to use Ag, by adding this to .vimrc:
let g:ackprg = 'ag --vimgrep'
And, then you can do :AckFromSearch like the following:
:AckFromSearch -G '.*py'
Since moving back to the Ack.vim plugin, I use this feature quite frequently and have mapped ,* to :AgFromSearch in vim.
Related
I am using the vim Ctrl+P plugin for file searching,
All that is listed in my .vimrc is
let g:ctrlp_working_path_mode = 0
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|CVS$\|build|\.svn$\|target$',
\ 'file': '\.class$\|\.so$',
\ }
let g:ctrlp_extensions = ['dir', 'mixed']
But it does not seem to index any directories that have a - in them. Does anyone know how to fix this?
If you use CtrlP, be careful which version you use. There is no longer maintained kien/ctrlp.vim, and its active fork ctrlpvim/ctrlp.vim.
Also, if you need to speed up your CtrlP, you should consider to use Silver Searcher. The integration with Vim can provide ag.vim plugin. About ignore setting you can check this answer.
I edit quite a few markdown files using Vim these days. One thing I'm missing is a map of the file like function list in C based on ctags. So I came up with the following .ctags file
--langdef=markdown
--langmap=markdown:.md
--regex-markdown=/^# ([a-zA-Z0-9]+)/\1/
It runs OK but generates no valid tags for my .md file. With verbose mode turned on I get the following:
Considering option file /home/wenliang/.ctags: reading...
Option: --langdef=markdown
Option: --langmap=markdown:.md
Setting markdown language map: .md
Option: --regex-markdown=/^# ([a-zA-Z0-9]+)/\1/
Considering option file ./.ctags: not found
What's wrong with what I did?
Your definition looks OK.
What command did you use to generate your tags file? $ ctags . won't index anything but $ ctags -R . will.
FWIW, here is a slightly modified version of your definition that provides meaningful tag names and kind informations:
--langdef=markdown
--langmap=markdown:.md
--regex-markdown=/^#[ \t](.*$)/\1/h,heading,headings/
As an alternative, you might be interested in these cheaper, built-in, solutions…
using the define option and :dlist:
:setlocal define=^#\\s*
:dli /<CR>
using :ilist and no setup:
:il /#<CR>
which both produce the same list, ready for you to type :126<CR>:
See :help :ilist, :help :dlist, :help 'define'.
I would like to use Ack (or similar plugin if something else can do the job) to search my whole project in Vim by default, rather than just the current directory. Ideally I'd end up with a process that works like using Cmd+Shift+F in Sublime. How can I do this?
An option like CtrlP's let g:ctrlp_working_path_mode = 'r' that makes it search within the nearest parent directory that contains a file like .git would be perfect. (https://github.com/kien/ctrlp.vim#basic-options)
I think Rooter is what you want. For example:
let g:rooter_patterns = ['Rakefile', '.git/']
I don't think Ack (or grep/vimgrep) can detect your "project root". If you often work on several projects, you could add this block in your vimrc:
let g:projectA_path="/path/to/A"
let g:projectB_path="/path/to/B"
let g:projectC_path="/path/to/C"
also define some functions/commands, like AckA, AckB, AckC...
basically the func/command just does:
exec 'Ack! '. pattern . " " . g:projectA_path
the pattern is the argument you passed in. then, in future, you could do:
:AckA foo
or
:call AckA("foo")
for quick grepping/acking in projectA.
I didn't think of a simpler way to do it. glad to see if there is better solution.
Most of the time I don't need to cd the project root, but stay in the same working directory.
So there is a simpler solution, based on answer of Kent, without cd'ing the project root, installing additional plugins and using ag:
let g:ackprg = 'ag --vimgrep --smart-case'
function! Find_git_root()
return system('git rev-parse --show-toplevel 2> /dev/null')[:-2]
endfunction
command! -nargs=1 Ag execute "Ack! <args> " . Find_git_root()
And to use it call :Ag <keyword>
I have this line in my .vimrc:
cnoreabbrev ack cd ~/your-project <bar> Ack! <Space>
Whenever you type :ack and hit the space the rest will be added to the command line and you can add the keyword.
I've installed the vim-latex-suite and I'd like to customize the folding for use with the labbook package. The labbook package uses \labday, \experiment, and \subexperiment in place of \chapter, \section, and \subsection.
I'd like to customize the folding options with vim-latex-suite in Vim so that \labday, \experiment, and \subexperiment are folded like the traditional sectioning commands.
I've tried adding to my ~/.vim/after/ftplugin/tex.vim the following (but it didn't work)
" Folding sections
let g:Tex_FoldedSections = ',labday,experiment,subexperiment'
" Folding commands
let g:Tex_FoldedCommands = ',labday,experiment,subexperiment'
Can someone show me how to customize the folding for the labbook package?
I think you should put
let g:Tex_FoldedSections = 'labday,experiment,subexperiment'`
in your .vimrc itself. If you take a look at ftplugin/latex-suite/folding.vim you'll find:
if g:Tex_FoldedSections != ''
call Tex_FoldSections(g:Tex_FoldedSections,
\ '^\s*\\frontmatter\|^\s*\\mainmatter\|^\s*\\backmatter\|'
\. '^\s*\\begin{thebibliography\|>>>\|^\s*\\endinput\|'
\. '^\s*\\begin{slide\|^\s*\\end{document')
endif
Which means that setting Tex_FoldedSections after the plugin as already loaded will not work. Also make sure that your sections in your latex file itself are nested correctly.
I've installed Haskell on my Mac using Homebrew, that is brew install ghc haskell-platform.
I'm looking for a way to generate a ctags file of the standard Haskell Platform libraries (modules) so I could browse the source while coding in Vim. I specifically need Prelude and the other most popular modules, like Data.List and such.
I am aware that the source is available on the web via Hoogle, but It'll be easier for me to jump-to-source whenever I need to, for learning purposes.
Where is the source located when installing the Haskell Platform?
Is the source even installed when installing the Haskell Platform, or just the compiled binaries or something of the sort?
How can I make the source available for browsing in Vim? As in put the generated tags file somewhere and tell Vim to read from it. I also understand there's no need to re-generate the tags file, since these modules are pretty much static and don't get updated very often.
1) and 2) were answered by permeakra in comments. I'll try to cover 3) by describing setup similar to the one I'm using. First simple solution for base libraries, then more generic solution for whatever Haskell source package in general.
As a prerequisites we will need a tool which generates tags file for Haskell:
cabal install hothasktags
Instead of hothasktags you might use your favourite one. See for example https://github.com/bitc/lushtags page which enumerates some of these.
Then we need to have sources for base libraries available. Here I'm using the ones from GitHub:
cd /space/haskell/sources/ # tweak to your personal taste
git clone https://github.com/ghc/packages-base.git
Optionally we might switch to particular branch. E.g.:
git checkout ghc-7.4
Run git branch -a to see all possibilities.
Now let's generate tags for the base libraries (I do not have Mac available and thus have to assume the command works there or you are able to tweak it appropriately):
cd packages-base
export LC_ALL=C # needed for case-sensitive searching
find -type f | egrep \.hs$\|\.lhs$ | xargs -Ii hothasktags i | sort > tags
(Note about sort: My Vim complains when I do not use the sort. For LC_ALL explanation see for example this blog post)
Now we need to let the Vim know about the tags we generated. The easiest way is probably to put the following line into your $HOME/.vimrc:
autocmd FileType haskell setlocal tags+=/space/haskell/sources/packages-base/tags
This way the tags for base libraries will be set for each Haskell file we open. If this is not desirable we can put following Vim command into .vimrc:
autocmd FileType haskell command! SetGHCTags
\ setlocal tags+=/space/haskell/sources/packages-base/tags
and call :SetGHCTags on demand.
For more generic solution which works with all Haskell sources packages we can use the following function (put into .vimrc or into Vim file dedicated to Haskell filetype):
" Add 'tags' of the given package to the current tag stack. The package sources
" must be available in "/space/haskell/sources/<package>" and the tags must be
" generated for it.
fun! s:SetHaskellTags(pathInHaskellSrcDir) "{{{
let tagFile = "/space/haskell/sources/" . a:pathInHaskellSrcDir . "/tags"
if filereadable(tagFile)
exe "setlocal tags+=" . tagFile
else
echoerr "File does not exist or is not readable: " . tagFile
endif
endfunction "}}}
command! -nargs=1 SetHaskellTags call <SID>SetHaskellTags(<args>)
Utilizing it for example for Shelly.hs library:
cd /space/haskell/sources/
git clone https://github.com/yesodweb/Shelly.hs.git
cd Shelly.hs
regenerate-haskell-tags # [1]
In Vim just call:
:SetHaskellTags "Shelly.hs"
There is space for improvement - SetHaskellTags could generate tags if not exist, or could even fetch the sources, configurable Haskell source code storage, directory completion, etc. But works good enough for me now. So at least sharing the solution I have. Will come back here if I get to some of these improvement done.
[1]: It's better to store regenerate-haskell-tags in your $PAHT.