I just installed macvim yesterday and I have been trying to install vim latex today.
The one thing I am confused about is the menu items on the top bar:
-------------------------------------------------------------------------------
<apple icon> File Edit Tools Syntax TeX-Suite TeX-Environments TeX-Elements
-------------------------------------------------------------------------------
| Packages > |_____
| Templates > | 1: |
| Macros > | 2: |
|----------- | 3: |
| Compile | 4: |
| View |-----
| ... |
-------------
So in words if you go TeX-Suite -> Templates there is a sub menu with menu items: 1: 2: 3: 4:.
Now I know that these templates live here:
% pwd
/Users/me/.vim/ftplugin/latex-suite/templates
% ls
IEEEtran.tex article.tex report.tex report_two_column.tex
and they are named correctly.
Also I know that the :TTemplate vim command should do the same thing. When I type that I get this result:
Choose a template file:
(1) IEEEtran (2) article
(3) report (4) report_two_column
Enter number or name of file :
So I am thinking that this must be a bug in MacVim. Is this a reasonable assumption? Any fixes?
The problem is that vim-latex puts the template name after the <Tab> when they set up the menus (see ":h menu"). This text is supposed to show a hint as to what command to use to access that particular menu item (e.g. File->Save has ":w" after <Tab>) and on most platforms it is displayed flush right on the menu items. However, on Mac OS X it is only possible to show keyboard shortcuts to the right in a menu item, so the text is instead displayed in a popup window if you let the mouse hover over the menu item for a while.
The only way to get around this problem is to edit the vim-latex menu files and delete the <Tab> from each menu command.
I just installed vim-latex on OS X. To get the templates menu items to show up I changed the line
exe "amenu ".g:Tex_TemplatesMenuLocation."&".i.":<Tab>".fname." ".
to
exe "amenu ".g:Tex_TemplatesMenuLocation."&".fname." ".
in the file ~/.vim/ftplugin/latex-suite/templates.vim. To get the items under TeX-Suite -> Macros to show up I changed the lines
exe "amenu ".g:Tex_MacrosMenuLocation."&Delete.&".i.":<tab>".fname." :call <SID>DeleteMacro('".fname."')<CR>"
exe "amenu ".g:Tex_MacrosMenuLocation."&Edit.&".i.":<tab>".fname." :call <SID>EditMacro('".fname."')<CR>"
exe "imenu ".g:Tex_MacrosMenuLocation."&".i.":<tab>".fname." <C-r>=<SID>ReadMacro('".fname."')<CR>"
exe "nmenu ".g:Tex_MacrosMenuLocation."&".i.":<tab>".fname." i<C-r>=
to
<SID>ReadMacro('".fname."')<CR>"
exe "amenu ".g:Tex_MacrosMenuLocation."&Delete.&".fname." :call <SID>DeleteMacro('".fname."')<CR>"
exe "amenu ".g:Tex_MacrosMenuLocation."&Edit.&".fname." :call <SID>EditMacro('".fname."')<CR>"
exe "imenu ".g:Tex_MacrosMenuLocation."&".fname." <C-r>=<SID>ReadMacro('".fname."')<CR>"
exe "nmenu ".g:Tex_MacrosMenuLocation."&".fname." i<C-r>=<SID>ReadMacro('".fname."')<CR>"
in ~/.vim/ftplugin/latex-suite/custommacros.vim.
Related
Adding a simple line to my .vimrc I managed to open an ePub archive with zip.vim on a vim buffer. This basically opens a numbered list of htm, css, jpg, xml files that one can access individually. I want to perform a search and replace through all these numbered files as it is too painful to edit each of them and do it - there's around 400 files. :args and :argdo did not really work or at least I could not make them. Any ideas?
I'm not sure it will work for you, and I'm going to assume that when you hit Enter on a filepath inside your Vim buffer, a new viewport is opened (by the ZipBrowseSelect() function defined in $VIMRUNTIME/autoload/zip.vim) to display the contents of the file.
If this is the case, you could try the following method.
:%argd
This command deletes all the paths in the current arglist.
Then, you would have to visually select all the lines containing a path to a file you want to modify. From normal mode, you could hit vip, for example, and adjust the visual selection to exclude some lines if needed.
:'<,'>g/^/exe "norm \r" | argadd % | close
This command should hit Enter on each line inside your visual selection, add the file which has been opened in a new viewport, and close the latter to get back to the original window.
:vim /pattern/ ##
This command should populate the quickfix list with all the lines containing the pattern you're looking for.
:cfdo %s/pattern/replacement/ge | update
This command should replace pattern with replacement in each file present in the quickfix list, and save the file if it has been changed.
The last step uses the :cfdo command which was introduced in Vim version 7.4.858. If your Vim version is not new enough to support :cfdo, you could bypass the last 2 steps, and directly execute:
:argdo %s/pattern/replacement/ge | update
The benefit of:
:vim /pattern/ ##
:cfdo %s/pattern/replacement/ge | update
... is to prune the arglist from the files which don't contain your pattern, so that the substitutions commands are only executed when needed.
If you don't have :cfdo but still want to prune the arglist, you could source this custom command:
com! -nargs=0 -bar Qargs exe 'args '.s:qfl_names()
fu! s:qfl_names() abort
let buffer_numbers = {}
for qf_item in getqflist()
let buffer_numbers[qf_item['bufnr']] = bufname(qf_item['bufnr'])
endfor
return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfu
I've copied it from this video: Project-wide find and replace.
Most of the other commands are also taken from this video, so it might help you to have a look at it, if you don't have already.
Then, you would replace the :cfdo command, with:
:Qargs
:argdo %s/pattern/replacement/ge | update
To summarize, you could try one of these 3 methods:
:%argd
visually select the paths of the files
:'<,'>g/^/exe "norm \r" | argadd % | close
:argdo %s/pattern/replacement/ge | update
Or:
:%argd
visually select the paths of the files
:'<,'>g/^/exe "norm \r" | argadd % | close
:vim /pattern/ ##
:cfdo %s/pattern/replacement/ge | update
Or:
:%argd
visually select the paths of the files
:'<,'>g/^/exe "norm \r" | argadd % | close
:vim /pattern/ ##
:Qargs
:argdo %s/pattern/replacement/ge | update
Edit:
You could also try to visually select the paths of the files, then execute:
:'<,'>g/^/e `='zipfile:'.expand('%:p').'::'.getline(".")` | %s/pattern/replacement/ge | update | b#
This method relies on the fact that the path to a file in the archive seems to follow this scheme:
zipfile:/path/to/epub::path/to/file/in/archive
So, you can get the path to a file under the cursor with the Vim expression:
'zipfile:'.expand('%:p').'::'.getline(".")
And you can edit this file using backticks (see :h `=):
:e `=Vim expression`
→
:e `='zipfile:'.expand('%:p').'::'.getline(".")`
From there, you need the global command, to repeat the edition on each line inside the visual selection.
In the epub I tested, all the paths were below the line mimetype. If this is the case for you, then you could merge the 2 steps (visual selection + global command) in a single command:
1/mimetype/+,$g/^/e `='zipfile:'.expand('%:p').'::'.getline(".")` | %s/pattern/replacement/ge | update | b#
I'm not sure but this mìght help you
On esc mode try
:%s/word you want to search/word you want yo replace with/g
Is there a way to limit :Ag output so it always takes one line and doesn't blow up the quickfix window?
At the moment it looks like this and it's awful. I can't see filenames, everything is super slow and just sucks:
Update For the record, I scrolled Quickfix window a bit to illustrate the point better. And while it is usable via :cn :cp, I would like to be able to quickly glance over the results with j k.
Looking over the man page, there does not seem to be any way to limit the output built into Ag itself.
Is there another way of limiting the line length? Actually, you do have the built in "cut" command in Linux, e.g. using it on the shell:
ag --column foo | cut -c 1-80
Limit all lines to 80.
Now we have to make ag.vim execute our specially crafted command, for which the g:agprg exists. So the first thing I thought of is this:
let g:agprg='ag --column \| cut -c 1-80' " doesn't work
The problem with this is that the ag.vim plugin just appends extra arguments to the end, and thus you end up executing something like ag --column | cut -c 1-80 something-i-searched-for. Is there a way to directly "insert" the arguments before the |?
One trick is to use a temporary shell function, like this:
f() { ag --column "$#" | cut -c 1-80 }; f something-i-search-for
Unfortunately, we still can't use this. ag.vim checks whether or not the first word is an actual command. So it complains that no executable by the name of "f()" exists. So my final solution:
let g:agprg='true ; f(){ ag --column "$#" \| cut -c 1-80 }; f'
As true always exists and doesn't do anything except return true, this works!
To your actual screenwidth instead of 80, you could use:
let g:agprg='true ; f(){ ag --column "$#" \| cut -c 1-'.(&columns - 6).' }; f'
I added the magic - 6 here to account for the extra characters Vim itself adds.
ag now supports a --width switch. rg has a similar --max-columns switch.
Assuming you are using this plugin. You should add this to your ~/.vimrc as specified by :h g:ag_qhandler
let g:ag_qhandler = 'copen 1'
However you can probably just do let :g:ag_qhandler = 'cc'. This will print the results at the in the bottom. When you move through the quickfix list via :cnext or :cprev it will print the current result as well.
For more help see:
:h g:ag_qhandler
:h :cope
Changing the geometry of the quickfix window won't help you fix your problem: the window is unusable not because of its size but because your search results are polluted by superfluous matches in minimized files.
Minimized JavaScript or CSS is the frontend development's equivalent of a binary and that kind of file should be ignored by search tools, indexing tools, file navigation tools and even version control tools, sometimes, because they are generally irrelevant.
Adding these lines to your ~/.agignore will make Ag search only in actual source files:
*.min*
*-min*
*_min*
*.min.*
bundle
min
vendor
tags
cscope.*
Adjust that list to your liking.
I would like to either find a vim plugin or write a vimscript function to open
a file in (or under) the same directory as my present file. The file should
match one of a list of regex files that is defined in a list.
I have a project that looks something like this:
src
|- controllers
| ...
|- util
| ...
|- widgets
| - widgetA
| | - widgetA.js
| | - widgetA.template.html
| -widgetB
| | - widgetB.js
| | - widgetB.template.html
| -widgetC
| | - widgetC.js
| | - widgetC.template.html
| | - someHelpers.js
Sample usecase (in the command line):
cd src
vim widgets/widgetA/widgetA.js
Inside vim:
press F4 while in command mode
Result:
widgetA.template.html is opened in vertical split mode with widgetA.js
Template files will either be in one of the following:
Named the same as the presently opened file but with this regex run on it: s/js$/tempate.html/
Named the same as the presently opened file but with this regex run on it: s/js$/html/
In a subdirectory named templates named as above
I am presently using nerdtree and ctrl-p to speed up file opening, but this is a workflow that
I use so frequently that I thought it could make sense to try to speed it up. Any suggestion?
It feels like you are looking for something along the lines of projectionist or fswitch.
projectionist
With projectionist you could in theory then just execute :A/:SA to switch to the alternate file.
So in your .projections.json (not tested) file would look something like this:
{
"widgets/*.js": {
"alternate": "widgets/{}.template.html",
"type": "widget"
},
"widgets/*.template.js": {
"alternate": "widgets/{}.js",
"type": "template"
}
You can also use :Ewidget and :Etemplate commands to find a widget/template. These commands will also take fuzzy filenames. e.g. :Ewidget wta. You can also open the files in split, vertical splits and tabs via :Swidget, :Vwidget, and :Twidget respectively. Please see :h projectionist for more information.
fswitch
Another option is to use something like fswitch which is a C/C++ .h/.c switcher. Please see :h fswitch-setup for more information.
There are a few other plugins that do similar things: altr and a.vim to name a few.
vanilla
If plugins are not your thing then you can use % tricks. e.g. :sp %<.template.html
Or maybe a quick and dirty mapping:
nnoremap <f4> %:p:s,\.js$,.X123X,:s,\.template\.html$,\.js,:s,\.X123X$,\.template\.html,<CR>
For more information see the following vim wiki page: Easily switch between source and header file
conclusion
I personally use projectionist and find it meets my needs, especially for navigating a structured project which I find more useful than just a simple switcher like fswitch. Projectionist will also be easier than the vanilla approach to when your needs become wilder.
What you want is easy to do in the shell:
$ cd src
$ vim -O w*/*A/*
but I'm not exactly sure how you see that working in Vim itself. Do you want that to happen in a new tab? Do you want the new pair of files to replace the current pair of files?
Dropping this into the your vimrc and relaunch vim will work.
Presently only working for files ending in .template.html that are in the same directory but easy to see how it could work for multiple other cases. When it can't find the template it opens nerdTree to the current directory.
map <F4> :call OpenTemplate()<cr>
function! OpenTemplate()
" Get the Current directory
let l:jake = expand('%')
" Replace .js with .template.html
let l:jake = substitute(l:jake, ".js$", ".template.html", "")
" Verify that the file exists and it it does open in using vs (see :help vs)
" if the file can't be found, open nerdTree
if filereadable(l:jake)
execute 'vs ' . l:jake
else
echo 'Cant find template'
:NERDTreeFind
endif
endfunction
I know how to open all files each in one tab or each in one window, but is it possible to make them open in a combination of tabs/windows?
I am using gvim 7.3
I think you have the notion of tab pages backwards. From :h tabpage:
A tab page holds one or more windows.
I'm not sure if it's what you want, but you can create two tabs each with two windows through liberal use of -c on the command line:
gvim -p2 first.txt third.txt -c "sp second.txt" -c "tabn" -c "sp fourth.txt"
This leaves the focus on the 4th file. You can rearrange the arguments (or add more) if you want to do something different. Also note that gvim will confusingly tell you that it's only opening two files.
You can use :[count]tab {cmd} (tab-page-commands) in combination with :[n]sbnext [N] (buffer-list) as follows:
vim file1 file2 file3 file4 +sbn +"tab sbn" +sbn
Just add more +"tab sbn" +sbn for more files. If you want to split vertically, replace +sbn by +"vert sbn".
BACKGROUND:
In vim (Ex mode) it is possible to run an external command and have the output from that command automatically inserted into the current buffer.
In Example 001, we see how to cd to the current directory, get a listing of the files there and auto insert that into the current buffer
EXAMPLE 001:
:cd . | :r ! dir /w/s/b
QUESTIONS:
1) Is it possible to automatically specify or capture the Vim {range} to reflect the lines that were recently inserted into the file ?
2) Using the range obtained in question 1) is it possible to chain Ex mode commands to automatically process the lines that were inserted into the file ?
3) If it is not possible to do 1) or 2) above, is there an alternate way for Vim to recognize lines recently inserted into the buffer and run arbitrary commands on them ?
4) What is a relevant :help cross reference that can be used for this purpose ?
GOAL:
The goal is to be able to chain multiple Ex mode commands together to easily run process recently added lines to a file, without having to expressly identify the line number or manually select them using Visual mode or something similar.
The goal is do something similar to the (psuedo-code) in Example 002
Example 002:
:cd . | :r ! dir /w/s/b | :{auto-range}s/^/ /
Vim sets the change marks '[ and '] to the inserted range; you can use these to define a range for subsequent Ex commands:
:cd . | execute 'r ! dir /w/s/b' | '[,']s/^/ /
You need :execute because otherwise the | is interpreted to belong to the :r command.
What about processing those lines before inserting them in Vim?
:r!dir /w/s/b | sed -e "s/^/ /"