How to search a directory path within a file using vi editor - editor

I want to search for a directory path within a file in vi editor. How can I do that ?

Using CentOS Linux 8.5 with vim 8.0, I was able to search a path within a text file edited via "vi myFile.txt" by escaping the path delimiter "/" with a "" character. Example: To look for /var/lib within myFile.txt, I run "vi myFile.txt" and in the editing session enter: \/var\/lib.

Related

Using Atom with Hydrogen. The working directory for Atom is one folder up from the current file's location. How do i change it to the current folder?

In both Hydrogen and using a plug-in terminal platform, the default directory is one folder up from where my code file resides.
E.g., I’ll be working on a file with path, say, parent/code/file.py. When I run pwd in the plug-in's terminal or the equivalent via Hydrogen in the python script I get parent/, but I need it to be parent/code/ to import files etc.
Perhaps the default directory for Atom is the project that is folder of the project that is open?
Any ideas how to change the default current directory for Atom (or is it package specific) to the file i’m working on/executing in Hydrogen?
In the hydrogen settings you can choose the location where the kernel should be started.
The default is the 'First started project's directory'. You can choose 'Current directory of the file' there, which should give you what you want.

Javac is not being recognized even after setting the class path variable

My problem is that I have set the bin path in Class path variables. After that
Command Prompt is recognizing "java" command but "javac" program is still not being recognized.
Make sure you are pointing to the "bin" directory of the jdk and NOT jre. Also, as Juned answered, you need to open a new command line after you update the environment variable in "PATH"
Assuming you have set the jdk/bin folder path to your system PATH variable.
Just make sure you re-open the command line because an open command line does refresh itself with the new environment params.
After adding jdk/bin to your PATH, simply launch a new command prompt and type javac, java magic should start happening.
Adding C:\Program Files\Java\jdk1.8.0_121\bin to Path environmental variable should be done. But you shouldn't insert any space between the previous ; and the path of bin folder:
Path: c:\some name\.....\; C:\Program Files\Java\jdk1.8.0_121\bin ==>WRONG
Path: c:\some name\.....\;C:\Program Files\Java\jdk1.8.0_121\bin ==>OK

Sublime 2 can not find file in the path (LaTeX plugin)

I have a project in directory A and files that I use in all my projects are in directory B.
When I moved a .sty file from A to B, the main .tex file does not compile anymore.
The error is that the .sty file was not found. I am puzzled because:
Directory B is included in the path of the project.
I cleaned (deleted manually) all the auxiliary files used in the previous compilations.
I refreshed the project folders .
Did anyone had similar problems? Suggestions?
The file LaTeX.sublime-build, within the Sublime Text folder . . . /Packages/LaTeXTools, contains a $PATH for different operating systems.
For example, Sublime Text 2 on an OSX operating system, has a file located at ~/Library/Application Support/Sublime Text 2/Packages/LaTeXTools/LaTeX.sublime-build. The relevant line of code for a MacTeX TexLive 2012 installation is "path": "$PATH:/usr/texbin:/usr/local/bin",. The plugin LaTeXTools looks in that path for *.sty files that are a part of the TexLive installation. While it may be possible (under some circumstances) to place the *.sty files within the working directory of the *.tex file, this particular plugin looks to the path mentioned hereinabove. So one option would be to add additional locations to the $PATH to suit the needs of the user, or simply place the *.sty files within the path that is pre-defined by the plugin developer.

How to 'set path' automatically when opening Vim from a directory?

I'm trying to get :A (e.g. switch between controller and spec) working in vim-rails. If I navigate to my rails project, run vim ., open a controller file and run :A, I get the error:
E345: Can't find file "app/controllers/widgets_controller.rb" in path
If I then set the path explicitly:
:set path=/Users/me/Documents/Code/my-project
then :A works as expected. How can I set the path initially when I open a directory with Vim?
Not exactly when opening a directory: since you seem to be working with projects, give the project plugin a try.
Using that, you could execute arbitrary commands when entering or leaving a project.
From the plugin description:
You can use this plugin's basic functionality to set up a list of
frequently-accessed files for easy navigation. The list of files
will be displayed in a window on the left side of the Vim
window, and you can press or double-click on
filenames in the list to open the files. This is similar to how
some IDEs I've used work. I find this easier to use than
having to navigate a directory hierarchy with the file-explorer.
It also obviates the need for a buffer explorer because you
have your list of files on the left of the Vim Window.
This is what I do to have a local .vimrc file per project:
In my ~/.vimrc file I define the following:
let s:project_root = finddir('.git/..', expand('%:p:h').';')
let s:local_vimrc = join([s:project_root, '.vimrc'], '/')
if filereadable(s:local_vimrc)
exec "source " . s:local_vimrc
endif
In the project root (which usually has a .git dir) I do the following:
touch /path/to/project/.vimrc
In the .vimrc file, I prepend the path variable (notice the ^path). Using :set path^= instead of :set path+= prepends the new directory to the beginning of the path instead of appending it to the end. This makes it faster for the find command to search for your files.
let s:project_root = finddir('.git/..', expand('%:p:h').';')
exec 'setlocal path^='.s:project_root
setlocal wildmode=longest,list,full
setlocal wildmenu
setlocal tags=/path/to/project/root/tags
Now the :find command should only display files and directories relative to the project root.

vimrc - current working directory

I would like to be able to access the current working directory in my vimrc.
For example, I can access the current file by using %.
Specifically,
I have the following line in my vimrc:
map ,l :!latex %
When it runs everything works fine, except the resulting dvi and other files are stored in my home directory instead of my current working directory.
Any suggestions?
See :help autochdir. Vim can automatically change the current working directory to the directory where the file you are editing lives.
Otherwise, if you want to do this manually, see :help cd and :help lcd.
see :he filename-modifiers
:!latex % -output-directory %:h
Most likely, you're running vim from your home directory, so it is the current for him. The latex command, being invoked from vim, also therefore has the home directory as current.
You probably know this, and want just to extract path from the filename and supply it as an argument to -o option of the latex command. Just use the shell capabilities:
:!latex % -output-directory `dirname "%"`
I am not sure that it's -output-directory option, but you get what you asked for--a directory name of the file you're editing.

Resources