What language is used in Linux scripts in dotfiles? - linux

I'm trying to figure out which language is used in Linux scripts to make the system more personal? I mean things like you put in the dotfiles — like .vimrc, or .zshrc — or to make a function for the terminal (like one that compiles a .tex file with bibtex and then pdflatex and then opens that .pdf with some reader).

What you call dotfiles are just configuration files of one or another program. So the "language" of each of those configuration files depends on the program that is going to use it.
In fact, that doesn't have to be a language, in general, hence the quotes in the previous paragraph. Those config files just have to match the format that the program that uses them expects. This occasionally means that configuarion files are required to use a specific language; an example is .vimrc, which has to use the vimscript language (aka VimL).

I think the term "Linux Scripts" will cause misunderstandment in here.
These dotfiles have a particular syntax for each one, but it's not a programming language.
It's allways a good idea to read the official documentation.
https://www.vim.org/docs.php
https://www.zsh.org/
For vimscript learning, I had a good experience with this one:
https://learnvimscriptthehardway.stevelosh.com/

Related

Vim Cmake integration

I have a cmake project. I want to do the following easily
search the declaration, definition and references of any variable, function, etc. under the cursor, which may be declared in an external header file whose path is added using INCLUDE_DIRECTORIES in CMakeLists.txt
rename a variable, function, etc. that is declared in the project
How can I set this up?
You can try to use vim plugin cmake4vim in order to integrate CMake to Vim.
This plugin helps to work with cmake targets and allows to generate compilation database file (compile_commands.json). A lot of plugins use this file for code completion, jump to definition and etc. (for example YCM)
Also you can use vim lsp plugins (for example vim-lsp) these plugins use language servers for code completion, refactoring and another good features.
But CMake project integration (cmake cache generation, project compilation, etc.) and search the declaration, definition and etc are different tasks. And different plugins and tools solve these tasks.
You can tell Vim where to look for includes by adding entries to the path option. I don't have enough experience with Cmake to know how to pull paths from CMakeLists.txt, though.
See :help 'path'.
Assuming a properly set path, it is possible to use the built-in :dsearch and related commands to search for definitions across includes.
The define option has a prescriptive name but it could be used to find any specific pattern so you could alter it to match declarations, too, or really anything.
See :help include-search and :help 'define'.
Vim has no built-in concept of "reference". :isearch and friends should work for that but they will probably be too noisy.
Renaming is usually done with something like:
:grep foo paths
:cwindow
:cdo s/foo/bar/gc
YouCompleteMe will help you. It uses compilation_database.json, witch can be generated by cmake.
This plugin also provides autocompetion for many languages.
I use functions in vim and assign them to a hotkey.
https://developer.ibm.com/tutorials/l-vim-script-2/
it gives you more an IDE feel. but at the end of the day you get a bit more control.

How to change a variable name automatically across the project in VIM?

In eclipse, if you change a variable name, eclipse will automatically change this variable's name in whole project.
Can vim do that too?
Vim is a text editor, not an IDE. Though it has some notion of a filetype's syntax, it does not fully parse nor understand the language's full syntax. Refactorings, even simple ones like Rename identifier, do require such full understanding (to be 100% correct).
There are attempts at refactoring support in Vim, most language-specific, some also generic. But I'd advise to keep using a real IDE for this (for its comfort, safety, and correctness), and instead use Vim only for simple, text-based replacements, using :bufdo substitute/... or macros, as described here.
Sort of.
Because it is not an IDE and thus doesn't understand anything about your code, Vim only sees text where you see a variable name. It can't infer anything from the scope or whatever. Without the use of some external program, renaming a variable in Vim is usually done with a buffer-wide or project-wide search/replace.
Since you didn't tell us what language you are working with we can't tell you if there is a language-specific solution for your needs.
try this plugin -> Clighter, for c-family rename-refactoring. It's based on clang, but there are limitations. Still in development

Compile Actionscript From Vim

I switched to Vim from Textmate a while back but I miss the Actionscript bundle for Textmate—particulate the ability to compile Actionscript directly from Textmate.
Has anyone found a way to compile Actionscript directly from Vim?
Yes, compiling AS3 from Vim is very easy.
One basic way, assuming you have main.as file open and you are in --NORMAL-- mode, type this:
:!/path/to/flex45/bin/mxmlc %
to obtain main.swf file next to main.as or:
:!/path/to/flex45/bin/mxmlc -output=../deploy/%<.swf %
to obtain ../deploy/main.swf (relative to main.as).
! means "the following is a shell command".
% means "this file, here, in the current buffer".
%< means "this file's name without the point and the extension".
Obviously it's not really smart but you can make mxmlc read a configuration XML, for more control. See the Flex doc for the list of possible arguments. Using this way it's going to suck a lot to debug your builds.
Another way is to set mxmlc as the build program for actionscript files with:
set makeprg=/path/to/flex45/bin/mxmlc
Then, type :make % to build your project. Errors will be displayed in the quickfix window.
That said, the actual "programming" part of doing AS3 with Vim sucks hard because the only omni-completion script available (to my knowledge) has been very very limited and unfinished for years (it's not an attack against the author which must be praised for his efforts).
I've started to augment that script a couple of months ago but it's far from being finished (and a low level priority) and not that good anyway compared to what you may get in Flash Builder or FDT.
Actually, the AS3 bundle is the only thing I miss from my TextMate days, it was surprisingly polished.
In the official vim documentation, there is an topic called: "fcsh tools : you can compile .as and .mxml files from vim via fcsh : Flex Comipler SHell". That topic describe all process of compilation .as and .mxml, but as noticed there, it tested only on unix systems.
If you want to use FCSH on vim, take a look on https://github.com/lucasdupin/vim-utils/blob/master/bin/fcshd - it works exactly like the FCSH daemon you have on TextMate.

Opening the header file to a C/C++ source file with vim from multiple directories and multiple extension

First off, I was about to write a long list of if/else statements in vim and realized that 1) there was a better way to do what I was trying to do and 2) SO would be ripe with help on the subject. So! I have a variety of files spread about like
foo/src/file01.C
foo/src/file02.cc
foo/src/file03.c
foo/include/file01.hh
foo/include/file02.h
foo/include/file03.h
If you notice that the C/H, cc/hh, c/h extension may or may not match then you are keen and I'd like you to please help. I've look at things like the following vim scripts from the Vim wiki for "Easily switch between source and header file" and although I only dumped a few hours into a.vim without success, it doesn't seem that the others would work via the docs on that page. So can anyone help out on how to make this work?
A good lead I had was a quick How to Easily Switch between Header and Source topic, but still couldn't make it work.
I guess what I really want is how to avoid the multiple if statements and use real matching to do what I want. I want to look into another directory and if look for a header file of the same name with any familiar extension if it was a source C/C++ file, or look for a source file of any regular extension if it was a header file. Thanks for your help!
UPDATE: I specifically want to open the file in a new tab. I live on vim tabs!
I recommend using the FSwitch plugin. https://github.com/derekwyatt/vim-fswitch
This does exactly what you need out of the box. It is better than a.vim in more than one way, being a rewrite of the idea behind a.vim.
The link you posted presents it as a solution, too.
I have just installed it to my vim configuration and it does its job well.
Enjoy.
Just to make sure I was using the most current version, I downloaded the latest a.vim script (2.18) and copied it into my ~/.vim/plugin directory.
You can define certain variables in your ~/.vimrc file to get a.vim to recognize alternate file extensions.
To get the files in your example to match their alternates I added the following to my ~/.vimrc:
let g:alternateExtensions_C = "H,hh"
let g:alternateExtensions_hh = "C"
These are global variables that allow you to override what's already defined. You'll have to define
both relationships (they don't work both ways).
You can see what the current mappings are by typing:
:echo g:alternateExtensionsDict
If you need to define other mappings, follow the same pattern. What comes after the underscore is the file extension you're editing. What's in the double quotes is a comma-separated list of alternate extensions.
let g:alternateExtensions_<ext> = "<list,of,alt,ext>"
If you have a different directory structure, you can define what paths to search by overriding the g:alternateSearchPath variable. ../src and ../include are already included by default.
:echo g:alternateSearchPath
To open the alternate file in a new tab:
:AT
By the way, the a.vim script is pretty well documented. You might want to open it up and take a look. I found a setting or two that I didn't know about and I've been using it for years ;o)
I hope that helps.
IMO your best option is to adopt existing scripts to use :tabf instead of :e or whatever the scripts use right now to open the counterpart file. You can also try to make the change configurable and submit it to the script author. (I'm pretty sure many would find the enhancement useful.)
That reminded me of a trick I used very long time ago. Instead of guessing where the corresponding source/header files are, I have used at the top of file special comment containing relative path to the counterpart file. Switching was as simple as finding the special comment, extracting file name and opening it. Problem was similar to yours in that file extensions were not predictable. My rational solution was to stop guessing and denote counterparts explicitly in the source code. (This days I would have probably tried to put the relationship table into an external file with a standard name and look it up in VIM using the upward search.)
Two helpful things
:he 'path'
:he tabfind
So you would do
:set path=../,/usr/include/,/home/buildagent/SDKROOT/mysdk/inc
:tabfind error_codes.h
to open error_codes.h from somewhere exotic without having to specify it. Note how vim globbing is very very flexible, so you might not need mucht
:argadd ./**/*.[h,H] | tab sall
will open all header files under the current directory, regardless of how many levels deep. Be careful running this command on a large tree or with symlinks outside the tree

A few vim questions

So I was hoping that some old school Vim'ers could help me out. These are all separate questions and normally I would put them up each on their own but I'm not sure if that qualifies as question whoring here.
Plus I think if you know enough to be asking any of these questions they will all be coming up in the near future:
I have a library I'm writing and a series of applications that use that library. There doesn't seem to be an easy way(from what I can tell) to build a ctags file for the library and build one for each of my applications and make sure one references the other when I'm in vim.
Using gf to open files from command mode is awesome, but a lot of my include files
don't contain the full path. They refer to an include directory I set in the IDE. How can I set this directory as another point for Vim to start looking for files?
Is there a way to compile a file inside Vim and send the output to a buffer? I'm currently using MSVS 2k3 but I'll be porting over to Linux in a few weeks so if this is possible on either system I'd appreciate it.
Re 3)
If you put a makefile in your root dir, you can simply write
:make
This will run make and (iirc) put any errors into a seperate buffer, and make vim goto the first compile error. From there you can navigate all erroring lines using :next-error
Also, see this page
http://wiki.beyondunreal.com/Legacy:Vim
and
http://linux.byexamples.com/archives/287/perform-grep-and-make-in-vim/
for details on how to show the result in a seperate console.
1- tags files are independent, and can be used together. See :h 'tags'
I can't tell what is the easy way to build tags files. I have one that consists in using two plugins of mine:
one (draft) plugin that knows how to update C++ tags files (it should be easy to adapt it to other filetypes),
and another (local_vimrc) that helps me define directories-local .vimrc. Thus for any files within a given directory hierarchy, I can adapt the &tags options to use the relevant tag files, and the current tag file that will be rebuilt automatically (or when a keybinding is triggered). (Plugins like project should do the trick as well)
2- :h 'path'
3- :h :make
HTH.
2)
:cd {path}
For help:
:he cd
A few others like :lcd might be better suited. Just scroll down that help page.
This is rather off topic, but might still be useful: if you're using Visual Studio a lot and like Vim, you might want to look at ViEmu. It's the best Vim-emulation for any IDE I've yet seen, and the cost is really low. :) And no, I'm not getting a commission. :P
It's not obvious, but if you open a directory instead of a file, it's nicely browseable.
e.g.
:e . (colon-e-dot)
:e .. (colon-e-dot-dot)
will let you browse from your current directory or its parent.
(understanding that you were probably hoping for a capability to have vim accept e.g.
:e abc.txt
and have it look in several directories, which I don't know how to do.)

Resources